Skip to content

Commit

Permalink
feat: implement sync test case execution (#252)
Browse files Browse the repository at this point in the history
* feat: added sync option for test case execution

* chore: added unit test

* chore: update deps and fix lint

* chore: update
  • Loading branch information
vijayg10 authored Apr 1, 2024
1 parent b3ddb9e commit 52310c9
Show file tree
Hide file tree
Showing 9 changed files with 311 additions and 193 deletions.
365 changes: 215 additions & 150 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,27 @@
"genexec": "pkg -t node8-win ."
},
"dependencies": {
"@elastic/elasticsearch": "8.12.2",
"@elastic/elasticsearch": "8.13.0",
"@hapi/basic": "7.0.2",
"@hapi/boom": "10.0.1",
"@hapi/good": "9.0.1",
"@hapi/hapi": "21.3.3",
"@hapi/hapi": "21.3.7",
"@hapi/inert": "7.1.0",
"@hapi/vision": "7.0.3",
"@mojaloop/central-services-logger": "11.2.2",
"@mojaloop/central-services-logger": "11.3.0",
"@mojaloop/ml-testing-toolkit-shared-lib": "14.0.1",
"@mojaloop/sdk-standard-components": "^17.1.3",
"@now-ims/hapi-now-auth": "2.1.0",
"@types/socket.io": "3.0.1",
"adm-zip": "0.5.10",
"adm-zip": "0.5.12",
"atob": "2.1.2",
"axios": "1.6.7",
"axios": "1.6.8",
"chai": "4.4.1",
"cookie-parser": "1.4.6",
"cookies": "0.9.1",
"cors": "2.8.5",
"dotenv": "16.4.5",
"express": "4.18.3",
"express": "4.19.2",
"express-validator": "7.0.1",
"fs": "0.0.1-security",
"handlebars": "4.7.8",
Expand All @@ -91,7 +91,7 @@
"json-rules-engine": "6.5.0",
"lodash": "4.17.21",
"mongo-uri-builder": "4.0.0",
"mongoose": "8.2.0",
"mongoose": "8.2.4",
"multer": "1.4.3",
"mustache": "4.2.0",
"mv": "2.1.1",
Expand All @@ -104,26 +104,26 @@
"passport-jwt": "4.0.1",
"path": "0.12.7",
"postman-collection": "4.4.0",
"postman-sandbox": "4.5.0",
"postman-sandbox": "4.6.1",
"rc": "1.2.8",
"request": "2.88.2",
"request-promise-native": "1.0.8",
"request-to-curl": "0.1.6",
"selectn": "1.1.2",
"socket.io": "4.7.4",
"socket.io-client": "4.7.4",
"socket.io": "4.7.5",
"socket.io-client": "4.7.5",
"uuid": "9.0.1",
"uuid4": "2.0.3",
"ws": "8.16.0"
},
"devDependencies": {
"@types/jest": "29.5.12",
"audit-ci": "6.6.1",
"get-port": "7.0.0",
"get-port": "7.1.0",
"jest": "29.7.0",
"jest-junit": "16.0.0",
"nodemon": "3.1.0",
"npm-check-updates": "16.14.15",
"npm-check-updates": "16.14.18",
"nyc": "15.1.0",
"parse-strings-in-object": "1.6.0",
"pre-commit": "1.2.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ paths:
backend logic such as party verification, quoted fees assessments etc...
tags:
- Transfers
operationId: TransfersPost
requestBody:
description: Transfer request body
content:
Expand Down Expand Up @@ -109,6 +110,7 @@ paths:
information on modes of transfer.
tags:
- Transfers
operationId: TransfersPut
requestBody:
content:
application/json:
Expand All @@ -134,6 +136,7 @@ paths:
for the creation of the transfer.
tags:
- Transfers
operationId: TransfersGet
parameters:
- $ref: '#/components/parameters/transferId'
responses:
Expand All @@ -157,6 +160,7 @@ paths:
of funds from payer DFSP to payees' DFSP.
tags:
- BulkTransfers
operationId: BulkTransfersPost
requestBody:
description: Bulk transfer request body
content:
Expand All @@ -183,6 +187,7 @@ paths:
was used for the creation of the bulk transfer.
tags:
- BulkTransfers
operationId: BulkTransfersGet
parameters:
- $ref: '#/components/parameters/bulkTransferId'
responses:
Expand All @@ -206,6 +211,7 @@ paths:
fascilitate funds transfer from payer DFSP to payees' DFSP.
tags:
- BulkQuotes
operationId: BulkQuotesPost
requestBody:
description: Bulk quote request body
content:
Expand All @@ -232,6 +238,7 @@ paths:
used for the creation of the bulk quote.
tags:
- BulkQuotes
operationId: BulkQuotesGet
parameters:
- $ref: '#/components/parameters/bulkQuoteId'
responses:
Expand Down Expand Up @@ -260,6 +267,7 @@ paths:
2. Transaction Request. This request enables a Payee to request Payer to send electronic funds to the Payee.
tags:
- RequestToPay
operationId: RequestToPayPost
requestBody:
description: RequestToPay request body
content:
Expand Down Expand Up @@ -312,6 +320,7 @@ paths:
backend logic such as party verification, quoted fees assessments etc...
tags:
- RequestToPayTransfer
operationId: RequestToPayTransferPost
requestBody:
description: Request To Pay Transfer request body
content:
Expand Down Expand Up @@ -347,6 +356,7 @@ paths:
more information on modes of transfer.
tags:
- RequestToPayTransferID
operationId: RequestToPayTransferPut
requestBody:
content:
application/json:
Expand Down Expand Up @@ -375,6 +385,7 @@ paths:
Caller DFSP is used as the account source FSP information
tags:
- Accounts
operationId: AccountsPost
requestBody:
description: Identities list request body
content:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,19 @@
}
}
}
},
"/transfers": {
"post": {
"response": {
"bodyOverride": {}
}
}
},
"/transfers/{transferId}": {
"put": {
"response": {
"bodyOverride": {}
}
}
}
}
10 changes: 7 additions & 3 deletions src/lib/api-routes/outbound.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,13 @@ router.post('/template/:traceID', [
const inputJson = JSON.parse(JSON.stringify(req.body))
// TODO: Change the following value to the dfspId based on the login incase HOSTING_ENABLED
const dfspId = req.user ? req.user.dfspId : null
outbound.OutboundSend(inputJson, traceID, dfspId)

return res.status(200).json({ status: 'OK' })
if (req.query.sync && req.query.sync === 'true') {
const result = await outbound.OutboundSend(inputJson, traceID, dfspId, true)
return res.status(200).json(result)
} else {
outbound.OutboundSend(inputJson, traceID, dfspId)
return res.status(200).json({ status: 'OK' })
}
} catch (err) {
res.status(500).json({ error: err && err.message })
}
Expand Down
7 changes: 3 additions & 4 deletions src/lib/db/models/mongoDBWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ const models = {
})
}

