@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.
Files changed (119) hide show
  1. package/.dockerignore +18 -0
  2. package/.eslintignore +2 -0
  3. package/.ncurc.yaml +7 -0
  4. package/CHANGELOG.md +20 -0
  5. package/CODEOWNERS +31 -1
  6. package/README.md +1 -0
  7. package/audit-resolve.json +35 -0
  8. package/package.json +13 -13
  9. package/test/__mocks__/@mojaloop/sdk-standard-components.js +0 -151
  10. package/test/__mocks__/javascript-state-machine.js +0 -21
  11. package/test/__mocks__/redis.js +0 -78
  12. package/test/__mocks__/uuidv4.js +0 -16
  13. package/test/config/integration.env +0 -146
  14. package/test/integration/lib/Outbound/data/quotesPostRequest.json +0 -52
  15. package/test/integration/lib/Outbound/data/transfersPostRequest.json +0 -24
  16. package/test/integration/lib/Outbound/parties.test.js +0 -31
  17. package/test/integration/lib/Outbound/quotes.test.js +0 -62
  18. package/test/integration/lib/Outbound/simpleTransfers.test.js +0 -70
  19. package/test/integration/lib/cache.test.js +0 -79
  20. package/test/integration/testEnv.js +0 -4
  21. package/test/unit/ControlClient.test.js +0 -69
  22. package/test/unit/ControlServer/events.js +0 -41
  23. package/test/unit/ControlServer/index.js +0 -227
  24. package/test/unit/ControlServer.test.js +0 -66
  25. package/test/unit/InboundServer.test.js +0 -443
  26. package/test/unit/TestServer.test.js +0 -392
  27. package/test/unit/api/accounts/accounts.test.js +0 -128
  28. package/test/unit/api/accounts/data/postAccountsBody.json +0 -7
  29. package/test/unit/api/accounts/data/postAccountsErrorMojaloopResponse.json +0 -33
  30. package/test/unit/api/accounts/data/postAccountsErrorTimeoutResponse.json +0 -19
  31. package/test/unit/api/accounts/data/postAccountsSuccessResponse.json +0 -31
  32. package/test/unit/api/accounts/data/postAccountsSuccessResponseWithError1.json +0 -34
  33. package/test/unit/api/accounts/data/postAccountsSuccessResponseWithError2.json +0 -39
  34. package/test/unit/api/accounts/utils.js +0 -79
  35. package/test/unit/api/proxy/data/proxyConfig.yaml +0 -82
  36. package/test/unit/api/proxy/data/requestBody.json +0 -22
  37. package/test/unit/api/proxy/data/requestHeaders.json +0 -5
  38. package/test/unit/api/proxy/data/requestQuery.json +0 -6
  39. package/test/unit/api/proxy/data/responseBody.json +0 -21
  40. package/test/unit/api/proxy/data/responseHeaders.json +0 -5
  41. package/test/unit/api/proxy/proxy.test.js +0 -220
  42. package/test/unit/api/proxy/utils.js +0 -79
  43. package/test/unit/api/transfers/data/getTransfersCommittedResponse.json +0 -24
  44. package/test/unit/api/transfers/data/getTransfersErrorNotFound.json +0 -18
  45. package/test/unit/api/transfers/data/postQuotesBody.json +0 -52
  46. package/test/unit/api/transfers/data/postTransfersBadBody.json +0 -17
  47. package/test/unit/api/transfers/data/postTransfersBody.json +0 -24
  48. package/test/unit/api/transfers/data/postTransfersErrorMojaloopResponse.json +0 -62
  49. package/test/unit/api/transfers/data/postTransfersErrorTimeoutResponse.json +0 -48
  50. package/test/unit/api/transfers/data/postTransfersSimpleBody.json +0 -26
  51. package/test/unit/api/transfers/data/postTransfersSuccessResponse.json +0 -128
  52. package/test/unit/api/transfers/data/putPartiesBody.json +0 -20
  53. package/test/unit/api/transfers/data/putQuotesBody.json +0 -37
  54. package/test/unit/api/transfers/data/putTransfersBody.json +0 -17
  55. package/test/unit/api/transfers/transfers.test.js +0 -191
  56. package/test/unit/api/transfers/utils.js +0 -264
  57. package/test/unit/api/utils.js +0 -86
  58. package/test/unit/config.test.js +0 -119
  59. package/test/unit/data/commonHttpHeaders.json +0 -7
  60. package/test/unit/data/defaultConfig.json +0 -70
  61. package/test/unit/data/postQuotesBody.json +0 -52
  62. package/test/unit/data/putParticipantsBody.json +0 -12
  63. package/test/unit/data/putPartiesBody.json +0 -20
  64. package/test/unit/data/testFile.json +0 -29
  65. package/test/unit/data/testFile.yaml +0 -14
  66. package/test/unit/inboundApi/data/mockArguments.json +0 -117
  67. package/test/unit/inboundApi/data/mockTransactionRequest.json +0 -42
  68. package/test/unit/inboundApi/handlers.test.js +0 -786
  69. package/test/unit/index.test.js +0 -88
  70. package/test/unit/lib/cache.test.js +0 -145
  71. package/test/unit/lib/model/AccountsModel.test.js +0 -124
  72. package/test/unit/lib/model/InboundTransfersModel.test.js +0 -889
  73. package/test/unit/lib/model/OutboundBulkQuotesModel.test.js +0 -253
  74. package/test/unit/lib/model/OutboundBulkTransfersModel.test.js +0 -247
  75. package/test/unit/lib/model/OutboundRequestToPayModel.test.js +0 -166
  76. package/test/unit/lib/model/OutboundRequestToPayTransferModel.test.js +0 -245
  77. package/test/unit/lib/model/OutboundTransfersModel.test.js +0 -1579
  78. package/test/unit/lib/model/PartiesModel.test.js +0 -478
  79. package/test/unit/lib/model/QuotesModel.test.js +0 -477
  80. package/test/unit/lib/model/TransfersModel.test.js +0 -481
  81. package/test/unit/lib/model/common/PersistentStateMachine.test.js +0 -178
  82. package/test/unit/lib/model/data/authorizationsResponse.json +0 -13
  83. package/test/unit/lib/model/data/bulkQuoteRequest.json +0 -27
  84. package/test/unit/lib/model/data/bulkQuoteResponse.json +0 -35
  85. package/test/unit/lib/model/data/bulkTransferFulfil.json +0 -13
  86. package/test/unit/lib/model/data/bulkTransferRequest.json +0 -29
  87. package/test/unit/lib/model/data/defaultConfig.json +0 -59
  88. package/test/unit/lib/model/data/getBulkTransfersBackendResponse.json +0 -42
  89. package/test/unit/lib/model/data/getBulkTransfersMojaloopResponse.json +0 -22
  90. package/test/unit/lib/model/data/getTransfersBackendResponse.json +0 -34
  91. package/test/unit/lib/model/data/getTransfersMojaloopResponse.json +0 -17
  92. package/test/unit/lib/model/data/mockArguments.json +0 -188
  93. package/test/unit/lib/model/data/mockTxnRequestsArguments.json +0 -63
  94. package/test/unit/lib/model/data/notificationAbortedToPayee.json +0 -10
  95. package/test/unit/lib/model/data/notificationReservedToPayee.json +0 -10
  96. package/test/unit/lib/model/data/notificationToPayee.json +0 -10
  97. package/test/unit/lib/model/data/payeeParty.json +0 -18
  98. package/test/unit/lib/model/data/putQuotesResponse.json +0 -33
  99. package/test/unit/lib/model/data/putTransfersResponse.json +0 -5
  100. package/test/unit/lib/model/data/quoteResponse.json +0 -42
  101. package/test/unit/lib/model/data/requestToPayRequest.json +0 -20
  102. package/test/unit/lib/model/data/requestToPayTransferRequest.json +0 -27
  103. package/test/unit/lib/model/data/transactionRequestResponse.json +0 -18
  104. package/test/unit/lib/model/data/transferFulfil.json +0 -10
  105. package/test/unit/lib/model/data/transferRequest.json +0 -26
  106. package/test/unit/lib/model/mockedLibRequests.js +0 -74
  107. package/test/unit/mockLogger.js +0 -39
  108. package/test/unit/outboundApi/data/bulkQuoteRequest.json +0 -28
  109. package/test/unit/outboundApi/data/bulkTransferRequest.json +0 -28
  110. package/test/unit/outboundApi/data/mockBulkQuoteError.json +0 -45
  111. package/test/unit/outboundApi/data/mockBulkTransferError.json +0 -48
  112. package/test/unit/outboundApi/data/mockError.json +0 -41
  113. package/test/unit/outboundApi/data/mockGetPartiesError.json +0 -4
  114. package/test/unit/outboundApi/data/mockRequestToPayError.json +0 -32
  115. package/test/unit/outboundApi/data/mockRequestToPayTransferError.json +0 -39
  116. package/test/unit/outboundApi/data/requestToPay.json +0 -21
  117. package/test/unit/outboundApi/data/requestToPayTransferRequest.json +0 -20
  118. package/test/unit/outboundApi/data/transferRequest.json +0 -21
  119. package/test/unit/outboundApi/handlers.test.js +0 -887
