@defra-fish/recurring-payments-job 1.44.0 → 1.45.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -14
- package/package.json +2 -2
- package/src/__tests__/recurring-payments-job.spec.js +45 -14
- package/src/recurring-payments-job.js +12 -3
package/README.md
CHANGED
|
@@ -8,20 +8,21 @@ When the RP job runs, all RP entries with an nextDueDate of the current date, a
|
|
|
8
8
|
|
|
9
9
|
# Environment variables
|
|
10
10
|
|
|
11
|
-
| name
|
|
12
|
-
|
|
|
13
|
-
| NODE_ENV
|
|
14
|
-
| RUN_RECURRING_PAYMENTS
|
|
15
|
-
| SALES_API_URL
|
|
16
|
-
| SALES_API_TIMEOUT_MS
|
|
17
|
-
| OAUTH_AUTHORITY_HOST_URL
|
|
18
|
-
| OAUTH_TENANT
|
|
19
|
-
| OAUTH_CLIENT_ID
|
|
20
|
-
| OAUTH_CLIENT_SECRET
|
|
21
|
-
| OAUTH_SCOPE
|
|
22
|
-
| DYNAMICS_API_PATH
|
|
23
|
-
| DYNAMICS_API_VERSION
|
|
24
|
-
| 1
|
|
11
|
+
| name | description | required | default | valid | notes |
|
|
12
|
+
| ------------------------------ | --------------------------------------------------------------- | :------: | ------------------- | ----------------------------- | --------------------------------------------------------------------------------- |
|
|
13
|
+
| NODE_ENV | Node environment | no | | development, test, production | |
|
|
14
|
+
| RUN_RECURRING_PAYMENTS | Determine whether to run recurring payments job or not | yes | | | |
|
|
15
|
+
| SALES_API_URL | URL for the sales API | no | http://0.0.0.0:4000 | | |
|
|
16
|
+
| SALES_API_TIMEOUT_MS | The timeout in milliseconds requests to the API | no | 10000 | | |
|
|
17
|
+
| OAUTH_AUTHORITY_HOST_URL | OAuth 2.0 authority host | yes | | | |
|
|
18
|
+
| OAUTH_TENANT | OAuth 2.0 tenant | yes | | | |
|
|
19
|
+
| OAUTH_CLIENT_ID | OAuth 2.0 client ID for client credentials flow | yes | | | |
|
|
20
|
+
| OAUTH_CLIENT_SECRET | OAuth 2.0 client secret for client credentials flow | yes | | | |
|
|
21
|
+
| OAUTH_SCOPE | OAuth 2.0 scope to request (client credentials resource) | yes | | | |
|
|
22
|
+
| 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/ |
|
|
23
|
+
| DYNAMICS_API_VERSION | The version of the Dynamics API | yes | | | The version of the dynamics web api. e.g. 9.1 |
|
|
24
|
+
| 1 |
|
|
25
|
+
| RECURRING_PAYMENTS_LOCAL_DELAY | Delay for running recurring payments until sales api is running | no | | |
|
|
25
26
|
|
|
26
27
|
### See also:
|
|
27
28
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defra-fish/recurring-payments-job",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.45.0-rc.1",
|
|
4
4
|
"description": "Rod Licensing Recurring Payments Job",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"@defra-fish/connectors-lib": "1.37.0-rc.2",
|
|
40
40
|
"commander": "^7.2.0"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "a0d8f7a57a81c54b1c181347002cffc82cc81ed7"
|
|
43
43
|
}
|
|
@@ -1,27 +1,58 @@
|
|
|
1
|
-
import
|
|
1
|
+
import commander from 'commander'
|
|
2
2
|
import { processRecurringPayments } from '../recurring-payments-processor.js'
|
|
3
3
|
|
|
4
|
-
jest.
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
jest.useFakeTimers()
|
|
5
|
+
|
|
6
|
+
jest.mock('../recurring-payments-processor.js', () => {
|
|
7
|
+
if (!global.processRecurringPayments) {
|
|
8
|
+
global.processRecurringPayments = jest.fn()
|
|
9
|
+
}
|
|
10
|
+
return { processRecurringPayments: global.processRecurringPayments }
|
|
11
|
+
})
|
|
7
12
|
|
|
8
13
|
jest.mock('commander', () => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
action: jest.fn(),
|
|
12
|
-
command: jest.fn().mockReturnThis(),
|
|
13
|
-
parse: jest.fn()
|
|
14
|
-
}))
|
|
14
|
+
if (!global.commander) {
|
|
15
|
+
global.commander = jest.requireActual('commander')
|
|
15
16
|
}
|
|
17
|
+
return global.commander
|
|
16
18
|
})
|
|
17
19
|
|
|
18
20
|
describe('recurring-payments-job', () => {
|
|
19
|
-
|
|
21
|
+
beforeEach(() => {
|
|
20
22
|
jest.clearAllMocks()
|
|
23
|
+
commander.args = ['test']
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('calls processRecurringPayments when no delay', () => {
|
|
27
|
+
jest.isolateModules(() => {
|
|
28
|
+
require('../recurring-payments-job.js')
|
|
29
|
+
expect(processRecurringPayments).toHaveBeenCalled()
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('doesnt call setTimeout when no correct delay', () => {
|
|
34
|
+
jest.isolateModules(() => {
|
|
35
|
+
const setTimeoutSpy = jest.spyOn(global, 'setTimeout')
|
|
36
|
+
require('../recurring-payments-job.js')
|
|
37
|
+
expect(setTimeoutSpy).not.toHaveBeenCalled()
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('calls processRecurringPayments when delay', () => {
|
|
42
|
+
process.env.RECURRING_PAYMENTS_LOCAL_DELAY = '5'
|
|
43
|
+
jest.isolateModules(() => {
|
|
44
|
+
require('../recurring-payments-job.js')
|
|
45
|
+
jest.advanceTimersByTime(parseInt(process.env.RECURRING_PAYMENTS_LOCAL_DELAY) * 1000)
|
|
46
|
+
expect(processRecurringPayments).toHaveBeenCalled()
|
|
47
|
+
})
|
|
21
48
|
})
|
|
22
49
|
|
|
23
|
-
it('
|
|
24
|
-
|
|
25
|
-
|
|
50
|
+
it('calls setTimeout with the correct delay', () => {
|
|
51
|
+
process.env.RECURRING_PAYMENTS_LOCAL_DELAY = '5'
|
|
52
|
+
jest.isolateModules(() => {
|
|
53
|
+
const setTimeoutSpy = jest.spyOn(global, 'setTimeout')
|
|
54
|
+
require('../recurring-payments-job.js')
|
|
55
|
+
expect(setTimeoutSpy).toHaveBeenCalled()
|
|
56
|
+
})
|
|
26
57
|
})
|
|
27
58
|
})
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
-
import
|
|
2
|
+
import recurringPaymentsJob from 'commander'
|
|
3
3
|
import { processRecurringPayments } from './recurring-payments-processor.js'
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const delay = parseInt(process.env.RECURRING_PAYMENTS_LOCAL_DELAY || '0', 10)
|
|
6
|
+
if (delay > 0) {
|
|
7
|
+
setTimeout(() => {
|
|
8
|
+
executeRecurringPaymentsJob()
|
|
9
|
+
}, delay * 1000)
|
|
10
|
+
} else {
|
|
11
|
+
executeRecurringPaymentsJob()
|
|
12
|
+
}
|
|
6
13
|
|
|
7
|
-
|
|
14
|
+
function executeRecurringPaymentsJob () {
|
|
15
|
+
recurringPaymentsJob.action(processRecurringPayments())
|
|
16
|
+
}
|
|
8
17
|
|
|
9
18
|
export default recurringPaymentsJob
|