mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-07 12:30:06 +00:00
test(get-token): covered getTokenRequestErrorPrefix
This commit is contained in:
81
src/auth/spec/getTokenRequestErrorPrefix.spec.ts
Normal file
81
src/auth/spec/getTokenRequestErrorPrefix.spec.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import { ServerType } from '@sasjs/utils/types'
|
||||
import { getTokenRequestErrorPrefix } from '../getTokenRequestErrorPrefix'
|
||||
|
||||
describe('getTokenRequestErrorPrefix', () => {
|
||||
it('should return error prefix', () => {
|
||||
// INFO: Viya with only required attributes
|
||||
let operation: 'fetching access token' = 'fetching access token'
|
||||
const funcName = 'testFunc'
|
||||
const url = '/SASjsApi/auth/token'
|
||||
|
||||
let expectedPrefix = `Error while ${operation} from ${url}
|
||||
Thrown by the @sasjs/adapter ${funcName} function.
|
||||
|
||||
Response from Viya is below.
|
||||
`
|
||||
|
||||
expect(
|
||||
getTokenRequestErrorPrefix(operation, funcName, ServerType.SasViya, url)
|
||||
).toEqual(expectedPrefix)
|
||||
|
||||
// INFO: Sasjs with data and headers
|
||||
const data = {
|
||||
grant_type: 'authorization_code',
|
||||
code: 'testCode'
|
||||
}
|
||||
const headers = {
|
||||
Authorization: 'Basic test=',
|
||||
Accept: 'application/json'
|
||||
}
|
||||
|
||||
expectedPrefix = `Error while ${operation} from ${url}
|
||||
Thrown by the @sasjs/adapter ${funcName} function.
|
||||
Payload:
|
||||
${JSON.stringify(data, null, 2)}
|
||||
Headers:
|
||||
${JSON.stringify(headers, null, 2)}
|
||||
|
||||
Response from Sasjs is below.
|
||||
`
|
||||
|
||||
expect(
|
||||
getTokenRequestErrorPrefix(
|
||||
operation,
|
||||
funcName,
|
||||
ServerType.Sasjs,
|
||||
url,
|
||||
data,
|
||||
headers
|
||||
)
|
||||
).toEqual(expectedPrefix)
|
||||
|
||||
// INFO: Viya with all attributes
|
||||
const clientId = 'testId'
|
||||
const clientSecret = 'testSecret'
|
||||
|
||||
expectedPrefix = `Error while ${operation} from ${url}
|
||||
Thrown by the @sasjs/adapter ${funcName} function.
|
||||
Payload:
|
||||
${JSON.stringify(data, null, 2)}
|
||||
Headers:
|
||||
${JSON.stringify(headers, null, 2)}
|
||||
ClientId: ${clientId}
|
||||
ClientSecret: ${clientSecret}
|
||||
|
||||
Response from Viya is below.
|
||||
`
|
||||
|
||||
expect(
|
||||
getTokenRequestErrorPrefix(
|
||||
operation,
|
||||
funcName,
|
||||
ServerType.SasViya,
|
||||
url,
|
||||
data,
|
||||
headers,
|
||||
clientId,
|
||||
clientSecret
|
||||
)
|
||||
).toEqual(expectedPrefix)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user