Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker/env/fulfilment_job.secrets.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ OAUTH_CLIENT_ID=<insert here>
OAUTH_CLIENT_SECRET=<insert here>
OAUTH_SCOPE=<insert here>

DYNAMICS_API_PATH=<insert here>
DYNAMICS_API_HOST=<insert here>
DYNAMICS_API_VERSION=<insert here>
2 changes: 1 addition & 1 deletion docker/env/sales_api.secrets.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ OAUTH_CLIENT_ID=<insert here>
OAUTH_CLIENT_SECRET=<insert here>
OAUTH_SCOPE=<insert here>

DYNAMICS_API_PATH=<insert here>
DYNAMICS_API_HOST=<insert here>
DYNAMICS_API_VERSION=<insert here>

# GOV.UK Pay
Expand Down
14 changes: 8 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@types/jest": "27.4.0",
"babel-jest": "27.5.1",
"clone-deep": "4.0.1",
"dynamics-web-api": "1.7.3",
"dynamics-web-api": "^2.4.0",
"eslint": "7.32.0",
"husky": "9.1.7",
"jest": "27.5.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/dynamics-lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ shared by the different packages which comprise the Rod Licensing digital servic
| OAUTH_AUTHORITY_HOST_URL | OAuth 2.0 authority host | yes | | | |
| OAUTH_TENANT | OAuth 2.0 tenant | yes | | | |
| OAUTH_SCOPE | OAuth 2.0 scope to request (client credentials resource) | yes | | | |
| DYNAMICS_API_PATH | Full URL to the dynamics API | yes | | | The full URL to the dynamics web api. e.g. https://dynamics-server/api/data/v9.1/ |
| DYNAMICS_API_HOST | The root domain of the dynamics server | yes | | | The root domain of the dynamics server. e.g. https://dynamics-server |
| DYNAMICS_API_VERSION | The version of the Dynamics API | yes | | | The version of the dynamics web api. e.g. 9.1 |
| DYNAMICS_API_TIMEOUT | The Dynamics API request timeout | no | 90000 | | The time in milliseconds after which requests will timeout if Dynamics does not return a response, e.g. 90000 |
| DYNAMICS_CACHE_TTL | Default TTL for cached operations | no | 12 hours | | The default TTL for cached operations. Specified in seconds. |
Expand Down
10 changes: 5 additions & 5 deletions packages/dynamics-lib/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/dynamics-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"cache-manager": "3.6.0",
"cache-manager-ioredis": "2.1.0",
"debug": "4.3.3",
"dynamics-web-api": "1.7.3",
"dynamics-web-api": "^2.4.0",
"joi": "17.13.3",
"moment": "2.29.1",
"pluralize": "8.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { readFileSync } = jest.requireActual('fs')
const Path = jest.requireActual('path')
const optionSetDataPath = Path.join(Project.root, 'src', '__mocks__', 'option-set-data.json')

