From 88086301ac3b4f608a60dd56a1a17e6b6b723023 Mon Sep 17 00:00:00 2001 From: Valentin Date: Wed, 8 Jul 2020 10:48:12 +0300 Subject: [PATCH 1/5] upstream merge --- model.sqlite | Bin 0 -> 61440 bytes src/docker-compose.yml | 20 ++++++++++---------- src/index.js | 6 +++--- src/test/unit/lib/validate/index.test.js | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) create mode 100644 model.sqlite diff --git a/model.sqlite b/model.sqlite new file mode 100644 index 0000000000000000000000000000000000000000..988c99f38b28533461f45d13bbd4927fe0919a1b GIT binary patch literal 61440 zcmeI%-EY!f9LMoiCmjr!Ue(0Roy08KpHCsic;Q1tJkwC#~0VMlbWt; zcZJY2%?Rh^aE_+&{z9}9uJzdVyiG&9a`RhZ`G;1_+FJ4J@~7hI;>W^L;d6dH|7EF= z&*m=YzGUs}_jwnf9RUOoKmY**5cod`1S_i1X*IoOPp^F*nzA&Fi+@cZ0o7_ye%%4E>(kZ^mz=S&Hv1 z2mdV@=IW}xe{L4+@v!HsglZ#yAd+f6+B~oNuH(C*&Bm78w#!?O6vcs*rF_PetB0jj z_cn>BHVeThYnYa$f4Hpj?K*vbB;WaNci{E9$-P`6Y4X@C?o+2ToK#{~!%3CixT9og zC(Uo?ogXW_2rH?sdr5>>u_hl}uQ%kzgW9-b%#K^4A=hO?)+%yas2hwvX^DDG+?Q1u zcD_n^yHdU{bJopV#;jZOxRL>zrR4rnaLO>ul@&c0DmZ`I+oSbj0xN2rF(oOEs+V6~ z%$Svxd4ZyvXqKX_Y#>hz3J=%@`iRr`rr$-`s+fCju(Tm+Wc9@CEH+^)Ehu@=% { From 5bfb6aab5a72bab7322ae94d66f8e0374d7d629b Mon Sep 17 00:00:00 2001 From: Valentin Date: Mon, 17 Aug 2020 17:59:19 +0300 Subject: [PATCH 2/5] added PUT /transfers/transferId handling for notifications to payee --- src/package.json | 3 +- src/simulator/api.yaml | 79 +++++++++++++++++++++++++++++++++++++++ src/simulator/handlers.js | 22 +++++++++-- 3 files changed, 99 insertions(+), 5 deletions(-) diff --git a/src/package.json b/src/package.json index d513f2bb..d8b878dc 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "mojaloop-simulator", - "version": "11.0.3", + "version": "11.1.0", "description": "A canonical test example implementation of the parties, transfers and quotes resources of the Mojaloop API", "license": "Apache-2.0", "main": "index.js", @@ -10,6 +10,7 @@ "Matt Kingston ", "Steven Oderayi ", "Aaron Reynoza ", + "Valentin Genev ", "ModusBox", "Mowali" ], diff --git a/src/simulator/api.yaml b/src/simulator/api.yaml index faadb54b..64b048b0 100644 --- a/src/simulator/api.yaml +++ b/src/simulator/api.yaml @@ -183,6 +183,31 @@ paths: schema: $ref: '#/components/schemas/errorResponse' + /transfers/{transferId}: + put: + summary: Receive notification for a specific transfer + description: The HTTP request `PUT /transfers/{transferId}` is used to receive notification for transfer being fulfiled when the FSP is a Payee + tags: + - Transfers + parameters: + - $ref: '#/components/schemas/transferId' + requestBody: + description: An incoming notification for fulfiled transfer + content: + application/json: + schema: + $ref: '#/components/schemas/fulfilNotification' + responses: + 200: + description: The notification was accepted + 500: + description: An error occured processing the request + content: + application/json: + schema: + $ref: '#/components/schemas/errorResponse' + + /otp/{requestToPayId}: get: summary: Requests OTP @@ -958,6 +983,60 @@ components: message: type: string description: Error message text + + extensionList: + type: array + items: + $ref: '#/components/schemas/extensionItem' + minItems: 0 + maxItems: 16 + + extensionItem: + type: object + properties: + key: + type: string + minLength: 1 + maxLength: 32 + value: + type: string + minLength: 1 + maxLength: 128 + + transferState: + type: string + enum: + - RECEIVED + - RESERVED + - COMMITTED + - ABORTED + description: > + Below are the allowed values for the enumeration + - RECEIVED DFSP has received the transfer. + - RESERVED DFSP has reserved the transfer. + - COMMITTED DFSP has successfully performed the transfer. + - ABORTED DFSP has aborted the transfer due a rejection or failure to perform the transfer. + + fulfilNotification: + title: TransfersIDPatchResponse + type: object + description: PUT /transfers/{transferId} object + properties: + completedTimestamp: + $ref: '#/components/schemas/timestamp' + description: Time and date when the transaction was completed. + example: "2020-05-19T08:38:08.699-04:00" + transferState: + $ref: '#/components/schemas/transferState' + description: State of the transfer. + example: COMMITTED + extensionList: + $ref: '#/components/schemas/extensionList' + description: Optional extension, specific to deployment. + required: + - completedTimestamp + - transferState + diff --git a/src/simulator/handlers.js b/src/simulator/handlers.js index d501ea71..95eed839 100644 --- a/src/simulator/handlers.js +++ b/src/simulator/handlers.js @@ -30,7 +30,6 @@ require('dotenv').config(); const { getStackOrInspect } = require('@internal/log'); const { ApiErrorCodes } = require('../models/errors.js'); - const getParticipantsByTypeAndId = async (ctx) => { try { const { idValue, idType } = ctx.state.path.params; @@ -48,7 +47,6 @@ const getParticipantsByTypeAndId = async (ctx) => { } }; - const getPartiesByTypeAndId = async (ctx) => { // TODO: check that the provided type was MSISDN? Or just encode that in the API spec.. try { @@ -80,7 +78,6 @@ const getOTPById = async (ctx) => { } }; - const postTransfers = async (ctx) => { try { const res = await ctx.state.model.transfer.create(ctx.request.body); @@ -94,6 +91,21 @@ const postTransfers = async (ctx) => { } }; +const putTransfersById = async (ctx) => { + try { + const res = await ctx.state.model.transfer.update(ctx.state.path.params.transferId, { + ...ctx.request.body, + homeTransactionId: ctx.state.path.params.transferId, + }); + ctx.state.logger.log(`putTransfersById is returning body: ${util.inspect(res)}`); + ctx.response.body = ctx.request.body; + ctx.response.status = 200; + } catch (err) { + ctx.state.logger.log(`Error in putTransfersById: ${getStackOrInspect(err)}`); + ctx.response.body = ApiErrorCodes.SERVER_ERROR; + ctx.response.status = 500; + } +}; const postQuotes = async (ctx) => { try { @@ -121,7 +133,6 @@ const postBulkQuotes = async (ctx) => { } }; - const getBulkQuoteById = async (ctx) => { try { const { idValue } = ctx.state.path.params; @@ -222,6 +233,9 @@ const map = { '/otp/{requestToPayId}': { get: getOTPById, }, + '/transfers/{transferId}': { + put: putTransfersById, + }, }; From b5caed689efd5e6722c89d6c5bf6565a3ae3dafe Mon Sep 17 00:00:00 2001 From: Valentin Date: Wed, 19 Aug 2020 12:06:03 +0300 Subject: [PATCH 3/5] added unit tests --- src/index.js | 6 +++--- src/test/simulator.js | 17 +++++++++++++++++ src/test/unit/lib/validate/index.test.js | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 1331efb1..7d64be6b 100644 --- a/src/index.js +++ b/src/index.js @@ -53,9 +53,9 @@ const { setConfig, getConfig } = require('./config.js'); const Model = require('./models/model'); -const simApiSpec = yaml.load('./src/simulator/api.yaml'); -const reportApiSpec = yaml.load('./src/reports/api.yaml'); -const testApiSpec = yaml.load('./src/test-api/api.yaml'); +const simApiSpec = yaml.load('./simulator/api.yaml'); +const reportApiSpec = yaml.load('./reports/api.yaml'); +const testApiSpec = yaml.load('./test-api/api.yaml'); const simulator = new Koa(); const report = new Koa(); diff --git a/src/test/simulator.js b/src/test/simulator.js index 4a369186..93f797fc 100644 --- a/src/test/simulator.js +++ b/src/test/simulator.js @@ -266,3 +266,20 @@ test('postBulkQuotes should handle 500 errors', async (t) => { t.deepEqual(t.context.response, expected, 'Response did not match expected'); t.pass(); }); + +test('putTransfersById should handle request', async (t) => { + // Arrange + // eslint-disable-next-line no-param-reassign + t.context.state.path = { params: { transferId: '1234' } }; + // eslint-disable-next-line no-throw-literal, no-param-reassign + t.context.request = { + body: { + completedTimestamp: '2017-11-15T14:16:09.663+01:00', + transferState: 'COMMITTED', + }, + }; + await map['/transfers/{transferId}'].put(t.context); + const expected = t.context.request.body; + t.deepEqual(t.context.response, { body: { ...expected }, status: 200 }, 'response is received'); + t.pass(); +}); diff --git a/src/test/unit/lib/validate/index.test.js b/src/test/unit/lib/validate/index.test.js index 5ddc076e..3df05b61 100644 --- a/src/test/unit/lib/validate/index.test.js +++ b/src/test/unit/lib/validate/index.test.js @@ -31,7 +31,7 @@ const uuid = require('uuid/v1'); const Validate = require('@internal/validate'); const { testLogger } = require('../../TestUtils'); -const simApiSpec = yaml.load('../simulator/api.yaml'); +const simApiSpec = yaml.load('./simulator/api.yaml'); test('Validates a simple request', async (t) => { From 41622e93737147731bfbab8f5da657827dc5db44 Mon Sep 17 00:00:00 2001 From: Valentin Date: Wed, 19 Aug 2020 12:27:59 +0300 Subject: [PATCH 4/5] ordered package.json to trigger ci/cd pipeline --- src/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package.json b/src/package.json index d8b878dc..dcf9ee2e 100644 --- a/src/package.json +++ b/src/package.json @@ -6,10 +6,10 @@ "main": "index.js", "author": "Matt Kingston, ModusBox Inc.", "contributors": [ + "Aaron Reynoza ", "Kamuela Franco ", "Matt Kingston ", "Steven Oderayi ", - "Aaron Reynoza ", "Valentin Genev ", "ModusBox", "Mowali" From 8b5e4d225a2192136fbed8495f7f966501e671a7 Mon Sep 17 00:00:00 2001 From: Valentin Date: Thu, 20 Aug 2020 17:23:44 +0300 Subject: [PATCH 5/5] removed homeTransactionId from transfer.update --- model.sqlite | Bin 61440 -> 0 bytes src/docker-compose.yml | 20 ++++++++++---------- src/models/transfer.js | 11 ++++------- src/simulator/handlers.js | 1 - 4 files changed, 14 insertions(+), 18 deletions(-) delete mode 100644 model.sqlite diff --git a/model.sqlite b/model.sqlite deleted file mode 100644 index 988c99f38b28533461f45d13bbd4927fe0919a1b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 61440 zcmeI%-EY!f9LMoiCmjr!Ue(0Roy08KpHCsic;Q1tJkwC#~0VMlbWt; zcZJY2%?Rh^aE_+&{z9}9uJzdVyiG&9a`RhZ`G;1_+FJ4J@~7hI;>W^L;d6dH|7EF= z&*m=YzGUs}_jwnf9RUOoKmY**5cod`1S_i1X*IoOPp^F*nzA&Fi+@cZ0o7_ye%%4E>(kZ^mz=S&Hv1 z2mdV@=IW}xe{L4+@v!HsglZ#yAd+f6+B~oNuH(C*&Bm78w#!?O6vcs*rF_PetB0jj z_cn>BHVeThYnYa$f4Hpj?K*vbB;WaNci{E9$-P`6Y4X@C?o+2ToK#{~!%3CixT9og zC(Uo?ogXW_2rH?sdr5>>u_hl}uQ%kzgW9-b%#K^4A=hO?)+%yas2hwvX^DDG+?Q1u zcD_n^yHdU{bJopV#;jZOxRL>zrR4rnaLO>ul@&c0DmZ`I+oSbj0xN2rF(oOEs+V6~ z%$Svxd4ZyvXqKX_Y#>hz3J=%@`iRr`rr$-`s+fCju(Tm+Wc9@CEH+^)Ehu@=% { try { const res = await ctx.state.model.transfer.update(ctx.state.path.params.transferId, { ...ctx.request.body, - homeTransactionId: ctx.state.path.params.transferId, }); ctx.state.logger.log(`putTransfersById is returning body: ${util.inspect(res)}`); ctx.response.body = ctx.request.body;