@@ -1,477 +0,0 @@
1
- /**************************************************************************
2
- * (C) Copyright ModusBox Inc. 2021 - 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
- * Paweł Marzec - pawel.marzec@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
-
16
- const { uuid } = require('uuidv4');
17
- const Model = require('~/lib/model').QuotesModel;
18
- const PSM = require('~/lib/model/common').PersistentStateMachine;
19
- const { SDKStateEnum } = require('~/lib/model/common');
20
- const { MojaloopRequests } = require('@mojaloop/sdk-standard-components');
21
- const defaultConfig = require('./data/defaultConfig');
22
- const mockLogger = require('../../mockLogger');
23
- const deferredJob = require('~/lib/model/lib').deferredJob;
24
- const pt = require('promise-timeout');
25
- const putQuotesResponse = require('./data/putQuotesResponse.json');
26
-
27
- describe('QuotesModel', () => {
28
- let cacheKey;
29
- let data;
30
- let modelConfig;
31
-
32
- const subId = uuid();
33
- let handler = null;
34
- beforeEach(async () => {
35
-
36
- modelConfig = {
37
- logger: mockLogger({app: 'QuotesModel-test'}),
38
-
39
- // there is no need to mock redis but only Cache
40
- cache: {
41
- get: jest.fn(() => Promise.resolve(data)),
42
- set: jest.fn(() => Promise.resolve),
43
-
44
- // mock subscription and store handler
45
- subscribe: jest.fn(async (channel, h) => {
46
- handler = jest.fn(h);
47
- return subId;
48
- }),
49
-
50
- // mock publish and call stored handler
51
- publish: jest.fn(async (channel, message) => await handler(channel, message, subId)),
52
-
53
- unsubscribe: jest.fn(() => Promise.resolve())
54
- },
55
- ...defaultConfig
56
- };
57
- data = {
58
- the: 'mocked data'
59
- };
60
-
61
- cacheKey = `key-quotes-${uuid()}`;
62
- });
63
-
64
- describe('create', () => {
65
- test('proper creation of model', async () => {
66
- const model = await Model.create(data, cacheKey, modelConfig);
67
-
68
- expect(model.state).toBe('start');
69
-
70
- // model's methods layout
71
- const methods = [
72
- 'run',
73
- 'getResponse',
74
- 'onRequestAction'
75
- ];
76
-
77
- methods.forEach((method) => expect(typeof model[method]).toEqual('function'));
78
- });
79
- });
80
-
81
- describe('getResponse', () => {
82
-
83
- it('should remap currentState', async () => {
84
- const model = await Model.create(data, cacheKey, modelConfig);
85
- const states = model.allStates();
86
- // should remap for all states except 'init' and 'none'
87
- states.filter((s) => s !== 'init' && s !== 'none').forEach((state) => {
88
- model.context.data.currentState = state;
89
- const result = model.getResponse();
90
- expect(result.currentState).toEqual(Model.mapCurrentState[state]);
91
- });
92
-
93
- });
94
-
95
- it('should handle unexpected state', async() => {
96
- const model = await Model.create(data, cacheKey, modelConfig);
97
-
98
- // simulate lack of state by undefined property
99
- delete model.context.data.currentState;
100
-
101
- const resp = model.getResponse();
102
- expect(resp.currentState).toEqual(Model.mapCurrentState.errored);
103
-
104
- // ensure that we log the problem properly
105
- expect(modelConfig.logger.error).toHaveBeenCalledWith(`QuotesModel model response being returned from an unexpected state: ${undefined}. Returning ERROR_OCCURRED state`);
106
- });
107
- });
108
-
109
- describe('channelName', () => {
110
- it('should validate input', () => {
111
- expect(Model.channelName({})).toEqual('quotes-undefined');
112
- });
113
-
114
- it('should generate proper channel name', () => {
115
- const quoteId = uuid();
116
- expect(Model.channelName({ quoteId })).toEqual(`quotes-${quoteId}`);
117
- });
118
-
119
- });
120
-
121
- describe('generateKey', () => {
122
- it('should generate proper cache key', () => {
123
- const quoteId = uuid();
124
- expect(Model.generateKey({ quoteId })).toEqual(`key-${Model.channelName({ quoteId })}`);
125
- });
126
-
127
- it('should handle lack of quoteId param', () => {
128
- expect(() => Model.generateKey({ })).toThrowError(new Error('QuotesModel args requires \'quoteId\' is nonempty string and mandatory property'));
129
- });
130
-
131
- });
132
-
133
- describe('onRequestAction', () => {
134
-
135
- it('should implement happy flow', async () => {
136
- const quoteId = uuid();
137
- const fspId = uuid();
138
- // our code takes care only about 'quoteId' property
139
- const quote = { quoteId };
140
- const channel = Model.channelName({ quoteId });
141
- const model = await Model.create(data, cacheKey, modelConfig);
142
- const { cache } = model.context;
143
- // mock workflow execution which is tested in separate case
144
- model.run = jest.fn(() => Promise.resolve());
145
-
146
- const message = {
147
- body: { ...putQuotesResponse },
148
- headers: {}
149
- };
150
-
151
- const onRequestActionPromise = new Promise((resolve, reject) => {
152
- // manually invoke transition handler
153
- model.onRequestAction(model.fsm, { quoteId, fspId, quote })
154
- .then(() => {
155
- // subscribe should be called only once
156
- expect(cache.subscribe).toBeCalledTimes(1);
157
-
158
- // subscribe should be done to proper notificationChannel
159
- expect(cache.subscribe.mock.calls[0][0]).toEqual(channel);
160
-
161
- // check invocation of request.getParties
162
- expect(MojaloopRequests.__postQuotes).toBeCalledWith(quote, fspId);
163
-
164
- // check that this.context.data is updated
165
- expect(model.context.data).toEqual({
166
- quotes: { ...message },
167
- // current state will be updated by onAfterTransition which isn't called
168
- // when manual invocation of transition handler happens
169
- currentState: 'start'
170
- });
171
- // handler should be called only once
172
- expect(handler).toBeCalledTimes(1);
173
-
174
- // handler should unsubscribe from notification channel
175
- expect(cache.unsubscribe).toBeCalledTimes(1);
176
- expect(cache.unsubscribe).toBeCalledWith(channel, subId);
177
- resolve();
178
- }).catch((err) => { reject(err); } );
179
- });
180
-
181
- // ensure handler wasn't called before publishing the message
182
- expect(handler).not.toBeCalled();
183
-
184
- // ensure that cache.unsubscribe does not happened before fire the message
185
- expect(cache.unsubscribe).not.toBeCalled();
186
-
187
- // fire publication with given message
188
- const df = deferredJob(cache, channel);
189
- setImmediate(() => df.trigger(message));
190
-
191
- // wait for onRequestAction
192
- await onRequestActionPromise;
193
- });
194
-
195
- it('should handle timeouts', async () => {
196
- const quoteId = uuid();
197
- const fspId = uuid();
198
- // our code takes care only about 'quoteId' property
199
- const quote = { quoteId };
200
- const channel = Model.channelName({ quoteId });
201
-
202
- const model = await Model.create(data, cacheKey, modelConfig);
203
- const { cache } = model.context;
204
- // mock workflow execution which is tested in separate case
205
- model.run = jest.fn(() => Promise.resolve());
206
-
207
- const message = {
208
- body: { ...putQuotesResponse },
209
- headers: {}
210
- };
211
-
212
- const onRequestActionPromise = new Promise((resolve, reject) => {
213
- // manually invoke transition handler
214
- model.onRequestAction(model.fsm, { quoteId, fspId, quote })
215
- .then(() => reject())
216
- .catch((err) => {
217
- // subscribe should be called only once
218
- expect(err instanceof pt.TimeoutError).toBeTruthy();
219
-
220
- // subscribe should be done to proper notificationChannel
221
- expect(cache.subscribe.mock.calls[0][0]).toEqual(channel);
222
-
223
- // check invocation of request.getParties
224
- expect(MojaloopRequests.__postQuotes).toBeCalledWith(quote, fspId);
225
-
226
- // handler should be called only once
227
- expect(handler).toBeCalledTimes(0);
228
-
229
- // handler should unsubscribe from notification channel
230
- expect(cache.unsubscribe).toBeCalledTimes(1);
231
- expect(cache.unsubscribe).toBeCalledWith(channel, subId);
232
- resolve();
233
- });
234
- });
235
-
236
- // ensure handler wasn't called before publishing the message
237
- expect(handler).not.toBeCalled();
238
-
239
- // ensure that cache.unsubscribe does not happened before fire the message
240
- expect(cache.unsubscribe).not.toBeCalled();
241
-
242
- // fire publication with given message
243
- const df = deferredJob(cache, channel);
244
-
245
- setTimeout(
246
- () => { df.trigger(message); },
247
- // ensure that publication will be far long after timeout should be auto triggered
248
- (modelConfig.requestProcessingTimeoutSeconds+1)*1000
249
- );
250
-
251
- // wait for onRequestAction
252
- await onRequestActionPromise;
253
- });
254
-
255
- it('should unsubscribe from cache in case when error happens in workflow run', async () => {
256
- const quoteId = uuid();
257
- const fspId = uuid();
258
- // our code takes care only about 'quoteId' property
259
- const quote = { quoteId };
260
- const channel = Model.channelName({ quoteId });
261
- const model = await Model.create(data, cacheKey, modelConfig);
262
- const { cache } = model.context;
263
-
264
- // fire publication to channel with invalid message
265
- // should throw the exception from JSON.parse
266
- const df = deferredJob(cache, channel);
267
- setImmediate(() => df.trigger(undefined));
268
-
269
- // invoke transition handler
270
- try {
271
- await model.onRequestAction(model.fsm, { quoteId, fspId, quote });
272
- throw new Error('this point should not be reached');
273
- } catch (err) {
274
- expect(err.message).toEqual('Unexpected token u in JSON at position 0');
275
- expect(cache.unsubscribe).toBeCalledTimes(1);
276
- expect(cache.unsubscribe).toBeCalledWith(channel, subId);
277
- }
278
- });
279
-
280
- it('should unsubscribe from cache in case when error happens Mojaloop requests', async () => {
281
- // simulate error
282
- MojaloopRequests.__postQuotes = jest.fn(() => Promise.reject('postQuotes failed'));
283
- const quoteId = uuid();
284
- const fspId = uuid();
285
- // our code takes care only about 'quoteId' property
286
- const quote = { quoteId };
287
- const channel = Model.channelName({ quoteId });
288
- const model = await Model.create(data, cacheKey, modelConfig);
289
- const { cache } = model.context;
290
-
291
- let theError = null;
292
- // invoke transition handler
293
- try {
294
- await model.onRequestAction(model.fsm, { quoteId, fspId, quote });
295
- throw new Error('this point should not be reached');
296
- } catch (error) {
297
- theError = error;
298
- expect(theError).toEqual('postQuotes failed');
299
- // handler should unsubscribe from notification channel
300
- expect(cache.unsubscribe).toBeCalledTimes(1);
301
- expect(cache.unsubscribe).toBeCalledWith(channel, subId);
302
- }
303
- });
304
-
305
- });
306
-
307
- describe('run workflow', () => {
308
- it('start', async () => {
309
- const quoteId = uuid();
310
- const fspId = uuid();
311
- // our code takes care only about 'quoteId' property
312
- const quote = { quoteId };
313
-
314
- const model = await Model.create(data, cacheKey, modelConfig);
315
-
316
- model.requestAction = jest.fn();
317
- model.getResponse = jest.fn(() => Promise.resolve({the: 'response'}));
318
-
319
- model.context.data.currentState = 'start';
320
- const result = await model.run({ quoteId, fspId, quote });
321
- expect(result).toEqual({the: 'response'});
322
- expect(model.requestAction).toBeCalledTimes(1);
323
- expect(model.getResponse).toBeCalledTimes(1);
324
- expect(model.context.logger.log.mock.calls).toEqual([
325
- ['State machine transitioned \'init\': none -> start'],
326
- ['Action called successfully'],
327
- [`Persisted model in cache: ${cacheKey}`],
328
- ]);
329
- });
330
- it('succeeded', async () => {
331
- const quoteId = uuid();
332
- const fspId = uuid();
333
- // our code takes care only about 'quoteId' property
334
- const quote = { quoteId };
335
-
336
- const model = await Model.create(data, cacheKey, modelConfig);
337
-
338
- model.getResponse = jest.fn(() => Promise.resolve({the: 'response'}));
339
-
340
- model.context.data.currentState = 'succeeded';
341
- const result = await model.run({ quoteId, fspId, quote });
342
-
343
- expect(result).toEqual({the: 'response'});
344
- expect(model.getResponse).toBeCalledTimes(1);
345
- expect(model.context.logger.log).toBeCalledWith('Action called successfully');
346
- });
347
-
348
- it('errored', async () => {
349
- const quoteId = uuid();
350
- const fspId = uuid();
351
- // our code takes care only about 'quoteId' property
352
- const quote = { quoteId };
353
-
354
- const model = await Model.create(data, cacheKey, modelConfig);
355
-
356
- model.getResponse = jest.fn(() => Promise.resolve({the: 'response'}));
357
-
358
- model.context.data.currentState = 'errored';
359
- const result = await model.run({ quoteId, fspId, quote});
360
-
361
- expect(result).toBeFalsy();
362
- expect(model.getResponse).not.toBeCalled();
363
- expect(model.context.logger.log).toBeCalledWith('State machine in errored state');
364
- });
365
-
366
- it('handling errors', async () => {
367
- const quoteId = uuid();
368
- const fspId = uuid();
369
- // our code takes care only about 'quoteId' property
370
- const quote = { quoteId };
371
-
372
- const model = await Model.create(data, cacheKey, modelConfig);
373
-
374
- model.requestAction = jest.fn(() => { throw new Error('mocked error'); });
375
-
376
- model.context.data.currentState = 'start';
377
-
378
- try {
379
- await model.run({ quoteId, fspId, quote });
380
- throw new Error('this point should not be reached');
381
- } catch (err) {
382
- expect(model.context.data.currentState).toEqual('errored');
383
- expect(err.requestActionState).toEqual( {
384
- ...data,
385
- currentState: SDKStateEnum.ERROR_OCCURRED,
386
- });
387
- }
388
- });
389
-
390
- it('should handle errors', async () => {
391
- const quoteId = uuid();
392
- const fspId = uuid();
393
- // our code takes care only about 'quoteId' property
394
- const quote = { quoteId };
395
-
396
- const model = await Model.create(data, cacheKey, modelConfig);
397
-
398
- model.requestAction = jest.fn(() => {
399
- const err = new Error('requestAction failed');
400
- err.requestActionState = 'some';
401
- return Promise.reject(err);
402
- });
403
- model.error = jest.fn();
404
- model.context.data.currentState = 'start';
405
-
406
- let theError = null;
407
- try {
408
- await model.run({ quoteId, fspId, quote });
409
- throw new Error('this point should not be reached');
410
- } catch(error) {
411
- theError = error;
412
- }
413
- // check propagation of original error
414
- expect(theError.message).toEqual('requestAction failed');
415
-
416
- // ensure we start transition to errored state
417
- expect(model.error).toBeCalledTimes(1);
418
- });
419
-
420
- it('should handle input validation for lack of quoteId param', async () => {
421
- const model = await Model.create(data, cacheKey, modelConfig);
422
-
423
- expect(() => model.run({}))
424
- .rejects.toEqual(
425
- new Error('QuotesModel args requires \'quoteId\' is nonempty string and mandatory property')
426
- );
427
- });
428
-
429
- it('should handle input validation for not quoteId & quote.quoteId be in sync', async () => {
430
- const quoteId = uuid();
431
- const model = await Model.create(data, cacheKey, modelConfig);
432
-
433
- expect(() => model.run({quoteId, quote: { quoteId: uuid()}}))
434
- .rejects.toEqual(
435
- new Error('QuotesModel args requires properties \'quote.quoteId\' and \'quoteId\' to be the equal in value')
436
- );
437
- });
438
-
439
- it('should handle input validation for fspId param', async () => {
440
- const quoteId = uuid();
441
- const model = await Model.create(data, cacheKey, modelConfig);
442
-
443
- expect(() => model.run({quoteId, fspId:'' }))
444
- .rejects.toEqual(
445
- new Error('QuotesModel args requires \'fspId\' to be nonempty string')
446
- );
447
- });
448
-
449
- });
450
-
451
- describe('loadFromCache', () => {
452
- test('should use PSM.loadFromCache properly', async () => {
453
- const spyLoadFromCache = jest.spyOn(PSM, 'loadFromCache');
454
- const key = uuid();
455
-
456
- // act
457
- const model = await Model.loadFromCache(key, modelConfig);
458
-
459
- // assert
460
- // check does model is proper
461
- expect(typeof model.requestAction).toEqual('function');
462
-
463
- // check how cache.get has been called
464
- expect(modelConfig.cache.get).toBeCalledWith(key);
465
-
466
- // check how loadFromCache from parent PSM module was used
467
- expect(spyLoadFromCache).toBeCalledTimes(1);
468
- expect(spyLoadFromCache).toBeCalledWith(
469
- modelConfig.cache,
470
- key,
471
- modelConfig.logger,
472
- expect.anything(),
473
- expect.anything()
474
- );
475
- });
476
- });
477
- });