@mojaloop/sdk-scheme-adapter 11.18.8 → 11.18.9
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/CHANGELOG.md +2 -0
- package/InboundServer/api.yaml +2 -0
- package/InboundServer/handlers.js +0 -38
- package/OutboundServer/api.yaml +23 -270
- package/OutboundServer/api_interfaces/openapi.d.ts +10 -127
- package/OutboundServer/api_template/openapi.yaml +0 -3
- package/OutboundServer/handlers.js +2 -40
- package/audit-resolve.json +80 -0
- package/lib/model/index.js +1 -3
- package/package.json +2 -2
- package/test/__mocks__/@mojaloop/sdk-standard-components.js +0 -2
- package/test/config/integration.env +0 -3
- package/test/unit/inboundApi/handlers.test.js +0 -46
- package/test/unit/outboundApi/handlers.test.js +1 -100
- package/OutboundServer/api_template/components/responses/authorizationPostSuccess.yaml +0 -5
- package/OutboundServer/api_template/components/responses/authorizationsServerError.yaml +0 -5
- package/OutboundServer/api_template/components/schemas/authorizationsPostRequest.yaml +0 -15
- package/OutboundServer/api_template/components/schemas/authorizationsPostResponse.yaml +0 -19
- package/OutboundServer/api_template/components/schemas/errorAuthorizationsResponse.yaml +0 -3
- package/OutboundServer/api_template/paths/authorizations.yaml +0 -19
- package/lib/model/AuthorizationsModel.js +0 -86
- package/test/integration/lib/Outbound/authorizations.test.js +0 -58
- package/test/integration/lib/Outbound/data/authorizationsPostRequest.json +0 -43
- package/test/unit/lib/model/AuthorizationsModel.test.js +0 -460
- package/test/unit/lib/model/data/putAuthorizationsResponse.json +0 -10
package/audit-resolve.json
CHANGED
|
@@ -58,6 +58,86 @@
|
|
|
58
58
|
"1781|@mojaloop/event-sdk>grpc>@mapbox/node-pre-gyp>tar": {
|
|
59
59
|
"decision": "fix",
|
|
60
60
|
"madeAt": 1631785230676
|
|
61
|
+
},
|
|
62
|
+
"1002401|@mojaloop/event-sdk>@grpc/proto-loader>yargs>string-width>strip-ansi>ansi-regex": {
|
|
63
|
+
"decision": "ignore",
|
|
64
|
+
"madeAt": 1634716056413,
|
|
65
|
+
"expiresAt": 1637308004771
|
|
66
|
+
},
|
|
67
|
+
"1002401|@mojaloop/central-services-shared>widdershins>oas-resolver>yargs>string-width>strip-ansi>ansi-regex": {
|
|
68
|
+
"decision": "ignore",
|
|
69
|
+
"madeAt": 1634716056413,
|
|
70
|
+
"expiresAt": 1637308004771
|
|
71
|
+
},
|
|
72
|
+
"1002401|@mojaloop/central-services-shared>widdershins>oas-resolver>yargs>cliui>string-width>strip-ansi>ansi-regex": {
|
|
73
|
+
"decision": "ignore",
|
|
74
|
+
"madeAt": 1634716056413,
|
|
75
|
+
"expiresAt": 1637308004771
|
|
76
|
+
},
|
|
77
|
+
"1002401|@mojaloop/central-services-shared>widdershins>swagger2openapi>oas-resolver>yargs>cliui>string-width>strip-ansi>ansi-regex": {
|
|
78
|
+
"decision": "ignore",
|
|
79
|
+
"madeAt": 1634716056413,
|
|
80
|
+
"expiresAt": 1637308004771
|
|
81
|
+
},
|
|
82
|
+
"1002401|@mojaloop/central-services-shared>widdershins>swagger2openapi>oas-validator>oas-resolver>yargs>cliui>string-width>strip-ansi>ansi-regex": {
|
|
83
|
+
"decision": "ignore",
|
|
84
|
+
"madeAt": 1634716056413,
|
|
85
|
+
"expiresAt": 1637308004771
|
|
86
|
+
},
|
|
87
|
+
"1002401|@mojaloop/central-services-shared>widdershins>swagger2openapi>oas-validator>oas-resolver>yargs>cliui>wrap-ansi>string-width>strip-ansi>ansi-regex": {
|
|
88
|
+
"decision": "ignore",
|
|
89
|
+
"madeAt": 1634716056413,
|
|
90
|
+
"expiresAt": 1637308004771
|
|
91
|
+
},
|
|
92
|
+
"1002401|@mojaloop/event-sdk>@grpc/proto-loader>yargs>cliui>wrap-ansi>strip-ansi>ansi-regex": {
|
|
93
|
+
"decision": "ignore",
|
|
94
|
+
"madeAt": 1634716056413,
|
|
95
|
+
"expiresAt": 1637308004771
|
|
96
|
+
},
|
|
97
|
+
"1002401|@mojaloop/central-services-shared>widdershins>oas-resolver>yargs>cliui>wrap-ansi>strip-ansi>ansi-regex": {
|
|
98
|
+
"decision": "ignore",
|
|
99
|
+
"madeAt": 1634716056413,
|
|
100
|
+
"expiresAt": 1637308004771
|
|
101
|
+
},
|
|
102
|
+
"1002401|@mojaloop/central-services-shared>widdershins>swagger2openapi>oas-resolver>yargs>cliui>wrap-ansi>strip-ansi>ansi-regex": {
|
|
103
|
+
"decision": "ignore",
|
|
104
|
+
"madeAt": 1634716056413,
|
|
105
|
+
"expiresAt": 1637308004771
|
|
106
|
+
},
|
|
107
|
+
"1002401|@mojaloop/central-services-shared>widdershins>swagger2openapi>oas-validator>oas-resolver>yargs>cliui>wrap-ansi>strip-ansi>ansi-regex": {
|
|
108
|
+
"decision": "ignore",
|
|
109
|
+
"madeAt": 1634716056413,
|
|
110
|
+
"expiresAt": 1637308004771
|
|
111
|
+
},
|
|
112
|
+
"1002401|@mojaloop/event-sdk>@grpc/proto-loader>yargs>cliui>strip-ansi>ansi-regex": {
|
|
113
|
+
"decision": "ignore",
|
|
114
|
+
"madeAt": 1634716056413,
|
|
115
|
+
"expiresAt": 1637308004771
|
|
116
|
+
},
|
|
117
|
+
"1002401|@mojaloop/central-services-shared>widdershins>yargs>string-width>strip-ansi>ansi-regex": {
|
|
118
|
+
"decision": "ignore",
|
|
119
|
+
"madeAt": 1634716073663,
|
|
120
|
+
"expiresAt": 1637308004771
|
|
121
|
+
},
|
|
122
|
+
"1002401|@mojaloop/central-services-shared>widdershins>yargs>cliui>string-width>strip-ansi>ansi-regex": {
|
|
123
|
+
"decision": "ignore",
|
|
124
|
+
"madeAt": 1634716073664,
|
|
125
|
+
"expiresAt": 1637308004771
|
|
126
|
+
},
|
|
127
|
+
"1002865|@mojaloop/central-services-shared>shins>sanitize-html": {
|
|
128
|
+
"decision": "ignore",
|
|
129
|
+
"madeAt": 1634716077764,
|
|
130
|
+
"expiresAt": 1637308004771
|
|
131
|
+
},
|
|
132
|
+
"1002866|@mojaloop/central-services-shared>shins>sanitize-html": {
|
|
133
|
+
"decision": "ignore",
|
|
134
|
+
"madeAt": 1634716077764,
|
|
135
|
+
"expiresAt": 1637308004771
|
|
136
|
+
},
|
|
137
|
+
"1003019|@mojaloop/central-services-shared>widdershins>yargs>yargs-parser": {
|
|
138
|
+
"decision": "ignore",
|
|
139
|
+
"madeAt": 1634716081521,
|
|
140
|
+
"expiresAt": 1637308004771
|
|
61
141
|
}
|
|
62
142
|
},
|
|
63
143
|
"rules": {},
|
package/lib/model/index.js
CHANGED
|
@@ -23,7 +23,6 @@ const { BackendError, PersistentStateMachine } = require('./common');
|
|
|
23
23
|
const PartiesModel = require('./PartiesModel');
|
|
24
24
|
const QuotesModel = require('./QuotesModel');
|
|
25
25
|
const TransfersModel = require('./TransfersModel');
|
|
26
|
-
const AuthorizationsModel = require('./AuthorizationsModel');
|
|
27
26
|
|
|
28
27
|
module.exports = {
|
|
29
28
|
AccountsModel,
|
|
@@ -38,6 +37,5 @@ module.exports = {
|
|
|
38
37
|
PersistentStateMachine,
|
|
39
38
|
PartiesModel,
|
|
40
39
|
QuotesModel,
|
|
41
|
-
TransfersModel
|
|
42
|
-
AuthorizationsModel
|
|
40
|
+
TransfersModel
|
|
43
41
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mojaloop/sdk-scheme-adapter",
|
|
3
|
-
"version": "11.18.
|
|
3
|
+
"version": "11.18.9",
|
|
4
4
|
"description": "An adapter for connecting to Mojaloop API enabled switches.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"devDependencies": {
|
|
80
80
|
"@babel/core": "^7.15.5",
|
|
81
81
|
"@babel/preset-env": "^7.15.6",
|
|
82
|
-
"@mojaloop/api-snippets": "^
|
|
82
|
+
"@mojaloop/api-snippets": "^13.0.3",
|
|
83
83
|
"@redocly/openapi-cli": "^1.0.0-beta.59",
|
|
84
84
|
"@types/jest": "^27.0.1",
|
|
85
85
|
"babel-jest": "^27.2.0",
|
|
@@ -26,7 +26,6 @@ class MockMojaloopRequests extends MojaloopRequests {
|
|
|
26
26
|
this.putQuotes = MockMojaloopRequests.__putQuotes;
|
|
27
27
|
this.putQuotesError = MockMojaloopRequests.__putQuotesError;
|
|
28
28
|
this.getAuthorizations = MockMojaloopRequests.__getAuthorizations;
|
|
29
|
-
this.postAuthorizations = MockMojaloopRequests.__postAuthorizations;
|
|
30
29
|
this.putAuthorizations = MockMojaloopRequests.__putAuthorizations;
|
|
31
30
|
this.getTransfers = MockMojaloopRequests.__getTransfers;
|
|
32
31
|
this.putTransactionRequests = MockMojaloopRequests.__putTransactionRequests;
|
|
@@ -50,7 +49,6 @@ MockMojaloopRequests.__postQuotes = jest.fn(() => Promise.resolve());
|
|
|
50
49
|
MockMojaloopRequests.__putQuotes = jest.fn(() => Promise.resolve());
|
|
51
50
|
MockMojaloopRequests.__putQuotesError = jest.fn(() => Promise.resolve());
|
|
52
51
|
MockMojaloopRequests.__getAuthorizations = jest.fn(() => Promise.resolve());
|
|
53
|
-
MockMojaloopRequests.__postAuthorizations = jest.fn(() => Promise.resolve());
|
|
54
52
|
MockMojaloopRequests.__putAuthorizations = jest.fn(() => Promise.resolve());
|
|
55
53
|
MockMojaloopRequests.__getTransfers = jest.fn(() => Promise.resolve());
|
|
56
54
|
MockMojaloopRequests.__putTransactionRequests = jest.fn(() => Promise.resolve());
|
|
@@ -127,9 +127,6 @@ QUOTES_ENDPOINT=ml-testing-toolkit:5000
|
|
|
127
127
|
# TRANSFERS_ENDPOINT
|
|
128
128
|
TRANSFERS_ENDPOINT=ml-testing-toolkit:5000
|
|
129
129
|
|
|
130
|
-
# Authorizations_ENDPOINT
|
|
131
|
-
TRANSACTION_REQUESTS_ENDPOINT=ml-testing-toolkit:5000
|
|
132
|
-
|
|
133
130
|
# To allow transfer without a previous quote request, set this value to true.
|
|
134
131
|
# The incoming transfer request should consists of an ILP packet and a matching condition in this case.
|
|
135
132
|
# The fulfilment will be generated from the provided ILP packet, and must hash to the provided condition.
|
|
@@ -17,7 +17,6 @@ const Model = require('../../../lib/model').InboundTransfersModel;
|
|
|
17
17
|
const QuotesModel = require('../../../lib/model').QuotesModel;
|
|
18
18
|
const PartiesModel = require('../../../lib/model').PartiesModel;
|
|
19
19
|
const TransfersModel = require('../../../lib/model').TransfersModel;
|
|
20
|
-
const AuthorizationsModel = require('../../../lib/model').AuthorizationsModel;
|
|
21
20
|
|
|
22
21
|
const mockArguments = require('./data/mockArguments');
|
|
23
22
|
const mockTransactionRequestData = require('./data/mockTransactionRequest');
|
|
@@ -527,51 +526,6 @@ describe('Inbound API handlers:', () => {
|
|
|
527
526
|
});
|
|
528
527
|
});
|
|
529
528
|
|
|
530
|
-
describe('PUT /authorizations', () => {
|
|
531
|
-
|
|
532
|
-
let mockContext;
|
|
533
|
-
|
|
534
|
-
beforeEach(() => {
|
|
535
|
-
mockContext = {
|
|
536
|
-
request: {
|
|
537
|
-
body: { the: 'mocked-body' },
|
|
538
|
-
headers: {
|
|
539
|
-
'fspiop-source': 'foo'
|
|
540
|
-
}
|
|
541
|
-
},
|
|
542
|
-
response: {},
|
|
543
|
-
state: {
|
|
544
|
-
conf: {},
|
|
545
|
-
path: {
|
|
546
|
-
params: {
|
|
547
|
-
'ID': '1234'
|
|
548
|
-
}
|
|
549
|
-
},
|
|
550
|
-
logger: new Logger.Logger({ context: { app: 'inbound-handlers-unit-test' }, stringify: () => '' }),
|
|
551
|
-
cache: {
|
|
552
|
-
publish: jest.fn(() => Promise.resolve(true))
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
};
|
|
556
|
-
|
|
557
|
-
});
|
|
558
|
-
|
|
559
|
-
test('calls `AuthorizationsModel.triggerDeferredJobSpy` with the expected arguments.', async () => {
|
|
560
|
-
const triggerDeferredJobSpy = jest.spyOn(AuthorizationsModel, 'triggerDeferredJob');
|
|
561
|
-
|
|
562
|
-
await expect(handlers['/authorizations/{ID}'].put(mockContext)).resolves.toBe(undefined);
|
|
563
|
-
|
|
564
|
-
expect(triggerDeferredJobSpy).toHaveBeenCalledTimes(1);
|
|
565
|
-
expect(triggerDeferredJobSpy).toBeCalledWith({
|
|
566
|
-
cache: mockContext.state.cache,
|
|
567
|
-
message: mockContext.request.body,
|
|
568
|
-
args: {
|
|
569
|
-
transactionRequestId: mockContext.state.path.params.ID
|
|
570
|
-
}
|
|
571
|
-
});
|
|
572
|
-
});
|
|
573
|
-
});
|
|
574
|
-
|
|
575
529
|
describe('PATCH /transfers/{ID}', () => {
|
|
576
530
|
let mockNotificationMessage;
|
|
577
531
|
|
|
@@ -35,8 +35,7 @@ const {
|
|
|
35
35
|
OutboundRequestToPayModel,
|
|
36
36
|
PartiesModel,
|
|
37
37
|
QuotesModel,
|
|
38
|
-
TransfersModel
|
|
39
|
-
AuthorizationsModel
|
|
38
|
+
TransfersModel
|
|
40
39
|
} = require('../../../lib/model');
|
|
41
40
|
|
|
42
41
|
/**
|
|
@@ -885,102 +884,4 @@ describe('Outbound API handlers:', () => {
|
|
|
885
884
|
});
|
|
886
885
|
});
|
|
887
886
|
});
|
|
888
|
-
describe('POST /authorizations', () => {
|
|
889
|
-
const mockContext = {
|
|
890
|
-
request: {
|
|
891
|
-
body: {
|
|
892
|
-
fspId: uuid(),
|
|
893
|
-
authorizationsPostRequest: {
|
|
894
|
-
transactionRequestId: uuid()
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
},
|
|
898
|
-
response: {},
|
|
899
|
-
state: {
|
|
900
|
-
conf: {},
|
|
901
|
-
wso2Auth: 'mocked wso2Auth',
|
|
902
|
-
logger: mockLogger({ app: 'outbound-api-handlers-test' }),
|
|
903
|
-
cache: {
|
|
904
|
-
subscribe: jest.fn(() => Promise.resolve())
|
|
905
|
-
}
|
|
906
|
-
},
|
|
907
|
-
};
|
|
908
|
-
test('happy flow', async () => {
|
|
909
|
-
|
|
910
|
-
// mock state machine
|
|
911
|
-
const mockedPSM = {
|
|
912
|
-
run: jest.fn(async () => ({ the: 'run response' }))
|
|
913
|
-
};
|
|
914
|
-
|
|
915
|
-
const createSpy = jest.spyOn(AuthorizationsModel, 'create')
|
|
916
|
-
.mockImplementationOnce(async () => mockedPSM);
|
|
917
|
-
|
|
918
|
-
// invoke handler
|
|
919
|
-
await handlers['/authorizations'].post(mockContext);
|
|
920
|
-
|
|
921
|
-
// PSM model creation
|
|
922
|
-
const state = mockContext.state;
|
|
923
|
-
const cacheKey = AuthorizationsModel.channelName({
|
|
924
|
-
transactionRequestId: mockContext.request.body.authorizationsPostRequest.transactionRequestId
|
|
925
|
-
});
|
|
926
|
-
const expectedConfig = {
|
|
927
|
-
cache: state.cache,
|
|
928
|
-
logger: state.logger,
|
|
929
|
-
wso2Auth: state.wso2Auth
|
|
930
|
-
};
|
|
931
|
-
expect(createSpy).toBeCalledWith({}, cacheKey, expectedConfig);
|
|
932
|
-
|
|
933
|
-
// run workflow
|
|
934
|
-
expect(mockedPSM.run).toBeCalledWith({
|
|
935
|
-
transactionRequestId: mockContext.request.body.authorizationsPostRequest.transactionRequestId,
|
|
936
|
-
fspId: mockContext.request.body.fspId,
|
|
937
|
-
authorization: mockContext.request.body.authorizationsPostRequest
|
|
938
|
-
});
|
|
939
|
-
|
|
940
|
-
// response
|
|
941
|
-
expect(mockContext.response.status).toBe(200);
|
|
942
|
-
expect(mockContext.response.body).toEqual({ the: 'run response' });
|
|
943
|
-
});
|
|
944
|
-
|
|
945
|
-
test('mojaloop error propagation for /authorizations/{ID}', async() => {
|
|
946
|
-
|
|
947
|
-
// mock state machine
|
|
948
|
-
const mockedPSM = {
|
|
949
|
-
run: jest.fn(async () => { throw { mocked: 'error' }; })
|
|
950
|
-
};
|
|
951
|
-
|
|
952
|
-
const createSpy = jest.spyOn(AuthorizationsModel, 'create')
|
|
953
|
-
.mockImplementationOnce(async () => mockedPSM);
|
|
954
|
-
|
|
955
|
-
// invoke handler
|
|
956
|
-
await handlers['/authorizations'].post(mockContext);
|
|
957
|
-
|
|
958
|
-
// PSM model creation
|
|
959
|
-
const state = mockContext.state;
|
|
960
|
-
const cacheKey = AuthorizationsModel.channelName({
|
|
961
|
-
transactionRequestId: mockContext.request.body.authorizationsPostRequest.transactionRequestId
|
|
962
|
-
});
|
|
963
|
-
const expectedConfig = {
|
|
964
|
-
cache: state.cache,
|
|
965
|
-
logger: state.logger,
|
|
966
|
-
wso2Auth: state.wso2Auth
|
|
967
|
-
};
|
|
968
|
-
expect(createSpy).toBeCalledWith({}, cacheKey, expectedConfig);
|
|
969
|
-
|
|
970
|
-
// run workflow
|
|
971
|
-
expect(mockedPSM.run).toBeCalledWith({
|
|
972
|
-
transactionRequestId: mockContext.request.body.authorizationsPostRequest.transactionRequestId,
|
|
973
|
-
fspId: mockContext.request.body.fspId,
|
|
974
|
-
authorization: mockContext.request.body.authorizationsPostRequest
|
|
975
|
-
});
|
|
976
|
-
|
|
977
|
-
// response
|
|
978
|
-
expect(mockContext.response.status).toBe(500);
|
|
979
|
-
expect(mockContext.response.body).toEqual({
|
|
980
|
-
message: 'Unspecified error',
|
|
981
|
-
requestAuthorizationsInformationState: {},
|
|
982
|
-
statusCode: '500',
|
|
983
|
-
});
|
|
984
|
-
});
|
|
985
|
-
});
|
|
986
887
|
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
title: AuthorizationsPostRequest
|
|
2
|
-
description: POST /authorizations Request object
|
|
3
|
-
type: object
|
|
4
|
-
properties:
|
|
5
|
-
fspId:
|
|
6
|
-
title: destination DFSP
|
|
7
|
-
$ref: >-
|
|
8
|
-
../../../../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/components/schemas/FspId.yaml
|
|
9
|
-
authorizationsPostRequest:
|
|
10
|
-
$ref: >-
|
|
11
|
-
../../../../node_modules/@mojaloop/api-snippets/thirdparty/openapi3/components/schemas/AuthorizationsPostRequest.yaml
|
|
12
|
-
required:
|
|
13
|
-
- fspId
|
|
14
|
-
- authorizationsPostRequest
|
|
15
|
-
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
title: AuthorizationsPostResponse
|
|
2
|
-
description: POST /authorizations response object
|
|
3
|
-
type: object
|
|
4
|
-
properties:
|
|
5
|
-
authorizations:
|
|
6
|
-
type: object
|
|
7
|
-
properties:
|
|
8
|
-
authenticationInfo:
|
|
9
|
-
$ref: '../../../../node_modules/@mojaloop/api-snippets/thirdparty/openapi3/components/schemas/AuthenticationInfo.yaml'
|
|
10
|
-
responseType:
|
|
11
|
-
$ref: '../../../../node_modules/@mojaloop/api-snippets/thirdparty/openapi3/components/schemas/AuthorizationResponseType.yaml'
|
|
12
|
-
required:
|
|
13
|
-
- responseType
|
|
14
|
-
currentState:
|
|
15
|
-
$ref: ../schemas/async2SyncCurrentState.yaml
|
|
16
|
-
required:
|
|
17
|
-
- authorizations
|
|
18
|
-
- currentState
|
|
19
|
-
additionalProperties: false
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
post:
|
|
2
|
-
description: The HTTP request `POST /authorizations` is used to request the Payer to enter the applicable credentials in the PISP system.
|
|
3
|
-
summary: Authorizations endpoint
|
|
4
|
-
operationId: AuthorizationsPost
|
|
5
|
-
tags:
|
|
6
|
-
- authorizations
|
|
7
|
-
requestBody:
|
|
8
|
-
description: Perform authorization
|
|
9
|
-
required: true
|
|
10
|
-
content:
|
|
11
|
-
application/json:
|
|
12
|
-
schema:
|
|
13
|
-
$ref: '../components/schemas/authorizationsPostRequest.yaml'
|
|
14
|
-
responses:
|
|
15
|
-
200:
|
|
16
|
-
$ref: '../components/responses/authorizationPostSuccess.yaml'
|
|
17
|
-
500:
|
|
18
|
-
$ref: '../components/responses/authorizationsServerError.yaml'
|
|
19
|
-
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**************************************************************************
|
|
2
|
-
* (C) Copyright ModusBox Inc. 2020 - 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
|
-
* Sridhar Voruganti - sridhar.voruganti@modusbox.com *
|
|
9
|
-
**************************************************************************/
|
|
10
|
-
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
const Async2SyncModel = require('./Async2SyncModel');
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
// delegated methods for AuthorizationsModel
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @name channelName
|
|
20
|
-
* @description generates the pub/sub channel name
|
|
21
|
-
* @param {object} - args
|
|
22
|
-
* @param {string} args.transactionRequestId - the transactionRequestId
|
|
23
|
-
* @param {string} [args.fspId] - ignored if passed - the destination fsp id
|
|
24
|
-
* @param {string} [args.authorization] - ignored if passed - the authorization payload
|
|
25
|
-
* @returns {string} - the pub/sub channel name
|
|
26
|
-
*/
|
|
27
|
-
function channelName ({ transactionRequestId /* ,fspId, authorization - are not used here */ }) {
|
|
28
|
-
const tokens = ['authorizations', transactionRequestId];
|
|
29
|
-
return tokens.map(x => `${x}`).join('-');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @name requestAction
|
|
34
|
-
* @description invokes the call to switch
|
|
35
|
-
* @param {object} requests - MojaloopRequests instance
|
|
36
|
-
* @param {array} args - the arguments passed as object to `run` method
|
|
37
|
-
* @param {string} [args.transactionRequestId] - the transactionRequestId
|
|
38
|
-
* @param {string} args.fspId - the destination fsp id
|
|
39
|
-
* @param {string} args.authorization - the authorization
|
|
40
|
-
*/
|
|
41
|
-
function requestAction (requests, { /* transactionRequestId, not used here */ fspId, authorization }) {
|
|
42
|
-
if (!fspId) {
|
|
43
|
-
throw new Error('AuthorizationsModel args requires \'fspId\' to be nonempty string');
|
|
44
|
-
}
|
|
45
|
-
return requests.postAuthorizations(authorization, fspId);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* @name argsValidationMethod
|
|
50
|
-
* @description makes validation of args object, invoked in `run, triggerDeferredJob, generateKey` methods to ensure everything is going well
|
|
51
|
-
* @param {array} args - the arguments passed as object to `run` method
|
|
52
|
-
* @param {string} args.transactionRequestId - the transactionRequestId
|
|
53
|
-
* @param {string} args.fspId - the destination fsp id
|
|
54
|
-
* @param {string} [args.authorization] - ignored if passed - the authorization payload
|
|
55
|
-
*/
|
|
56
|
-
function argsValidation ({ transactionRequestId, fspId /* ,authorization not used here */ }) {
|
|
57
|
-
if (!(transactionRequestId && typeof (transactionRequestId) === 'string' && transactionRequestId.length > 0)) {
|
|
58
|
-
throw new Error('AuthorizationsModel args requires \'transactionRequestId\' is nonempty string and mandatory property');
|
|
59
|
-
}
|
|
60
|
-
if (fspId && !(typeof (fspId) === 'string' && fspId.length > 0)) {
|
|
61
|
-
throw new Error('AuthorizationsModel args requires \'fspId\' to be nonempty string');
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* @name reformatMessage
|
|
67
|
-
* @description reformats message received from PUB/SUB channel, it is optional method, if not specified identify function is used by default
|
|
68
|
-
* @param {object} message - message received
|
|
69
|
-
* @returns {object} - reformatted message
|
|
70
|
-
*/
|
|
71
|
-
function reformatMessage (message) {
|
|
72
|
-
return {
|
|
73
|
-
authorizations: { ...message }
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// generate model
|
|
78
|
-
const AuthorizationsModel = Async2SyncModel.generate({
|
|
79
|
-
modelName: 'AuthorizationsModel',
|
|
80
|
-
channelNameMethod: channelName,
|
|
81
|
-
requestActionMethod: requestAction,
|
|
82
|
-
argsValidationMethod: argsValidation,
|
|
83
|
-
reformatMessageMethod: reformatMessage
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
module.exports = AuthorizationsModel;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const axios = require('axios');
|
|
4
|
-
const { uuid } = require('uuidv4');
|
|
5
|
-
const env = require('../../testEnv');
|
|
6
|
-
const authorizationsPostRequest = require('./data/authorizationsPostRequest.json');
|
|
7
|
-
|
|
8
|
-
jest.dontMock('redis');
|
|
9
|
-
|
|
10
|
-
describe('/authorizations', () => {
|
|
11
|
-
|
|
12
|
-
test('post - happy flow', async () => {
|
|
13
|
-
const postAuthorizationsURI = `${env.OutboundHostURI}/authorizations`;
|
|
14
|
-
const transactionRequestId = uuid();
|
|
15
|
-
const res = await axios({
|
|
16
|
-
method: 'POST',
|
|
17
|
-
url: postAuthorizationsURI,
|
|
18
|
-
data: {
|
|
19
|
-
fspId: 'switch',
|
|
20
|
-
authorizationsPostRequest: {
|
|
21
|
-
...authorizationsPostRequest,
|
|
22
|
-
transactionRequestId
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
headers: {
|
|
26
|
-
'access-control-allow-origin': '*'
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
expect(res.status).toEqual(200);
|
|
31
|
-
expect(res.data.currentState).toEqual('COMPLETED');
|
|
32
|
-
expect(typeof res.data).toEqual('object');
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test('post - timeout', (done) => {
|
|
36
|
-
const postAuthorizationsURI = `${env.OutboundHostURI}/authorizations`;
|
|
37
|
-
const transactionRequestId = uuid();
|
|
38
|
-
axios({
|
|
39
|
-
method: 'POST',
|
|
40
|
-
url: postAuthorizationsURI,
|
|
41
|
-
data: {
|
|
42
|
-
fspId: 'timeout-fsp-id',
|
|
43
|
-
authorizationsPostRequest: {
|
|
44
|
-
...authorizationsPostRequest,
|
|
45
|
-
transactionRequestId
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
headers: {
|
|
49
|
-
'access-control-allow-origin': '*'
|
|
50
|
-
}
|
|
51
|
-
}).catch(err => {
|
|
52
|
-
expect(err.response.status).toEqual(500);
|
|
53
|
-
expect(err.response.data.message).toEqual('Timeout');
|
|
54
|
-
done();
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
});
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"authenticationType": "U2F",
|
|
3
|
-
"retriesLeft": 1,
|
|
4
|
-
"amount": {
|
|
5
|
-
"currency": "USD",
|
|
6
|
-
"amount": "100"
|
|
7
|
-
},
|
|
8
|
-
"transactionId": "2f169631-ef99-4cb1-96dc-91e8fc08f539",
|
|
9
|
-
"transactionRequestId": "02e28448-3c05-4059-b5f7-d518d0a2d8ea",
|
|
10
|
-
"quote": {
|
|
11
|
-
"transferAmount": {
|
|
12
|
-
"currency": "USD",
|
|
13
|
-
"amount": "100"
|
|
14
|
-
},
|
|
15
|
-
"payeeReceiveAmount": {
|
|
16
|
-
"currency": "USD",
|
|
17
|
-
"amount": "99"
|
|
18
|
-
},
|
|
19
|
-
"payeeFspFee": {
|
|
20
|
-
"currency": "USD",
|
|
21
|
-
"amount": "1"
|
|
22
|
-
},
|
|
23
|
-
"payeeFspCommission": {
|
|
24
|
-
"currency": "USD",
|
|
25
|
-
"amount": "0"
|
|
26
|
-
},
|
|
27
|
-
"expiration": "2020-05-17T15:28:54.250Z",
|
|
28
|
-
"geoCode": {
|
|
29
|
-
"latitude": "+45.4215",
|
|
30
|
-
"longitude": "+75.6972"
|
|
31
|
-
},
|
|
32
|
-
"ilpPacket": "AQAAAAAAACasIWcuc2UubW9iaWxlbW9uZXkubXNpc2RuLjEyMzQ1Njc4OYIEIXsNCiAgICAidHJhbnNhY3Rpb25JZCI6ICI4NWZlYWMyZi0zOWIyLTQ5MWItODE3ZS00YTAzMjAzZDRmMTQiLA0KICAgICJxdW90ZUlkIjogIjdjMjNlODBjLWQwNzgtNDA3Ny04MjYzLTJjMDQ3ODc2ZmNmNiIsDQogICAgInBheWVlIjogew0KICAgICAgICAicGFydHlJZEluZm8iOiB7DQogICAgICAgICAgICAicGFydHlJZFR5cGUiOiAiTVNJU0ROIiwNCiAgICAgICAgICAgICJwYXJ0eUlkZW50aWZpZXIiOiAiMTIzNDU2Nzg5IiwNCiAgICAgICAgICAgICJmc3BJZCI6ICJNb2JpbGVNb25leSINCiAgICAgICAgfSwNCiAgICAgICAgInBlcnNvbmFsSW5mbyI6IHsNCiAgICAgICAgICAgICJjb21wbGV4TmFtZSI6IHsNCiAgICAgICAgICAgICAgICAiZmlyc3ROYW1lIjogIkhlbnJpayIsDQogICAgICAgICAgICAgICAgImxhc3ROYW1lIjogIkthcmxzc29uIg0KICAgICAgICAgICAgfQ0KICAgICAgICB9DQogICAgfSwNCiAgICAicGF5ZXIiOiB7DQogICAgICAgICJwZXJzb25hbEluZm8iOiB7DQogICAgICAgICAgICAiY29tcGxleE5hbWUiOiB7DQogICAgICAgICAgICAgICAgImZpcnN0TmFtZSI6ICJNYXRzIiwNCiAgICAgICAgICAgICAgICAibGFzdE5hbWUiOiAiSGFnbWFuIg0KICAgICAgICAgICAgfQ0KICAgICAgICB9LA0KICAgICAgICAicGFydHlJZEluZm8iOiB7DQogICAgICAgICAgICAicGFydHlJZFR5cGUiOiAiSUJBTiIsDQogICAgICAgICAgICAicGFydHlJZGVudGlmaWVyIjogIlNFNDU1MDAwMDAwMDA1ODM5ODI1NzQ2NiIsDQogICAgICAgICAgICAiZnNwSWQiOiAiQmFua05yT25lIg0KICAgICAgICB9DQogICAgfSwNCiAgICAiYW1vdW50Ijogew0KICAgICAgICAiYW1vdW50IjogIjEwMCIsDQogICAgICAgICJjdXJyZW5jeSI6ICJVU0QiDQogICAgfSwNCiAgICAidHJhbnNhY3Rpb25UeXBlIjogew0KICAgICAgICAic2NlbmFyaW8iOiAiVFJBTlNGRVIiLA0KICAgICAgICAiaW5pdGlhdG9yIjogIlBBWUVSIiwNCiAgICAgICAgImluaXRpYXRvclR5cGUiOiAiQ09OU1VNRVIiDQogICAgfSwNCiAgICAibm90ZSI6ICJGcm9tIE1hdHMiDQp9DQo\u003d\u003d",
|
|
33
|
-
"condition": "f5sqb7tBTWPd5Y8BDFdMm9BJR_MNI4isf8p8n4D5pHA",
|
|
34
|
-
"extensionList": {
|
|
35
|
-
"extension": [
|
|
36
|
-
{
|
|
37
|
-
"key": "errorDescription1",
|
|
38
|
-
"value": "This is a more detailed error description"
|
|
39
|
-
}
|
|
40
|
-
]
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|