process.on('SIGINT', () => {
mongoose.connection.close(() => {
process.exit(0)
})
process.on('SIGINT', async () => {
await mongoose.connection.close()
process.exit(0)
})

module.exports = {
Expand Down
27 changes: 16 additions & 11 deletions src/lib/mocking/openApiMockHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,22 @@ module.exports.handleRequest = async (req, h) => {
req.customInfo.negotiatedContentType = versionNegotiationResult.responseContentTypeHeader
selectedApi = apis[versionNegotiationResult.negotiatedIndex]
}
return selectedApi.openApiBackendObject.handleRequest(
{
method: req.method,
path: req.path,
body: req.payload,
query: req.query,
headers: req.headers
},
req,
h
)
try {
return await selectedApi.openApiBackendObject.handleRequest(
{
method: req.method,
path: req.path,
body: req.payload,
query: req.query,
headers: req.headers
},
req,
h
)
} catch (err) {
customLogger.logMessage('error', err.message, { request: req })
return h.response({ error: 'Not Found' }).code(404)
}
}

const pickApiByMethodPathHostnameAndPrefix = (req) => {
Expand Down
27 changes: 15 additions & 12 deletions src/lib/test-outbound/outbound-initiator.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const getTracing = (traceID, dfspId) => {
return tracing
}

const OutboundSend = async (inputTemplate, traceID, dfspId) => {
const OutboundSend = async (inputTemplate, traceID, dfspId, sync = false) => {
const totalCounts = getTotalCounts(inputTemplate)
const globalConfig = {
broadcastOutboundProgressEnabled: true,
Expand Down Expand Up @@ -98,18 +98,21 @@ const OutboundSend = async (inputTemplate, traceID, dfspId) => {
const completedTimeStamp = new Date()
const runDurationMs = completedTimeStamp.getTime() - startedTimeStamp.getTime()
// Send the total result to client
const runtimeInformation = {
testReportId: inputTemplate.name + '_' + completedTimeStamp.toISOString(),
completedTimeISO: completedTimeStamp.toISOString(),
startedTime: startedTimeStamp.toUTCString(),
completedTime: completedTimeStamp,
completedTimeUTC: completedTimeStamp.toUTCString(),
runDurationMs,
avgResponseTime: 'NA',
totalAssertions: 0,
totalPassedAssertions: 0
}
if (sync) {
return generateFinalReport(inputTemplate, runtimeInformation)
}
if (tracing.outboundID) {
const runtimeInformation = {
testReportId: inputTemplate.name + '_' + completedTimeStamp.toISOString(),
completedTimeISO: completedTimeStamp.toISOString(),
startedTime: startedTimeStamp.toUTCString(),
completedTime: completedTimeStamp,
completedTimeUTC: completedTimeStamp.toUTCString(),
runDurationMs,
avgResponseTime: 'NA',
totalAssertions: 0,
totalPassedAssertions: 0
}
const totalResult = generateFinalReport(inputTemplate, runtimeInformation)
if (Config.getSystemConfig().HOSTING_ENABLED) {
dbAdapter.upsert('reports', totalResult, { dfspId })
Expand Down
19 changes: 18 additions & 1 deletion test/unit/lib/test-outbound/outbound-initiator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1708,7 +1708,24 @@ describe('Outbound Initiator Functions', () => {
await OutboundInitiator.OutboundSend(sampleTemplateModified4, '123')
expect(spyDbAdapterUpsertReport).toBeCalled()
})

it('OutboundSend with sync option enabled', async () => {
axios.mockImplementation(() => Promise.resolve({
status: 200,
statusText: 'OK',
data: {},
request: {
toCurl: () => ''
}
}))
SpyGetApiDefinitions.mockResolvedValue([{
specFile: 'spec_files/api_definitions/fspiop_1.0/api_spec.yaml',
type: 'fspiop'
}])
const syncResp = await OutboundInitiator.OutboundSend(sampleTemplate, 'aabb123aabb', null, true)
expect(syncResp).not.toBeNull
expect(syncResp.test_cases[0]?.requests[0]).toHaveProperty('status')
expect(syncResp.test_cases[0]?.requests[0]).toHaveProperty('response')
})
})

describe('terminateOutbound', () => {
Expand Down

0 comments on commit 52310c9

Please sign in to comment.