From cd3d35e4be15d33b210bccaf9bbf691b292e85e1 Mon Sep 17 00:00:00 2001 From: Kevin Date: Wed, 11 May 2022 13:50:49 -0500 Subject: [PATCH 1/3] fix: update outbound interface and response oa3 defs --- src/OutboundServer/api.yaml | 73 ++++++++++-------- .../api_interfaces/openapi.d.ts | 35 +++++---- .../schemas/partiesByIdResponse.yaml | 10 ++- .../schemas/quotesPostResponse.yaml | 75 ++++++++++--------- .../schemas/simpleTransfersPostResponse.yaml | 8 +- src/lib/model/PartiesModel.js | 15 +++- test/unit/api/transfers/utils.js | 2 +- test/unit/lib/model/PartiesModel.test.js | 20 +++-- test/unit/lib/model/QuotesModel.test.js | 10 ++- test/unit/lib/model/TransfersModel.test.js | 10 ++- 10 files changed, 162 insertions(+), 96 deletions(-) diff --git a/src/OutboundServer/api.yaml b/src/OutboundServer/api.yaml index 4392adc79..5a54bdf80 100644 --- a/src/OutboundServer/api.yaml +++ b/src/OutboundServer/api.yaml @@ -2124,8 +2124,12 @@ components: description: 'GET /parties/{Type}/{ID} response object' properties: party: - $ref: '#/components/schemas/Party' - description: Information regarding the requested Party. + properties: + body: + $ref: '#/components/schemas/Party' + description: Information regarding the requested Party. + headers: + type: object currentState: $ref: '#/components/schemas/async2SyncCurrentState' required: @@ -2235,33 +2239,38 @@ components: type: object description: 'The object sent in the PUT /quotes/{ID} callback.' properties: - transferAmount: - $ref: '#/components/schemas/Money' - payeeReceiveAmount: - $ref: '#/components/schemas/Money' - payeeFspFee: - $ref: '#/components/schemas/Money' - payeeFspCommission: - $ref: '#/components/schemas/Money' - expiration: - type: string - description: >- - Date and time until when the quotation is valid and can be - honored when used in the subsequent transaction. - example: '2016-05-24T08:38:08.699-04:00' - geoCode: - $ref: '#/components/schemas/GeoCode' - ilpPacket: - $ref: '#/components/schemas/IlpPacket' - condition: - $ref: '#/components/schemas/IlpCondition' - extensionList: - $ref: '#/components/schemas/ExtensionList' - required: - - transferAmount - - expiration - - ilpPacket - - condition + body: + type: object + properties: + transferAmount: + $ref: '#/components/schemas/Money' + payeeReceiveAmount: + $ref: '#/components/schemas/Money' + payeeFspFee: + $ref: '#/components/schemas/Money' + payeeFspCommission: + $ref: '#/components/schemas/Money' + expiration: + type: string + description: >- + Date and time until when the quotation is valid and can be + honored when used in the subsequent transaction. + example: '2016-05-24T08:38:08.699-04:00' + geoCode: + $ref: '#/components/schemas/GeoCode' + ilpPacket: + $ref: '#/components/schemas/IlpPacket' + condition: + $ref: '#/components/schemas/IlpCondition' + extensionList: + $ref: '#/components/schemas/ExtensionList' + required: + - transferAmount + - expiration + - ilpPacket + - condition + headers: + type: object currentState: $ref: '#/components/schemas/async2SyncCurrentState' required: @@ -2316,7 +2325,11 @@ components: type: object properties: transfer: - $ref: '#/components/schemas/TransfersIDPutResponse' + properties: + body: + $ref: '#/components/schemas/TransfersIDPutResponse' + headers: + type: object currentState: $ref: '#/components/schemas/async2SyncCurrentState' required: diff --git a/src/OutboundServer/api_interfaces/openapi.d.ts b/src/OutboundServer/api_interfaces/openapi.d.ts index 22328e854..0c7eb5721 100644 --- a/src/OutboundServer/api_interfaces/openapi.d.ts +++ b/src/OutboundServer/api_interfaces/openapi.d.ts @@ -1070,8 +1070,11 @@ export interface components { | "ERROR_OCCURRED"; /** GET /parties/{Type}/{ID} response object */ partiesByIdResponse: { - /** Information regarding the requested Party. */ - party: components["schemas"]["Party"]; + party: { + /** Information regarding the requested Party. */ + body?: components["schemas"]["Party"]; + headers?: { [key: string]: unknown }; + }; currentState: components["schemas"]["async2SyncCurrentState"]; }; /** The object sent in the POST /quotes request. */ @@ -1110,16 +1113,19 @@ export interface components { quotesPostResponse: { /** The object sent in the PUT /quotes/{ID} callback. */ quotes: { - transferAmount: components["schemas"]["Money"]; - payeeReceiveAmount?: components["schemas"]["Money"]; - payeeFspFee?: components["schemas"]["Money"]; - payeeFspCommission?: components["schemas"]["Money"]; - /** Date and time until when the quotation is valid and can be honored when used in the subsequent transaction. */ - expiration: string; - geoCode?: components["schemas"]["GeoCode"]; - ilpPacket: components["schemas"]["IlpPacket"]; - condition: components["schemas"]["IlpCondition"]; - extensionList?: components["schemas"]["ExtensionList"]; + body?: { + transferAmount: components["schemas"]["Money"]; + payeeReceiveAmount?: components["schemas"]["Money"]; + payeeFspFee?: components["schemas"]["Money"]; + payeeFspCommission?: components["schemas"]["Money"]; + /** Date and time until when the quotation is valid and can be honored when used in the subsequent transaction. */ + expiration: string; + geoCode?: components["schemas"]["GeoCode"]; + ilpPacket: components["schemas"]["IlpPacket"]; + condition: components["schemas"]["IlpCondition"]; + extensionList?: components["schemas"]["ExtensionList"]; + }; + headers?: { [key: string]: unknown }; }; currentState: components["schemas"]["async2SyncCurrentState"]; }; @@ -1142,7 +1148,10 @@ export interface components { transfersPostRequest: components["schemas"]["TransfersPostRequest"]; }; simpleTransfersPostResponse: { - transfer: components["schemas"]["TransfersIDPutResponse"]; + transfer: { + body?: components["schemas"]["TransfersIDPutResponse"]; + headers?: { [key: string]: unknown }; + }; currentState: components["schemas"]["async2SyncCurrentState"]; }; errorSimpleTransfersResponse: components["schemas"]["errorResponse"] & { diff --git a/src/OutboundServer/api_template/components/schemas/partiesByIdResponse.yaml b/src/OutboundServer/api_template/components/schemas/partiesByIdResponse.yaml index b9fa25b03..935be43d4 100644 --- a/src/OutboundServer/api_template/components/schemas/partiesByIdResponse.yaml +++ b/src/OutboundServer/api_template/components/schemas/partiesByIdResponse.yaml @@ -3,9 +3,13 @@ description: 'GET /parties/{Type}/{ID} response object' properties: party: - $ref: >- - ../../../../../node_modules/@mojaloop/api-snippets/thirdparty/v1_0/openapi3/components/schemas/Party.yaml - description: Information regarding the requested Party. + properties: + body: + $ref: >- + ../../../../../node_modules/@mojaloop/api-snippets/thirdparty/v1_0/openapi3/components/schemas/Party.yaml + description: Information regarding the requested Party. + headers: + type: object currentState: $ref: ../schemas/async2SyncCurrentState.yaml required: diff --git a/src/OutboundServer/api_template/components/schemas/quotesPostResponse.yaml b/src/OutboundServer/api_template/components/schemas/quotesPostResponse.yaml index af7811457..44beb1c40 100644 --- a/src/OutboundServer/api_template/components/schemas/quotesPostResponse.yaml +++ b/src/OutboundServer/api_template/components/schemas/quotesPostResponse.yaml @@ -6,41 +6,46 @@ properties: type: object description: 'The object sent in the PUT /quotes/{ID} callback.' properties: - transferAmount: - $ref: >- - ../../../../../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/components/schemas/Money.yaml - payeeReceiveAmount: - $ref: >- - ../../../../../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/components/schemas/Money.yaml - payeeFspFee: - $ref: >- - ../../../../../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/components/schemas/Money.yaml - payeeFspCommission: - $ref: >- - ../../../../../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/components/schemas/Money.yaml - expiration: - type: string - description: >- - Date and time until when the quotation is valid and can be honored when - used in the subsequent transaction. - example: '2016-05-24T08:38:08.699-04:00' - geoCode: - $ref: >- - ../../../../../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/components/schemas/GeoCode.yaml - ilpPacket: - $ref: >- - ../../../../../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/components/schemas/IlpPacket.yaml - condition: - $ref: >- - ../../../../../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/components/schemas/IlpCondition.yaml - extensionList: - $ref: >- - ../../../../../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/components/schemas/ExtensionList.yaml - required: - - transferAmount - - expiration - - ilpPacket - - condition + body: + type: object + properties: + transferAmount: + $ref: >- + ../../../../../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/components/schemas/Money.yaml + payeeReceiveAmount: + $ref: >- + ../../../../../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/components/schemas/Money.yaml + payeeFspFee: + $ref: >- + ../../../../../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/components/schemas/Money.yaml + payeeFspCommission: + $ref: >- + ../../../../../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/components/schemas/Money.yaml + expiration: + type: string + description: >- + Date and time until when the quotation is valid and can be honored when + used in the subsequent transaction. + example: '2016-05-24T08:38:08.699-04:00' + geoCode: + $ref: >- + ../../../../../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/components/schemas/GeoCode.yaml + ilpPacket: + $ref: >- + ../../../../../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/components/schemas/IlpPacket.yaml + condition: + $ref: >- + ../../../../../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/components/schemas/IlpCondition.yaml + extensionList: + $ref: >- + ../../../../../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/components/schemas/ExtensionList.yaml + required: + - transferAmount + - expiration + - ilpPacket + - condition + headers: + type: object currentState: $ref: ../schemas/async2SyncCurrentState.yaml required: diff --git a/src/OutboundServer/api_template/components/schemas/simpleTransfersPostResponse.yaml b/src/OutboundServer/api_template/components/schemas/simpleTransfersPostResponse.yaml index 43a373046..a3b83b2c7 100644 --- a/src/OutboundServer/api_template/components/schemas/simpleTransfersPostResponse.yaml +++ b/src/OutboundServer/api_template/components/schemas/simpleTransfersPostResponse.yaml @@ -2,8 +2,12 @@ title: SimpleTransfersPostResponse type: object properties: transfer: - $ref: >- - ../../../../../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/components/schemas/TransfersIDPutResponse.yaml + properties: + body: + $ref: >- + ../../../../../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/components/schemas/TransfersIDPutResponse.yaml + headers: + type: object currentState: $ref: ../schemas/async2SyncCurrentState.yaml required: diff --git a/src/lib/model/PartiesModel.js b/src/lib/model/PartiesModel.js index c3c84ac66..d4b543c99 100644 --- a/src/lib/model/PartiesModel.js +++ b/src/lib/model/PartiesModel.js @@ -58,12 +58,25 @@ function argsValidation({ type, id, subId }) { } } +/** + * @name reformatMessage + * @description reformats message received from PUB/SUB channel, it is optional method, if not specified identify function is used by default + * @param {object} message - message received + * @returns {object} - reformatted message + */ +function reformatMessage(message) { + return { + party: { ...message } + }; +} + // generate model const PartiesModel = Async2SyncModel.generate({ modelName: 'PartiesModel', channelNameMethod: channelName, requestActionMethod: requestAction, - argsValidationMethod: argsValidation + argsValidationMethod: argsValidation, + reformatMessageMethod: reformatMessage }); module.exports = PartiesModel; diff --git a/test/unit/api/transfers/utils.js b/test/unit/api/transfers/utils.js index 1fe1d82fe..fba2df9be 100644 --- a/test/unit/api/transfers/utils.js +++ b/test/unit/api/transfers/utils.js @@ -202,7 +202,7 @@ function createPostTransfersTester( const res = await reqOutbound.post('/transfers').send(postTransfersSimpleBody); const {body} = res; - console.log(body) + expect(res.statusCode).toEqual(responseCode); // remove elements of the response we do not want/need to compare for correctness. diff --git a/test/unit/lib/model/PartiesModel.test.js b/test/unit/lib/model/PartiesModel.test.js index b1b0877fb..b47640fae 100644 --- a/test/unit/lib/model/PartiesModel.test.js +++ b/test/unit/lib/model/PartiesModel.test.js @@ -155,9 +155,12 @@ describe('PartiesModel', () => { model.run = jest.fn(() => Promise.resolve()); const message = { - party: { - Iam: 'the-body' - } + body: { + party: { + Iam: 'the-body' + } + }, + headers: {} }; const onRequestActionPromise = new Promise((resolve, reject) => { @@ -175,7 +178,7 @@ describe('PartiesModel', () => { // check that this.context.data is updated expect(model.context.data).toEqual({ - ...message, + party: { ...message }, // current state will be updated by onAfterTransition which isn't called // when manual invocation of transition handler happens currentState: 'start' @@ -216,9 +219,12 @@ describe('PartiesModel', () => { model.run = jest.fn(() => Promise.resolve()); const message = { - party: { - Iam: 'the-body' - } + body: { + party: { + Iam: 'the-body' + } + }, + headers: {} }; const onRequestActionPromise = new Promise((resolve, reject) => { diff --git a/test/unit/lib/model/QuotesModel.test.js b/test/unit/lib/model/QuotesModel.test.js index 9a529338f..328eb696f 100644 --- a/test/unit/lib/model/QuotesModel.test.js +++ b/test/unit/lib/model/QuotesModel.test.js @@ -142,7 +142,10 @@ describe('QuotesModel', () => { // mock workflow execution which is tested in separate case model.run = jest.fn(() => Promise.resolve()); - const message = { ...putQuotesResponse }; + const message = { + body: { ...putQuotesResponse }, + headers: {} + }; const onRequestActionPromise = new Promise((resolve, reject) => { // manually invoke transition handler @@ -200,7 +203,10 @@ describe('QuotesModel', () => { // mock workflow execution which is tested in separate case model.run = jest.fn(() => Promise.resolve()); - const message = { ...putQuotesResponse }; + const message = { + body: { ...putQuotesResponse }, + headers: {} + }; const onRequestActionPromise = new Promise((resolve, reject) => { // manually invoke transition handler diff --git a/test/unit/lib/model/TransfersModel.test.js b/test/unit/lib/model/TransfersModel.test.js index 0b76c584d..9203a0de1 100644 --- a/test/unit/lib/model/TransfersModel.test.js +++ b/test/unit/lib/model/TransfersModel.test.js @@ -142,7 +142,10 @@ describe('TransfersModel', () => { // mock workflow execution which is tested in separate case model.run = jest.fn(() => Promise.resolve()); - const message = { ...putTransfersResponse }; + const message = { + body: { ...putTransfersResponse }, + headers: {} + }; const onRequestActionPromise = new Promise((resolve, reject) => { // manually invoke transition handler @@ -200,7 +203,10 @@ describe('TransfersModel', () => { // mock workflow execution which is tested in separate case model.run = jest.fn(() => Promise.resolve()); - const message = { ...putTransfersResponse }; + const message = { + body: { ...putTransfersResponse }, + headers: {} + }; const onRequestActionPromise = new Promise((resolve, reject) => { // manually invoke transition handler From cc3958f58a3019ac5c990272eab204c15c89746f Mon Sep 17 00:00:00 2001 From: Kevin Date: Wed, 11 May 2022 13:54:56 -0500 Subject: [PATCH 2/3] chore: fix --- src/OutboundServer/api.yaml | 9 +++++++++ src/OutboundServer/api_interfaces/openapi.d.ts | 12 ++++++------ .../components/schemas/partiesByIdResponse.yaml | 3 +++ .../components/schemas/quotesPostResponse.yaml | 3 +++ .../schemas/simpleTransfersPostResponse.yaml | 3 +++ 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/OutboundServer/api.yaml b/src/OutboundServer/api.yaml index 5a54bdf80..cdfbc6e85 100644 --- a/src/OutboundServer/api.yaml +++ b/src/OutboundServer/api.yaml @@ -2130,6 +2130,9 @@ components: description: Information regarding the requested Party. headers: type: object + required: + - body + - headers currentState: $ref: '#/components/schemas/async2SyncCurrentState' required: @@ -2271,6 +2274,9 @@ components: - condition headers: type: object + required: + - body + - headers currentState: $ref: '#/components/schemas/async2SyncCurrentState' required: @@ -2330,6 +2336,9 @@ components: $ref: '#/components/schemas/TransfersIDPutResponse' headers: type: object + required: + - body + - headers currentState: $ref: '#/components/schemas/async2SyncCurrentState' required: diff --git a/src/OutboundServer/api_interfaces/openapi.d.ts b/src/OutboundServer/api_interfaces/openapi.d.ts index 0c7eb5721..5a90b87db 100644 --- a/src/OutboundServer/api_interfaces/openapi.d.ts +++ b/src/OutboundServer/api_interfaces/openapi.d.ts @@ -1072,8 +1072,8 @@ export interface components { partiesByIdResponse: { party: { /** Information regarding the requested Party. */ - body?: components["schemas"]["Party"]; - headers?: { [key: string]: unknown }; + body: components["schemas"]["Party"]; + headers: { [key: string]: unknown }; }; currentState: components["schemas"]["async2SyncCurrentState"]; }; @@ -1113,7 +1113,7 @@ export interface components { quotesPostResponse: { /** The object sent in the PUT /quotes/{ID} callback. */ quotes: { - body?: { + body: { transferAmount: components["schemas"]["Money"]; payeeReceiveAmount?: components["schemas"]["Money"]; payeeFspFee?: components["schemas"]["Money"]; @@ -1125,7 +1125,7 @@ export interface components { condition: components["schemas"]["IlpCondition"]; extensionList?: components["schemas"]["ExtensionList"]; }; - headers?: { [key: string]: unknown }; + headers: { [key: string]: unknown }; }; currentState: components["schemas"]["async2SyncCurrentState"]; }; @@ -1149,8 +1149,8 @@ export interface components { }; simpleTransfersPostResponse: { transfer: { - body?: components["schemas"]["TransfersIDPutResponse"]; - headers?: { [key: string]: unknown }; + body: components["schemas"]["TransfersIDPutResponse"]; + headers: { [key: string]: unknown }; }; currentState: components["schemas"]["async2SyncCurrentState"]; }; diff --git a/src/OutboundServer/api_template/components/schemas/partiesByIdResponse.yaml b/src/OutboundServer/api_template/components/schemas/partiesByIdResponse.yaml index 935be43d4..a22784ce9 100644 --- a/src/OutboundServer/api_template/components/schemas/partiesByIdResponse.yaml +++ b/src/OutboundServer/api_template/components/schemas/partiesByIdResponse.yaml @@ -10,6 +10,9 @@ description: Information regarding the requested Party. headers: type: object + required: + - body + - headers currentState: $ref: ../schemas/async2SyncCurrentState.yaml required: diff --git a/src/OutboundServer/api_template/components/schemas/quotesPostResponse.yaml b/src/OutboundServer/api_template/components/schemas/quotesPostResponse.yaml index 44beb1c40..43bb4831a 100644 --- a/src/OutboundServer/api_template/components/schemas/quotesPostResponse.yaml +++ b/src/OutboundServer/api_template/components/schemas/quotesPostResponse.yaml @@ -46,6 +46,9 @@ properties: - condition headers: type: object + required: + - body + - headers currentState: $ref: ../schemas/async2SyncCurrentState.yaml required: diff --git a/src/OutboundServer/api_template/components/schemas/simpleTransfersPostResponse.yaml b/src/OutboundServer/api_template/components/schemas/simpleTransfersPostResponse.yaml index a3b83b2c7..7b254d0cf 100644 --- a/src/OutboundServer/api_template/components/schemas/simpleTransfersPostResponse.yaml +++ b/src/OutboundServer/api_template/components/schemas/simpleTransfersPostResponse.yaml @@ -8,6 +8,9 @@ properties: ../../../../../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/components/schemas/TransfersIDPutResponse.yaml headers: type: object + required: + - body + - headers currentState: $ref: ../schemas/async2SyncCurrentState.yaml required: From ebe49b60f47cc59c0755f18558f7480097fec5da Mon Sep 17 00:00:00 2001 From: Kevin Date: Wed, 11 May 2022 14:30:48 -0500 Subject: [PATCH 3/3] chore: fix int tests --- test/integration/lib/Outbound/parties.test.js | 4 +++- test/integration/lib/Outbound/quotes.test.js | 2 ++ test/integration/lib/Outbound/simpleTransfers.test.js | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/test/integration/lib/Outbound/parties.test.js b/test/integration/lib/Outbound/parties.test.js index b0b9edcf0..eed8bf9ef 100644 --- a/test/integration/lib/Outbound/parties.test.js +++ b/test/integration/lib/Outbound/parties.test.js @@ -13,7 +13,9 @@ describe('/parties', () => { expect(res.status).toEqual(200); expect(res.data.currentState).toEqual('COMPLETED'); - expect(typeof res.data.body.party).toEqual('object'); + expect(typeof res.data.party).toEqual('object'); + expect(typeof res.data.party.body).toEqual('object'); + expect(typeof res.data.party.headers).toEqual('object'); }); test('get - timeout', (done) => { diff --git a/test/integration/lib/Outbound/quotes.test.js b/test/integration/lib/Outbound/quotes.test.js index 4b6a69f0d..898da31d7 100644 --- a/test/integration/lib/Outbound/quotes.test.js +++ b/test/integration/lib/Outbound/quotes.test.js @@ -30,6 +30,8 @@ describe('/quotes', () => { expect(res.status).toEqual(200); expect(res.data.currentState).toEqual('COMPLETED'); expect(typeof res.data.quotes).toEqual('object'); + expect(typeof res.data.quotes.body).toEqual('object'); + expect(typeof res.data.quotes.headers).toEqual('object'); }); test('post - timeout', (done) => { diff --git a/test/integration/lib/Outbound/simpleTransfers.test.js b/test/integration/lib/Outbound/simpleTransfers.test.js index 84e1b237f..7edfba57a 100644 --- a/test/integration/lib/Outbound/simpleTransfers.test.js +++ b/test/integration/lib/Outbound/simpleTransfers.test.js @@ -39,6 +39,8 @@ describe('/simpleTransfers', () => { expect(res.status).toEqual(200); expect(res.data.currentState).toEqual('COMPLETED'); expect(typeof res.data.transfer).toEqual('object'); + expect(typeof res.data.transfer.body).toEqual('object'); + expect(typeof res.data.transfer.headers).toEqual('object'); }); test('post - timeout', async () => {