@mojaloop/sdk-scheme-adapter 18.0.0 → 18.0.2
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/.dockerignore +18 -0
- package/.eslintignore +2 -0
- package/.ncurc.yaml +7 -0
- package/CHANGELOG.md +20 -0
- package/CODEOWNERS +31 -1
- package/README.md +1 -0
- package/audit-resolve.json +35 -0
- package/package.json +13 -13
- package/test/__mocks__/@mojaloop/sdk-standard-components.js +0 -151
- package/test/__mocks__/javascript-state-machine.js +0 -21
- package/test/__mocks__/redis.js +0 -78
- package/test/__mocks__/uuidv4.js +0 -16
- package/test/config/integration.env +0 -146
- package/test/integration/lib/Outbound/data/quotesPostRequest.json +0 -52
- package/test/integration/lib/Outbound/data/transfersPostRequest.json +0 -24
- package/test/integration/lib/Outbound/parties.test.js +0 -31
- package/test/integration/lib/Outbound/quotes.test.js +0 -62
- package/test/integration/lib/Outbound/simpleTransfers.test.js +0 -70
- package/test/integration/lib/cache.test.js +0 -79
- package/test/integration/testEnv.js +0 -4
- package/test/unit/ControlClient.test.js +0 -69
- package/test/unit/ControlServer/events.js +0 -41
- package/test/unit/ControlServer/index.js +0 -227
- package/test/unit/ControlServer.test.js +0 -66
- package/test/unit/InboundServer.test.js +0 -443
- package/test/unit/TestServer.test.js +0 -392
- package/test/unit/api/accounts/accounts.test.js +0 -128
- package/test/unit/api/accounts/data/postAccountsBody.json +0 -7
- package/test/unit/api/accounts/data/postAccountsErrorMojaloopResponse.json +0 -33
- package/test/unit/api/accounts/data/postAccountsErrorTimeoutResponse.json +0 -19
- package/test/unit/api/accounts/data/postAccountsSuccessResponse.json +0 -31
- package/test/unit/api/accounts/data/postAccountsSuccessResponseWithError1.json +0 -34
- package/test/unit/api/accounts/data/postAccountsSuccessResponseWithError2.json +0 -39
- package/test/unit/api/accounts/utils.js +0 -79
- package/test/unit/api/proxy/data/proxyConfig.yaml +0 -82
- package/test/unit/api/proxy/data/requestBody.json +0 -22
- package/test/unit/api/proxy/data/requestHeaders.json +0 -5
- package/test/unit/api/proxy/data/requestQuery.json +0 -6
- package/test/unit/api/proxy/data/responseBody.json +0 -21
- package/test/unit/api/proxy/data/responseHeaders.json +0 -5
- package/test/unit/api/proxy/proxy.test.js +0 -220
- package/test/unit/api/proxy/utils.js +0 -79
- package/test/unit/api/transfers/data/getTransfersCommittedResponse.json +0 -24
- package/test/unit/api/transfers/data/getTransfersErrorNotFound.json +0 -18
- package/test/unit/api/transfers/data/postQuotesBody.json +0 -52
- package/test/unit/api/transfers/data/postTransfersBadBody.json +0 -17
- package/test/unit/api/transfers/data/postTransfersBody.json +0 -24
- package/test/unit/api/transfers/data/postTransfersErrorMojaloopResponse.json +0 -62
- package/test/unit/api/transfers/data/postTransfersErrorTimeoutResponse.json +0 -48
- package/test/unit/api/transfers/data/postTransfersSimpleBody.json +0 -26
- package/test/unit/api/transfers/data/postTransfersSuccessResponse.json +0 -128
- package/test/unit/api/transfers/data/putPartiesBody.json +0 -20
- package/test/unit/api/transfers/data/putQuotesBody.json +0 -37
- package/test/unit/api/transfers/data/putTransfersBody.json +0 -17
- package/test/unit/api/transfers/transfers.test.js +0 -191
- package/test/unit/api/transfers/utils.js +0 -264
- package/test/unit/api/utils.js +0 -86
- package/test/unit/config.test.js +0 -119
- package/test/unit/data/commonHttpHeaders.json +0 -7
- package/test/unit/data/defaultConfig.json +0 -70
- package/test/unit/data/postQuotesBody.json +0 -52
- package/test/unit/data/putParticipantsBody.json +0 -12
- package/test/unit/data/putPartiesBody.json +0 -20
- package/test/unit/data/testFile.json +0 -29
- package/test/unit/data/testFile.yaml +0 -14
- package/test/unit/inboundApi/data/mockArguments.json +0 -117
- package/test/unit/inboundApi/data/mockTransactionRequest.json +0 -42
- package/test/unit/inboundApi/handlers.test.js +0 -786
- package/test/unit/index.test.js +0 -88
- package/test/unit/lib/cache.test.js +0 -145
- package/test/unit/lib/model/AccountsModel.test.js +0 -124
- package/test/unit/lib/model/InboundTransfersModel.test.js +0 -889
- package/test/unit/lib/model/OutboundBulkQuotesModel.test.js +0 -253
- package/test/unit/lib/model/OutboundBulkTransfersModel.test.js +0 -247
- package/test/unit/lib/model/OutboundRequestToPayModel.test.js +0 -166
- package/test/unit/lib/model/OutboundRequestToPayTransferModel.test.js +0 -245
- package/test/unit/lib/model/OutboundTransfersModel.test.js +0 -1579
- package/test/unit/lib/model/PartiesModel.test.js +0 -478
- package/test/unit/lib/model/QuotesModel.test.js +0 -477
- package/test/unit/lib/model/TransfersModel.test.js +0 -481
- package/test/unit/lib/model/common/PersistentStateMachine.test.js +0 -178
- package/test/unit/lib/model/data/authorizationsResponse.json +0 -13
- package/test/unit/lib/model/data/bulkQuoteRequest.json +0 -27
- package/test/unit/lib/model/data/bulkQuoteResponse.json +0 -35
- package/test/unit/lib/model/data/bulkTransferFulfil.json +0 -13
- package/test/unit/lib/model/data/bulkTransferRequest.json +0 -29
- package/test/unit/lib/model/data/defaultConfig.json +0 -59
- package/test/unit/lib/model/data/getBulkTransfersBackendResponse.json +0 -42
- package/test/unit/lib/model/data/getBulkTransfersMojaloopResponse.json +0 -22
- package/test/unit/lib/model/data/getTransfersBackendResponse.json +0 -34
- package/test/unit/lib/model/data/getTransfersMojaloopResponse.json +0 -17
- package/test/unit/lib/model/data/mockArguments.json +0 -188
- package/test/unit/lib/model/data/mockTxnRequestsArguments.json +0 -63
- package/test/unit/lib/model/data/notificationAbortedToPayee.json +0 -10
- package/test/unit/lib/model/data/notificationReservedToPayee.json +0 -10
- package/test/unit/lib/model/data/notificationToPayee.json +0 -10
- package/test/unit/lib/model/data/payeeParty.json +0 -18
- package/test/unit/lib/model/data/putQuotesResponse.json +0 -33
- package/test/unit/lib/model/data/putTransfersResponse.json +0 -5
- package/test/unit/lib/model/data/quoteResponse.json +0 -42
- package/test/unit/lib/model/data/requestToPayRequest.json +0 -20
- package/test/unit/lib/model/data/requestToPayTransferRequest.json +0 -27
- package/test/unit/lib/model/data/transactionRequestResponse.json +0 -18
- package/test/unit/lib/model/data/transferFulfil.json +0 -10
- package/test/unit/lib/model/data/transferRequest.json +0 -26
- package/test/unit/lib/model/mockedLibRequests.js +0 -74
- package/test/unit/mockLogger.js +0 -39
- package/test/unit/outboundApi/data/bulkQuoteRequest.json +0 -28
- package/test/unit/outboundApi/data/bulkTransferRequest.json +0 -28
- package/test/unit/outboundApi/data/mockBulkQuoteError.json +0 -45
- package/test/unit/outboundApi/data/mockBulkTransferError.json +0 -48
- package/test/unit/outboundApi/data/mockError.json +0 -41
- package/test/unit/outboundApi/data/mockGetPartiesError.json +0 -4
- package/test/unit/outboundApi/data/mockRequestToPayError.json +0 -32
- package/test/unit/outboundApi/data/mockRequestToPayTransferError.json +0 -39
- package/test/unit/outboundApi/data/requestToPay.json +0 -21
- package/test/unit/outboundApi/data/requestToPayTransferRequest.json +0 -20
- package/test/unit/outboundApi/data/transferRequest.json +0 -21
- package/test/unit/outboundApi/handlers.test.js +0 -887
package/test/unit/index.test.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/**************************************************************************
|
|
2
|
-
* (C) Copyright ModusBox Inc. 2019 - All rights reserved. *
|
|
3
|
-
* *
|
|
4
|
-
* This file is made available under the terms of the license agreement *
|
|
5
|
-
* specified in the corresponding source code repository. *
|
|
6
|
-
* *
|
|
7
|
-
* ORIGINAL AUTHOR: *
|
|
8
|
-
* James Bush - james.bush@modusbox.com *
|
|
9
|
-
**************************************************************************/
|
|
10
|
-
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
jest.mock('dotenv', () => ({
|
|
14
|
-
config: jest.fn()
|
|
15
|
-
}));
|
|
16
|
-
|
|
17
|
-
const promClient = require('prom-client');
|
|
18
|
-
const defaultConfig = require('./data/defaultConfig.json');
|
|
19
|
-
const { Logger } = require('@mojaloop/sdk-standard-components');
|
|
20
|
-
|
|
21
|
-
const TestControlServer = require('./ControlServer');
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
process.env.PEER_ENDPOINT = '172.17.0.3:4000';
|
|
25
|
-
process.env.BACKEND_ENDPOINT = '172.17.0.5:4000';
|
|
26
|
-
process.env.CACHE_URL = 'redis://172.17.0.2:6379';
|
|
27
|
-
process.env.MGMT_API_WS_URL = '0.0.0.0';
|
|
28
|
-
|
|
29
|
-
const index = require('~/index.js');
|
|
30
|
-
|
|
31
|
-
describe('index.js', () => {
|
|
32
|
-
beforeEach(() => {
|
|
33
|
-
promClient.register.clear();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test('Exports expected modules', () => {
|
|
37
|
-
expect(typeof(index.Server)).toBe('function');
|
|
38
|
-
expect(typeof(index.InboundServerMiddleware)).toBe('object');
|
|
39
|
-
expect(typeof(index.OutboundServerMiddleware)).toBe('object');
|
|
40
|
-
expect(typeof(index.Router)).toBe('function');
|
|
41
|
-
expect(typeof(index.Validate)).toBe('function');
|
|
42
|
-
expect(typeof(index.Cache)).toBe('function');
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
describe('Server', () => {
|
|
47
|
-
let server, controlServer, conf, logger;
|
|
48
|
-
|
|
49
|
-
beforeEach(async () => {
|
|
50
|
-
promClient.register.clear();
|
|
51
|
-
logger = new Logger.Logger({ stringify: () => '' });
|
|
52
|
-
conf = JSON.parse(JSON.stringify(defaultConfig));
|
|
53
|
-
conf.enableTestFeatures = true;
|
|
54
|
-
conf.pm4mlEnabled = true;
|
|
55
|
-
conf.control.mgmtAPIWsUrl = 'localhost';
|
|
56
|
-
conf.control.mgmtAPIWsPort = 4005;
|
|
57
|
-
conf.control.port = conf.control.mgmtAPIWsPort;
|
|
58
|
-
controlServer = new TestControlServer.Server({ logger, appConfig: conf });
|
|
59
|
-
server = new index.Server(conf, logger);
|
|
60
|
-
server.restart = jest.fn();
|
|
61
|
-
await server.start();
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
afterEach(async () => {
|
|
65
|
-
await controlServer.stop();
|
|
66
|
-
await server.stop();
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe('is reconfigured correctly by the control client', () => {
|
|
70
|
-
let newConf;
|
|
71
|
-
beforeEach(async () => {
|
|
72
|
-
// not every server restarts on every config change, we'll make sure they all restart
|
|
73
|
-
newConf = { ...conf, logIndent: conf.logIndent + 1, control: { ...conf.control, rubbish: 'data' }, test: { trash: 'data' } };
|
|
74
|
-
// Just in case, we'll assert the new configuration is different to the old one
|
|
75
|
-
expect(newConf).not.toEqual(conf);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('reconfigures and restarts constituent servers when triggered by control client', async () => {
|
|
79
|
-
controlServer.broadcastConfigChange(newConf);
|
|
80
|
-
|
|
81
|
-
// We wait for the servers to get restarted
|
|
82
|
-
await new Promise((wait) => setTimeout(wait, 1000));
|
|
83
|
-
|
|
84
|
-
expect(server.restart).toHaveBeenCalledTimes(1);
|
|
85
|
-
expect(server.restart).toHaveBeenCalledWith(newConf);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
});
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
/**************************************************************************
|
|
2
|
-
* (C) Copyright ModusBox Inc. 2019 - All rights reserved. *
|
|
3
|
-
* *
|
|
4
|
-
* This file is made available under the terms of the license agreement *
|
|
5
|
-
* specified in the corresponding source code repository. *
|
|
6
|
-
* *
|
|
7
|
-
* ORIGINAL AUTHOR: *
|
|
8
|
-
* James Bush - james.bush@modusbox.com *
|
|
9
|
-
**************************************************************************/
|
|
10
|
-
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
jest.mock('redis');
|
|
14
|
-
|
|
15
|
-
const Cache = require('~/lib/cache');
|
|
16
|
-
const { Logger } = require('@mojaloop/sdk-standard-components');
|
|
17
|
-
|
|
18
|
-
const createCache = async() => {
|
|
19
|
-
const logger = new Logger.Logger({ context: { app: 'model-unit-tests-cache' }, stringify: () => '' });
|
|
20
|
-
const cache = new Cache({
|
|
21
|
-
cacheUrl: 'redis://dummy:1234',
|
|
22
|
-
logger,
|
|
23
|
-
});
|
|
24
|
-
await cache.connect();
|
|
25
|
-
return cache;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
describe('Cache', () => {
|
|
29
|
-
let dummyPubMessage;
|
|
30
|
-
|
|
31
|
-
beforeEach(() => {
|
|
32
|
-
dummyPubMessage = JSON.parse(JSON.stringify({
|
|
33
|
-
data: 12345,
|
|
34
|
-
test: '98765'
|
|
35
|
-
}));
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test('Makes connections to redis server for cache operations', async () => {
|
|
39
|
-
const cache = await createCache();
|
|
40
|
-
expect(cache).not.toBeFalsy();
|
|
41
|
-
await cache.disconnect();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
test('Makes subscriber callbacks on the correct channels when messages arrive', async () => {
|
|
46
|
-
const cache = await createCache();
|
|
47
|
-
|
|
48
|
-
const msg1 = dummyPubMessage;
|
|
49
|
-
|
|
50
|
-
// make the messages different
|
|
51
|
-
const msg2 = JSON.parse(JSON.stringify(dummyPubMessage));
|
|
52
|
-
msg2.abc = 'xyz';
|
|
53
|
-
|
|
54
|
-
const chan1 = 'dummychannel1';
|
|
55
|
-
const chan2 = 'dummychannel2';
|
|
56
|
-
|
|
57
|
-
// create a promise that only gets resoled if the subscription gets the
|
|
58
|
-
// correct message
|
|
59
|
-
const cb1Promise = new Promise((resolve) => {
|
|
60
|
-
const mockCb1 = jest.fn((cn, msg) => {
|
|
61
|
-
expect(cn).toBe(chan1);
|
|
62
|
-
|
|
63
|
-
const value = JSON.parse(msg);
|
|
64
|
-
// check we got the expected message
|
|
65
|
-
expect(value).toEqual(msg1);
|
|
66
|
-
|
|
67
|
-
//resolve the promise
|
|
68
|
-
resolve();
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
// subscribe to a ficticious channel
|
|
72
|
-
return cache.subscribe(chan1, mockCb1).then(cbId1 => {
|
|
73
|
-
// we should be the first callback registered (zero index)
|
|
74
|
-
expect(cbId1).toBe(0);
|
|
75
|
-
|
|
76
|
-
// now we have subscribed, inject a message.
|
|
77
|
-
return cache.publish(chan1, msg1);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
// create a second promise that only gets resolved if the second subscription gets the
|
|
82
|
-
// correct message
|
|
83
|
-
const cb2Promise = new Promise((resolve) => {
|
|
84
|
-
const mockCb2 = jest.fn((cn, msg) => {
|
|
85
|
-
expect(cn).toBe(chan2);
|
|
86
|
-
|
|
87
|
-
// check we got the expected message
|
|
88
|
-
const value = JSON.parse(msg);
|
|
89
|
-
expect(value).toEqual(msg2);
|
|
90
|
-
|
|
91
|
-
//resolve the promise
|
|
92
|
-
resolve();
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
// subscribe to a ficticious channel
|
|
96
|
-
return cache.subscribe(chan2, mockCb2).then(cbId2 => {
|
|
97
|
-
// we should be the second callback registered (zero index)
|
|
98
|
-
expect(cbId2).toBe(1);
|
|
99
|
-
|
|
100
|
-
// now we have subscribed, inject a message.
|
|
101
|
-
return cache.publish(chan2, msg2);
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
await Promise.all([cb1Promise, cb2Promise]);
|
|
106
|
-
|
|
107
|
-
await cache.disconnect();
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
test('Unsubscribed callbacks do not get called when messages arrive', async () => {
|
|
112
|
-
const cache = await createCache();
|
|
113
|
-
const msg1 = dummyPubMessage;
|
|
114
|
-
|
|
115
|
-
const chan = 'dummychannel1';
|
|
116
|
-
|
|
117
|
-
// create a promise that only gets resoled if the subscription gets the
|
|
118
|
-
// correct message
|
|
119
|
-
await new Promise((resolve, reject) => {
|
|
120
|
-
const mockCb1 = jest.fn((cn, msg) => { // eslint-disable-line no-unused-vars
|
|
121
|
-
//reject the outer promise if this func gets called!
|
|
122
|
-
reject();
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
// subscribe to a ficticious channel
|
|
126
|
-
return cache.subscribe(chan, mockCb1).then(cbId1 => {
|
|
127
|
-
// we should be the first callback registered (zero index)
|
|
128
|
-
expect(cbId1).toBe(0);
|
|
129
|
-
|
|
130
|
-
// now we have subscribed we unsubscribe
|
|
131
|
-
return cache.unsubscribe(chan, cbId1).then(() => {
|
|
132
|
-
// now we have unsubscribed, inject a message
|
|
133
|
-
cache.publish(chan, msg1);
|
|
134
|
-
|
|
135
|
-
// wait 3 seconds and if the callback has not been called we assume a pass
|
|
136
|
-
setTimeout(() => {
|
|
137
|
-
expect(mockCb1.mock.calls.length).toBe(0);
|
|
138
|
-
return resolve();
|
|
139
|
-
}, 3000);
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
await cache.disconnect();
|
|
144
|
-
});
|
|
145
|
-
});
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
/**************************************************************************
|
|
2
|
-
* (C) Copyright ModusBox Inc. 2019 - All rights reserved. *
|
|
3
|
-
* *
|
|
4
|
-
* This file is made available under the terms of the license agreement *
|
|
5
|
-
* specified in the corresponding source code repository. *
|
|
6
|
-
* *
|
|
7
|
-
* ORIGINAL AUTHOR: *
|
|
8
|
-
* Yevhen Kyriukha - yevhen.kyriukha@modusbox.com *
|
|
9
|
-
**************************************************************************/
|
|
10
|
-
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
// we use a mock standard components lib to intercept and mock certain funcs
|
|
14
|
-
jest.mock('@mojaloop/sdk-standard-components');
|
|
15
|
-
jest.mock('redis');
|
|
16
|
-
|
|
17
|
-
const Cache = require('~/lib/cache');
|
|
18
|
-
const { AccountsModel } = require('~/lib/model');
|
|
19
|
-
|
|
20
|
-
const StateMachine = require('javascript-state-machine');
|
|
21
|
-
const { MojaloopRequests, Logger } = require('@mojaloop/sdk-standard-components');
|
|
22
|
-
const { SDKStateEnum } = require('../../../../src/lib/model/common');
|
|
23
|
-
|
|
24
|
-
const defaultConfig = require('./data/defaultConfig');
|
|
25
|
-
const transferRequest = require('./data/transferRequest');
|
|
26
|
-
|
|
27
|
-
function generateAccounts(count, currencies) {
|
|
28
|
-
const accounts = [];
|
|
29
|
-
for (let currencyIndex = 0; currencyIndex < currencies.length; currencyIndex++) {
|
|
30
|
-
for (let i = 1; i <= count; i++) {
|
|
31
|
-
accounts.push({
|
|
32
|
-
idType: 'MSISDN',
|
|
33
|
-
idValue: String(i * (currencyIndex + 1)).padStart(9, '0'),
|
|
34
|
-
idSubValue: `Sub_${String(i * (currencyIndex + 1))}`.padStart(5, '0'),
|
|
35
|
-
currency: currencies[currencyIndex],
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return accounts;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
describe('AccountsModel', () => {
|
|
44
|
-
let logger;
|
|
45
|
-
let cache;
|
|
46
|
-
|
|
47
|
-
async function testCreateAccount(count, currencies) {
|
|
48
|
-
const MAX_ITEMS_PER_REQUEST = 10000; // As per API Spec 6.2.2.2 (partyList field)
|
|
49
|
-
|
|
50
|
-
MojaloopRequests.__postParticipants = jest.fn(request => {
|
|
51
|
-
// simulate a response from ALS
|
|
52
|
-
const response = {
|
|
53
|
-
type: 'accountsCreationSuccessfulResponse',
|
|
54
|
-
data: {
|
|
55
|
-
body: {
|
|
56
|
-
partyList: request.partyList.map(party => ({
|
|
57
|
-
partyId: party,
|
|
58
|
-
// errorInformation: null
|
|
59
|
-
})),
|
|
60
|
-
currency: request.currency,
|
|
61
|
-
},
|
|
62
|
-
headers: {}
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
cache.publish(`ac_${request.requestId}`, response);
|
|
66
|
-
return Promise.resolve();
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
const model = new AccountsModel({
|
|
70
|
-
...defaultConfig,
|
|
71
|
-
cache,
|
|
72
|
-
logger,
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
const accounts = generateAccounts(count, currencies);
|
|
76
|
-
await model.initialize({ accounts });
|
|
77
|
-
|
|
78
|
-
expect(StateMachine.__instance.state).toBe('start');
|
|
79
|
-
|
|
80
|
-
// wait for the model to reach a terminal state
|
|
81
|
-
const result = await model.run();
|
|
82
|
-
|
|
83
|
-
const expectedRequestsCount = currencies.length *
|
|
84
|
-
(Math.floor(count / MAX_ITEMS_PER_REQUEST) + ((count % MAX_ITEMS_PER_REQUEST) ? 1 : 0));
|
|
85
|
-
expect(MojaloopRequests.__postParticipants).toHaveBeenCalledTimes(expectedRequestsCount);
|
|
86
|
-
|
|
87
|
-
expect(result.currentState).toBe(SDKStateEnum.COMPLETED);
|
|
88
|
-
expect(StateMachine.__instance.state).toBe('succeeded');
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
beforeAll(() => {
|
|
92
|
-
logger = new Logger.Logger({ context: { app: 'outbound-model-unit-tests-cache' }, stringify: () => '' });
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
beforeEach(async () => {
|
|
96
|
-
cache = new Cache({
|
|
97
|
-
cacheUrl: 'redis://dummy:1234',
|
|
98
|
-
logger,
|
|
99
|
-
});
|
|
100
|
-
await cache.connect();
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
afterEach(async () => {
|
|
104
|
-
await cache.disconnect();
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
test('initializes to starting state', async () => {
|
|
108
|
-
const model = new AccountsModel({
|
|
109
|
-
...defaultConfig,
|
|
110
|
-
cache,
|
|
111
|
-
logger,
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
await model.initialize(JSON.parse(JSON.stringify(transferRequest)));
|
|
115
|
-
|
|
116
|
-
expect(StateMachine.__instance.state).toBe('start');
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
test('create 100 accounts', () =>
|
|
120
|
-
testCreateAccount(100, ['USD', 'EUR', 'UAH']));
|
|
121
|
-
|
|
122
|
-
test('create 20000 accounts', () =>
|
|
123
|
-
testCreateAccount(20000, ['USD', 'EUR']));
|
|
124
|
-
});
|