Skip to content

Commit

Permalink
feat(mojaloop/#3636): v15.3.0 RC changes (#133)
Browse files Browse the repository at this point in the history
v15.3.0 RC changes - [#3636](mojaloop/project#3636)
- Implement retry logic for a number of flaky tests
- Switched a number of tests to HTTP endpoints as a temporary workarounds for TTK websocket issue
  • Loading branch information
oderayi authored Dec 11, 2023
1 parent b327d29 commit 0bdbcf6
Show file tree
Hide file tree
Showing 10 changed files with 574 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -436,16 +436,20 @@
"scripts": {
"preRequest": {
"exec": [
"if (environment.ENABLE_WS_ASSERTIONS===true) {",
" await websocket.connect(environment.PAYEEFSP_SDK_TESTAPI_WS_URL + '/requests/{$inputs.toIdValue}', 'payeeRequest')",
"}"
"// NOTE: This has been commented out due to the WS issue https://github.com/mojaloop/project/issues/3164, with a work-around to call the HTTP equivalent API on the postRequest instead until it can be resolved.",
"// if (environment.ENABLE_WS_ASSERTIONS===true) {",
"// await websocket.connect(environment.PAYEEFSP_SDK_TESTAPI_WS_URL + '/requests/{$inputs.toIdValue}', 'payeeRequest')",
"// }"
]
},
"postRequest": {
"exec": [
"if (environment.ENABLE_WS_ASSERTIONS===true) {",
" environment.payeeRequest = await websocket.getMessage('payeeRequest', environment.WS_ASSERTION_TIMEOUT)",
"}"
"// NOTE: This has been commented out due to the WS issue https://github.com/mojaloop/project/issues/3164, with a work-around to call the HTTP equivalent API instead until it can be resolved.",
"// if (environment.ENABLE_WS_ASSERTIONS===true) {",
"// environment.payeeRequest = await websocket.getMessage('payeeRequest', environment.WS_ASSERTION_TIMEOUT)",
"// }",
"",
"environment.payeeRequest = (await axios.get(environment.PAYEEFSP_SDK_TESTAPI_URL + '/requests/{$inputs.toIdValue}')).data"
]
}
}
Expand Down Expand Up @@ -636,16 +640,20 @@
"scripts": {
"preRequest": {
"exec": [
"if (environment.ENABLE_WS_ASSERTIONS===true) {",
" await websocket.connect(environment.PAYEEFSP_SDK_TESTAPI_WS_URL + '/requests/{$request.body.quoteId}', 'payeeRequest')",
"}"
"// NOTE: This has been commented out due to the WS issue https://github.com/mojaloop/project/issues/3164, with a work-around to call the HTTP equivalent API on the postRequest instead until it can be resolved.",
"// if (environment.ENABLE_WS_ASSERTIONS===true) {",
"// await websocket.connect(environment.PAYEEFSP_SDK_TESTAPI_WS_URL + '/requests/{$request.body.quoteId}', 'payeeRequest')",
"// }"
]
},
"postRequest": {
"exec": [
"if (environment.ENABLE_WS_ASSERTIONS===true) {",
" environment.payeeRequest = await websocket.getMessage('payeeRequest', environment.WS_ASSERTION_TIMEOUT)",
"}"
"// NOTE: This has been commented out due to the WS issue https://github.com/mojaloop/project/issues/3164, with a work-around to call the HTTP equivalent API instead until it can be resolved.",
"// if (environment.ENABLE_WS_ASSERTIONS===true) {",
"// environment.payeeRequest = await websocket.getMessage('payeeRequest', environment.WS_ASSERTION_TIMEOUT)",
"// }",
"",
"environment.payeeRequest = (await axios.get(environment.PAYEEFSP_SDK_TESTAPI_URL + '/requests/{$request.body.quoteId}')).data"
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@
"fulfilment": "{$inputs.validFulfillment}",
"completedTimestamp": "{$environment.fulfillCompletedTimestamp}"
},
"ignoreCallbacks": true,
"ignoreCallbacks": false,
"scriptingEngine": "javascript",
"tests": {
"assertions": [
Expand Down Expand Up @@ -382,7 +382,8 @@
"postRequest": {
"exec": [
"requestVariables.payeeDuplicateCallback = await inboundEvent.getMessage('payeeDuplicateCallback')",
"console.log(requestVariables.payeeDuplicateCallback)"
"console.log(requestVariables.payeeDuplicateCallback)",
""
]
},
"preRequest": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@
"console.log(requestVariables.payeePostQuotes)"
]
}
}
},
"disabled": false
},
{
"id": 2,
Expand Down Expand Up @@ -183,7 +184,8 @@
"console.log(requestVariables.payerPutQuotes)"
]
}
}
},
"disabled": false
},
{
"id": 3,
Expand Down Expand Up @@ -253,7 +255,8 @@
"console.log(requestVariables.payeePostTransfer)"
]
}
}
},
"disabled": false
},
{
"id": 4,
Expand Down Expand Up @@ -309,7 +312,8 @@
""
]
}
}
},
"disabled": false
},
{
"id": 5,
Expand Down Expand Up @@ -427,7 +431,8 @@
"// console.log(environment.newDateString)"
]
}
}
},
"disabled": false
},
{
"id": 6,
Expand Down Expand Up @@ -456,84 +461,83 @@
"Content-Type": "{$inputs.contentTypeTransfers}"
},
"scriptingEngine": "javascript",
"delay": "16000",
"tests": {
"assertions": [
{
"id": 1,
"description": "Response status to be 202",
"exec": [
"expect(response.status).to.equal(202)"
"expect(requestVariables.transferResponse.code).to.equal(202)"
]
},
{
"id": 2,
"description": "Response statusText be Accepted",
"exec": [
"expect(response.statusText).to.equal('Accepted')"
"expect(requestVariables.transferResponse.status).to.equal('Accepted')"
]
},
{
"id": 12,
"description": "Callback Header - fspiop-source is switch",
"exec": [
"expect(callback.headers['fspiop-source']).to.equal('switch')",
"expect(requestVariables.transferCallback.headers['fspiop-source']).to.equal('switch')",
""
]
},
{
"id": 13,
"description": "Callback Header - fspiop-desination is fspiop-source in request",
"exec": [
"expect(callback.headers['fspiop-destination']).to.equal('{$inputs.fromFspId}')",
"expect(requestVariables.transferCallback.headers['fspiop-destination']).to.equal('{$inputs.fromFspId}')",
""
]
},
{
"id": 14,
"description": "Callback Header - content-type",
"exec": [
"expect(callback.headers['content-type']).to.equal('application/vnd.interoperability.transfers+json;version={$inputs.expectedTransfersVersion}')",
"expect(requestVariables.transferCallback.headers['content-type']).to.equal('application/vnd.interoperability.transfers+json;version={$inputs.expectedTransfersVersion}')",
""
]
},
{
"id": 15,
"description": "Callback Header - accept is empty",
"exec": [
"expect(callback.headers['accept']).to.equal(undefined)",
"expect(requestVariables.transferCallback.headers['accept']).to.equal(undefined)",
""
]
},
{
"id": 16,
"description": "Callback Header - Date is not empty",
"exec": [
"expect(callback.headers['date']).to.not.equal(undefined)",
"expect(requestVariables.transferCallback.headers['date']).to.not.equal(undefined)",
""
]
},
{
"id": 17,
"description": "Callback Header - fspiop-uri is /transfers/transferId",
"exec": [
"expect(callback.headers['fspiop-uri']).to.equal('/transfers/' + request.params.ID)",
"expect(requestVariables.transferCallback.headers['fspiop-uri']).to.equal('/transfers/' + request.params.ID)",
""
]
},
{
"id": 18,
"description": "Callback Header - fspiop-http-method is PUT",
"exec": [
"expect(callback.headers['fspiop-http-method']).to.equal('PUT')",
"expect(requestVariables.transferCallback.headers['fspiop-http-method']).to.equal('PUT')",
""
]
},
{
"id": 21,
"description": "Callback Body - transferState is ABORTED",
"exec": [
"expect(callback.body.transferState).to.equal('ABORTED')",
"expect(requestVariables.transferCallback.body.transferState).to.equal('ABORTED')",
""
]
},
Expand All @@ -542,10 +546,10 @@
"description": "Callback Body - error cause in extensionList",
"exec": [
"",
"expect(callback.body).to.have.property('extensionList')",
"expect(callback.body.extensionList).to.have.property('extension')",
"expect(requestVariables.transferCallback.body).to.have.property('extensionList')",
"expect(requestVariables.transferCallback.body.extensionList).to.have.property('extension')",
"",
"const filteredExtensionListForCause = callback.body.extensionList.extension.filter(ext => ext.key === \"cause\")",
"const filteredExtensionListForCause = requestVariables.transferCallback.body.extensionList.extension.filter(ext => ext.key === \"cause\")",
"",
"expect(filteredExtensionListForCause.length).to.equal(1)",
"",
Expand All @@ -561,8 +565,69 @@
"exec": [
""
]
},
"postRequest": {
"exec": [
"requestVariables.transferResponse = null",
"requestVariables.transferCallback = null",
"const expectedTransferState = 'ABORTED'",
"",
"// lets get retry config",
"const maxRetryCount = Number.parseFloat(environment.RETRY_MAX_ATTEMPTS) || 20",
"const maxRetryWait = Number.parseFloat(environment.RETRY_MAX_WAIT_IN_MS) || 250",
"",
"const callbackName = 'put-transfer'",
"const callbackPath = `/transfers/{$prev.3.request.body.transferId}`",
"",
"async function main() {",
" let _response = response",
" let _callback = callback",
"",
" for (let retryCount = 0 ; retryCount < maxRetryCount; retryCount++) {",
" console.log(`retry-count=${retryCount+1}, max-count=${maxRetryCount}, max-wait=${maxRetryWait}`)",
" ",
" const isOk = _callback?.body?.transferState === expectedTransferState;",
" ",
" if (isOk) {",
" console.log(`Everything is OK, let's continue`)",
" requestVariables.transferResponse = _response",
" requestVariables.transferCallback = _callback",
" break;",
" } else {",
" console.log(`Everything is NOT OK, let's wait for ${maxRetryWait}ms, and try again...`)",
" await custom.sleep(maxRetryWait)",
" await inboundEvent.addListener(callbackName, 'put', callbackPath)",
" const axiosRes = await makeRequest()",
" _response = { code: axiosRes.status, status: axiosRes.statusText }",
" _callback = await inboundEvent.getMessage(callbackName)",
" console.log(`retryCount: ${retryCount+1} - ${callbackName} callback: `, _callback)",
" ",
" }",
" }",
"}",
"",
"async function makeRequest() {",
" const reqParams = {",
" method: 'get', ",
" url: `{$inputs.HOST_ML_API_ADAPTER}/transfers/{$prev.3.request.body.transferId}`,",
" headers: {",
" 'Content-Type': `{$inputs.contentTypeTransfers}`,",
" Accept: `{$inputs.acceptTransfers}`,",
" Date: `{$function.generic.curDate}`,",
" 'FSPIOP-Source': `{$inputs.fromFspId}`,",
" Authorization: `{$inputs.TTK_BEARER_TOKEN}`",
" }",
" };",
" ",
" return axios(reqParams);",
"}",
"",
"await main()"
]
}
}
},
"ignoreCallbacks": false,
"delay": "1000"
}
]
}
Expand Down
Loading

0 comments on commit 0bdbcf6

Please sign in to comment.