@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,478 +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
- * 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').PartiesModel;
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
-
26
- describe('PartiesModel', () => {
27
- let cacheKey;
28
- let data;
29
- let modelConfig;
30
-
31
- const subId = 123;
32
- let handler = null;
33
- beforeEach(async () => {
34
-
35
- modelConfig = {
36
- logger: mockLogger({app: 'PartiesModel-test'}),
37
-
38
- // there is no need to mock redis but only Cache
39
- cache: {
40
- get: jest.fn(() => Promise.resolve(data)),
41
- set: jest.fn(() => Promise.resolve),
42
-
43
- // mock subscription and store handler
44
- subscribe: jest.fn(async (channel, h) => {
45
- handler = jest.fn(h);
46
- return subId;
47
- }),
48
-
49
- // mock publish and call stored handler
50
- publish: jest.fn(async (channel, message) => await handler(channel, message, subId)),
51
-
52
- unsubscribe: jest.fn(() => Promise.resolve())
53
- },
54
- ...defaultConfig
55
- };
56
- data = { the: 'mocked data' };
57
-
58
- cacheKey = 'cache-key';
59
- });
60
-
61
- describe('create', () => {
62
- test('proper creation of model', async () => {
63
- const model = await Model.create(data, cacheKey, modelConfig);
64
-
65
- expect(model.state).toBe('start');
66
-
67
- // model's methods layout
68
- const methods = [
69
- 'run',
70
- 'getResponse',
71
- 'onRequestAction'
72
- ];
73
-
74
- methods.forEach((method) => expect(typeof model[method]).toEqual('function'));
75
- });
76
- });
77
-
78
- describe('getResponse', () => {
79
-
80
- it('should remap currentState', async () => {
81
- const model = await Model.create(data, cacheKey, modelConfig);
82
- const states = model.allStates();
83
- // should remap for all states except 'init' and 'none'
84
- states.filter((s) => s !== 'init' && s !== 'none').forEach((state) => {
85
- model.context.data.currentState = state;
86
- const result = model.getResponse();
87
- expect(result.currentState).toEqual(Model.mapCurrentState[state]);
88
- });
89
-
90
- });
91
-
92
- it('should handle unexpected state', async() => {
93
- const model = await Model.create(data, cacheKey, modelConfig);
94
-
95
- // simulate lack of state by undefined property
96
- delete model.context.data.currentState;
97
-
98
- const resp = model.getResponse();
99
- expect(resp.currentState).toEqual(Model.mapCurrentState.errored);
100
-
101
- // ensure that we log the problem properly
102
- expect(modelConfig.logger.error).toHaveBeenCalledWith(`PartiesModel model response being returned from an unexpected state: ${undefined}. Returning ERROR_OCCURRED state`);
103
- });
104
- });
105
-
106
- describe('channelName', () => {
107
- it('should validate input', () => {
108
- expect(Model.channelName({})).toEqual('parties-undefined-undefined-undefined');
109
- });
110
-
111
- it('should generate proper channel name', () => {
112
- const type = uuid();
113
- const id = uuid();
114
- expect(Model.channelName({ type, id })).toEqual(`parties-${type}-${id}-undefined`);
115
- });
116
-
117
- it('should generate proper channel name when all params specified', () => {
118
- const type = uuid();
119
- const id = uuid();
120
- const subId = uuid();
121
- expect(Model.channelName({ type, id, subId })).toEqual(`parties-${type}-${id}-${subId}`);
122
- });
123
- });
124
-
125
- describe('generateKey', () => {
126
- it('should generate proper cache key', () => {
127
- const type = uuid();
128
- const id = uuid();
129
- expect(Model.generateKey({ type, id })).toEqual(`key-${Model.channelName({ type, id })}`);
130
- });
131
-
132
- it('should handle lack of id param', () => {
133
- const type = uuid();
134
- expect(() => Model.generateKey({ type })).toThrowError(new Error('PartiesModel args required at least two string arguments: \'type\' and \'id\''));
135
- });
136
-
137
- it('should handle all params', () => {
138
- const type = uuid();
139
- const id = uuid();
140
- const subId = uuid();
141
- expect(Model.generateKey({ type, id, subId })).toEqual(`key-${Model.channelName({ type, id, subId })}`);
142
- });
143
- });
144
-
145
- describe('onRequestAction', () => {
146
-
147
- it('should implement happy flow', async () => {
148
- const type = uuid();
149
- const id = uuid();
150
- const subIdValue = uuid();
151
-
152
- const channel = Model.channelName({ type, id, subId: subIdValue });
153
- const model = await Model.create(data, cacheKey, modelConfig);
154
- const { cache } = model.context;
155
- // mock workflow execution which is tested in separate case
156
- model.run = jest.fn(() => Promise.resolve());
157
-
158
- const message = {
159
- body: {
160
- party: {
161
- Iam: 'the-body'
162
- }
163
- },
164
- headers: {}
165
- };
166
-
167
- const onRequestActionPromise = new Promise((resolve, reject) => {
168
- // manually invoke transition handler
169
- model.onRequestAction(model.fsm, { type, id, subId: subIdValue })
170
- .then(() => {
171
- // subscribe should be called only once
172
- expect(cache.subscribe).toBeCalledTimes(1);
173
-
174
- // subscribe should be done to proper notificationChannel
175
- expect(cache.subscribe.mock.calls[0][0]).toEqual(channel);
176
-
177
- // check invocation of request.getParties
178
- expect(MojaloopRequests.__getParties).toBeCalledWith(type, id, subIdValue);
179
-
180
- // check that this.context.data is updated
181
- expect(model.context.data).toEqual({
182
- party: {
183
- body: { ...message.body.party },
184
- headers: { ...message.headers }
185
- },
186
- // current state will be updated by onAfterTransition which isn't called
187
- // when manual invocation of transition handler happens
188
- currentState: 'start'
189
- });
190
- // handler should be called only once
191
- expect(handler).toBeCalledTimes(1);
192
-
193
- // handler should unsubscribe from notification channel
194
- expect(cache.unsubscribe).toBeCalledTimes(1);
195
- expect(cache.unsubscribe).toBeCalledWith(channel, subId);
196
- resolve();
197
- }).catch((err) => { reject(err); } );
198
- });
199
-
200
- // ensure handler wasn't called before publishing the message
201
- expect(handler).not.toBeCalled();
202
-
203
- // ensure that cache.unsubscribe does not happened before fire the message
204
- expect(cache.unsubscribe).not.toBeCalled();
205
-
206
- // fire publication with given message
207
- const df = deferredJob(cache, channel);
208
- setImmediate(() => df.trigger(message));
209
-
210
- // wait for onRequestAction
211
- await onRequestActionPromise;
212
- });
213
-
214
- it('should handle timeouts', async () => {
215
- const type = uuid();
216
- const id = uuid();
217
- const subIdValue = uuid();
218
-
219
- const channel = Model.channelName({ type, id, subId: subIdValue });
220
- const model = await Model.create(data, cacheKey, modelConfig);
221
- const { cache } = model.context;
222
- // mock workflow execution which is tested in separate case
223
- model.run = jest.fn(() => Promise.resolve());
224
-
225
- const message = {
226
- body: {
227
- party: {
228
- Iam: 'the-body'
229
- }
230
- },
231
- headers: {}
232
- };
233
-
234
- const onRequestActionPromise = new Promise((resolve, reject) => {
235
- // manually invoke transition handler
236
- model.onRequestAction(model.fsm, { type, id, subId: subIdValue })
237
- .then(() => reject())
238
- .catch((err) => {
239
- // subscribe should be called only once
240
- expect(err instanceof pt.TimeoutError).toBeTruthy();
241
-
242
- // subscribe should be done to proper notificationChannel
243
- expect(cache.subscribe.mock.calls[0][0]).toEqual(channel);
244
-
245
- // check invocation of request.getParties
246
- expect(MojaloopRequests.__getParties).toBeCalledWith(type, id, subIdValue);
247
-
248
- // handler should be called only once
249
- expect(handler).toBeCalledTimes(0);
250
-
251
- // handler should unsubscribe from notification channel
252
- expect(cache.unsubscribe).toBeCalledTimes(1);
253
- expect(cache.unsubscribe).toBeCalledWith(channel, subId);
254
- resolve();
255
- });
256
- });
257
-
258
- // ensure handler wasn't called before publishing the message
259
- expect(handler).not.toBeCalled();
260
-
261
- // ensure that cache.unsubscribe does not happened before fire the message
262
- expect(cache.unsubscribe).not.toBeCalled();
263
-
264
- // fire publication with given message
265
- const df = deferredJob(cache, channel);
266
-
267
- setTimeout(
268
- () => { df.trigger(message); },
269
- // ensure that publication will be far long after timeout should be auto triggered
270
- (modelConfig.requestProcessingTimeoutSeconds+1)*1000
271
- );
272
-
273
- // wait for onRequestAction
274
- await onRequestActionPromise;
275
- });
276
-
277
- it('should unsubscribe from cache in case when error happens in workflow run', async () => {
278
- const type = uuid();
279
- const id = uuid();
280
- const subIdValue = uuid();
281
-
282
- const channel = Model.channelName({ type, id, subId: subIdValue });
283
- const model = await Model.create(data, cacheKey, modelConfig);
284
- const { cache } = model.context;
285
-
286
- const onRequestActionPromise = new Promise((resolve, reject) => {
287
- // invoke transition handler
288
- model.onRequestAction(model.fsm, { type, id, subId: subIdValue })
289
- .then(() => reject())
290
- .catch((err) => {
291
- expect(err.message).toEqual('Unexpected token u in JSON at position 0');
292
- expect(cache.unsubscribe).toBeCalledTimes(1);
293
- expect(cache.unsubscribe).toBeCalledWith(channel, subId);
294
- resolve();
295
- });
296
- });
297
-
298
- // fire publication to channel with invalid message
299
- // should throw the exception from JSON.parse
300
- const df = deferredJob(cache, channel);
301
- setImmediate(() => df.trigger(undefined));
302
-
303
- // wait for onRequestAction
304
- await onRequestActionPromise;
305
- });
306
-
307
- it('should unsubscribe from cache in case when error happens Mojaloop requests', async () => {
308
- // simulate error
309
- MojaloopRequests.__getParties = jest.fn(() => Promise.reject('getParties failed'));
310
- const type = uuid();
311
- const id = uuid();
312
- const subIdValue = uuid();
313
-
314
- const channel = Model.channelName({ type, id, subId: subIdValue });
315
- const model = await Model.create(data, cacheKey, modelConfig);
316
- const { cache } = model.context;
317
-
318
- let theError = null;
319
- // invoke transition handler
320
- try {
321
- await model.onRequestAction(model.fsm, { type, id, subId: subIdValue });
322
- throw new Error('this point should not be reached');
323
- } catch (error) {
324
- theError = error;
325
- expect(theError).toEqual('getParties failed');
326
- // handler should unsubscribe from notification channel
327
- expect(cache.unsubscribe).toBeCalledTimes(1);
328
- expect(cache.unsubscribe).toBeCalledWith(channel, subId);
329
- }
330
- });
331
-
332
- });
333
-
334
- describe('run workflow', () => {
335
- it('start', async () => {
336
- const type = uuid();
337
- const id = uuid();
338
- const subIdValue = uuid();
339
-
340
- const model = await Model.create(data, cacheKey, modelConfig);
341
-
342
- model.requestAction = jest.fn();
343
- model.getResponse = jest.fn(() => Promise.resolve({the: 'response'}));
344
-
345
- model.context.data.currentState = 'start';
346
- const result = await model.run({ type, id, subId: subIdValue });
347
- expect(result).toEqual({the: 'response'});
348
- expect(model.requestAction).toBeCalledTimes(1);
349
- expect(model.getResponse).toBeCalledTimes(1);
350
- expect(model.context.logger.log.mock.calls).toEqual([
351
- ['State machine transitioned \'init\': none -> start'],
352
- ['Action called successfully'],
353
- [`Persisted model in cache: ${cacheKey}`],
354
- ]);
355
- });
356
- it('succeeded', async () => {
357
- const type = uuid();
358
- const id = uuid();
359
- const subIdValue = uuid();
360
-
361
- const model = await Model.create(data, cacheKey, modelConfig);
362
-
363
- model.getResponse = jest.fn(() => Promise.resolve({the: 'response'}));
364
-
365
- model.context.data.currentState = 'succeeded';
366
- const result = await model.run({ type, id, subId: subIdValue });
367
-
368
- expect(result).toEqual({the: 'response'});
369
- expect(model.getResponse).toBeCalledTimes(1);
370
- expect(model.context.logger.log).toBeCalledWith('Action called successfully');
371
- });
372
-
373
- it('errored', async () => {
374
- const type = uuid();
375
- const id = uuid();
376
- const subIdValue = uuid();
377
-
378
- const model = await Model.create(data, cacheKey, modelConfig);
379
-
380
- model.getResponse = jest.fn(() => Promise.resolve({the: 'response'}));
381
-
382
- model.context.data.currentState = 'errored';
383
- const result = await model.run({ type, id, subId: subIdValue });
384
-
385
- expect(result).toBeFalsy();
386
- expect(model.getResponse).not.toBeCalled();
387
- expect(model.context.logger.log).toBeCalledWith('State machine in errored state');
388
- });
389
-
390
- it('handling errors', async () => {
391
- const type = uuid();
392
- const id = uuid();
393
- const subIdValue = uuid();
394
-
395
- const model = await Model.create(data, cacheKey, modelConfig);
396
-
397
- model.requestAction = jest.fn(() => { throw new Error('mocked error'); });
398
-
399
- model.context.data.currentState = 'start';
400
- try {
401
- await model.run({ type, id, subId: subIdValue });
402
- throw new Error('this point should not be reached');
403
- } catch (err) {
404
- expect(model.context.data.currentState).toEqual('errored');
405
- expect(err.requestActionState).toEqual( {
406
- ...data,
407
- currentState: SDKStateEnum.ERROR_OCCURRED,
408
- });
409
- }
410
- });
411
-
412
- it('should handle errors', async () => {
413
- const type = uuid();
414
- const id = uuid();
415
- const subIdValue = uuid();
416
-
417
- const model = await Model.create(data, cacheKey, modelConfig);
418
-
419
- model.requestAction = jest.fn(() => {
420
- const err = new Error('requestAction failed');
421
- err.requestActionState = 'some';
422
- return Promise.reject(err);
423
- });
424
- model.error = jest.fn();
425
- model.context.data.currentState = 'start';
426
-
427
- let theError = null;
428
- try {
429
- await model.run({ type, id, subId: subIdValue });
430
- throw new Error('this point should not be reached');
431
- } catch(error) {
432
- theError = error;
433
- }
434
- // check propagation of original error
435
- expect(theError.message).toEqual('requestAction failed');
436
-
437
- // ensure we start transition to errored state
438
- expect(model.error).toBeCalledTimes(1);
439
- });
440
-
441
- it('should handle input validation for id/subId params', async () => {
442
- const type = uuid();
443
- const model = await Model.create(data, cacheKey, modelConfig);
444
-
445
- expect(() => model.run(type))
446
- .rejects.toEqual(
447
- new Error('PartiesModel args required at least two string arguments: \'type\' and \'id\'')
448
- );
449
- });
450
- });
451
-
452
- describe('loadFromCache', () => {
453
- test('should use PSM.loadFromCache properly', async () => {
454
- const spyLoadFromCache = jest.spyOn(PSM, 'loadFromCache');
455
- const key = uuid();
456
-
457
- // act
458
- const model = await Model.loadFromCache(key, modelConfig);
459
-
460
- // assert
461
- // check does model is proper
462
- expect(typeof model.requestAction).toEqual('function');
463
-
464
- // check how cache.get has been called
465
- expect(modelConfig.cache.get).toBeCalledWith(key);
466
-
467
- // check how loadFromCache from parent PSM module was used
468
- expect(spyLoadFromCache).toBeCalledTimes(1);
469
- expect(spyLoadFromCache).toBeCalledWith(
470
- modelConfig.cache,
471
- key,
472
- modelConfig.logger,
473
- expect.anything(),
474
- expect.anything()
475
- );
476
- });
477
- });
478
- });