export const configureDynamicsWebApiMock = (DynamicsWebApi = jest.genMockFromModule('dynamics-web-api')) => {
export const configureDynamicsWebApiMock = DynamicsWebApi => {
let expectedResponse = {}
let nextResponses = {}
let callError = {}
Expand Down Expand Up @@ -53,12 +53,12 @@ export const configureDynamicsWebApiMock = (DynamicsWebApi = jest.genMockFromMod
}
}

DynamicsWebApi.prototype.retrieveRequest = jest.fn(async () => responseCapableMethod('retrieveRequest'))
DynamicsWebApi.prototype.createRequest = jest.fn(async () => responseCapableMethod('createRequest'))
DynamicsWebApi.prototype.updateRequest = jest.fn(async () => responseCapableMethod('updateRequest'))
DynamicsWebApi.prototype.retrieveMultipleRequest = jest.fn(async () => responseCapableMethod('retrieveMultipleRequest'))
DynamicsWebApi.prototype.retrieve = jest.fn(async () => responseCapableMethod('retrieve'))
DynamicsWebApi.prototype.create = jest.fn(async () => responseCapableMethod('create'))
DynamicsWebApi.prototype.update = jest.fn(async () => responseCapableMethod('update'))
DynamicsWebApi.prototype.retrieveMultiple = jest.fn(async () => responseCapableMethod('retrieveMultiple'))
DynamicsWebApi.prototype.retrieveGlobalOptionSets = jest.fn(async () => responseCapableMethod('retrieveGlobalOptionSets'))
DynamicsWebApi.prototype.executeUnboundFunction = jest.fn(async functionName => {
DynamicsWebApi.prototype.callFunction = jest.fn(async functionName => {
let returnValue = null
if (functionName === 'RetrieveVersion') {
returnValue = {
Expand Down
6 changes: 4 additions & 2 deletions packages/dynamics-lib/src/__mocks__/dynamics-web-api.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { configureDynamicsWebApiMock } from './dynamics-web-api-mock-helper.js'
const DynamicsWebApi = jest.genMockFromModule('dynamics-web-api')
export default configureDynamicsWebApiMock(DynamicsWebApi)
const DynamicsWebApi = jest.fn()
DynamicsWebApi.prototype = {}
configureDynamicsWebApiMock(DynamicsWebApi)
export { DynamicsWebApi }
24 changes: 11 additions & 13 deletions packages/dynamics-lib/src/client/__tests__/dynamics-client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SimpleOAuth2 from 'simple-oauth2'

describe('dynamics-client', () => {
it('is configured via environment variables', async () => {
process.env.DYNAMICS_API_PATH = 'https://test-server/api/data/v9.1/'
process.env.DYNAMICS_API_HOST = 'https://test-server'
process.env.DYNAMICS_API_VERSION = '9.1'
process.env.DYNAMICS_API_TIMEOUT = 60000
process.env.OAUTH_AUTHORITY_HOST_URL = 'https://test-authority/'
Expand All @@ -14,26 +14,24 @@ describe('dynamics-client', () => {
const dynamicsApiConfig = config()

expect(dynamicsApiConfig).toMatchObject({
webApiUrl: process.env.DYNAMICS_API_PATH,
webApiVersion: process.env.DYNAMICS_API_VERSION,
serverUrl: process.env.DYNAMICS_API_HOST,
dataApi: { version: process.env.DYNAMICS_API_VERSION },
timeout: `${process.env.DYNAMICS_API_TIMEOUT}`,
onTokenRefresh: expect.any(Function)
})
const testCallback = jest.fn()
await dynamicsApiConfig.onTokenRefresh(testCallback)
expect(testCallback).toHaveBeenCalledWith('MOCK TOKEN')
const token = await dynamicsApiConfig.onTokenRefresh()
expect(token).toBe('MOCK TOKEN')
})

it('caches tokens until they expire', async () => {
const dynamicsApiConfig = config()
const testCallback = jest.fn()
await dynamicsApiConfig.onTokenRefresh(testCallback)
expect(testCallback).toHaveBeenLastCalledWith('MOCK TOKEN')
let token = await dynamicsApiConfig.onTokenRefresh()
expect(token).toBe('MOCK TOKEN')
SimpleOAuth2.__setMockTokenReturnValue('NEW MOCK TOKEN')
await dynamicsApiConfig.onTokenRefresh(testCallback)
expect(testCallback).toHaveBeenLastCalledWith('MOCK TOKEN')
token = await dynamicsApiConfig.onTokenRefresh()
expect(token).toBe('MOCK TOKEN')
SimpleOAuth2.__setMockTokenExpired(true)
await dynamicsApiConfig.onTokenRefresh(testCallback)
expect(testCallback).toHaveBeenLastCalledWith('NEW MOCK TOKEN')
token = await dynamicsApiConfig.onTokenRefresh()
expect(token).toBe('NEW MOCK TOKEN')
})
})
Loading
Loading