Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: integration of requestPartiesInformation #65

Merged
merged 19 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM node:12.16.1-alpine as builder
FROM node:14.15-alpine as builder
USER root
WORKDIR /opt/thirdparty-scheme-adapter

RUN apk add --no-cache -t build-dependencies git make gcc g++ python libtool autoconf automake \
RUN apk update \
&& apk add --no-cache -t build-dependencies git make gcc g++ python libtool autoconf automake openssh \
&& cd $(npm root -g)/npm \
&& npm config set unsafe-perm true \
&& npm install -g node-gyp
Expand All @@ -13,7 +14,7 @@ RUN npm prune --production

COPY . /opt/thirdparty-scheme-adapter

FROM node:12.16.1-alpine
FROM node:14.15-alpine
WORKDIR /opt/thirdparty-scheme-adapter

# Create empty log file & link stdout to the application log file
Expand Down
21,527 changes: 569 additions & 20,958 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"@mojaloop/central-services-health": "^11.0.0",
"@mojaloop/central-services-metrics": "^9.5.0",
"@mojaloop/central-services-shared": "^11.5.9",
"@mojaloop/sdk-scheme-adapter": "^11.15.0",
"@mojaloop/sdk-standard-components": "^15.4.0",
"@types/axios": "^0.14.0",
"@types/convict": "^5.2.2",
Expand Down
11 changes: 3 additions & 8 deletions src/models/pispTransaction.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
v1_1 as fspiopAPI,
thirdparty as tpAPI
} from '@mojaloop/api-snippets'
import { OutboundAPI } from '@mojaloop/sdk-scheme-adapter'
import { Method } from 'javascript-state-machine'
import { ErrorInformation } from '~/interface/types'
import { ControlledStateMachine, StateData, PersistentModelConfig } from '~/models/persistent.model'
Expand All @@ -46,12 +47,6 @@ export enum RequestPartiesInformationState {
ERROR_OCCURRED = 'ERROR_OCCURRED'
}

export interface RequestPartiesInformationResponse {
party?: fspiopAPI.Schemas.Party
currentState: RequestPartiesInformationState
errorInformation?: ErrorInformation
}

export enum PISPTransactionModelState {
start = 'start',
partyLookupSuccess = 'partyLookupSuccess',
Expand Down Expand Up @@ -100,7 +95,7 @@ export interface ThirdpartyTransactionPartyLookupRequest {
}

export interface ThirdpartyTransactionPartyLookupResponse {
party?: fspiopAPI.Schemas.Party
party?: tpAPI.Schemas.Party
errorInformation?: ErrorInformation
currentState: PISPTransactionModelState
}
Expand Down Expand Up @@ -141,7 +136,7 @@ export interface PISPTransactionData extends StateData {

// party lookup
payeeRequest?: PayeeLookupRequest
payeeResolved?: RequestPartiesInformationResponse
payeeResolved?: OutboundAPI.Schemas.partiesByIdResponse
partyLookupResponse?: ThirdpartyTransactionPartyLookupResponse

// initiate
Expand Down
4 changes: 2 additions & 2 deletions src/models/pispTransaction.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
MojaloopRequests,
ThirdpartyRequests
} from '@mojaloop/sdk-standard-components'
import { OutboundAPI } from '@mojaloop/sdk-scheme-adapter'
import {
v1_1 as fspiopAPI,
thirdparty as tpAPI
Expand All @@ -44,7 +45,6 @@ import {
PISPTransactionModelState,
PISPTransactionPhase,
PISPTransactionStateMachine,
RequestPartiesInformationResponse,
ThirdpartyTransactionApproveResponse,
ThirdpartyTransactionInitiateRequest,
ThirdpartyTransactionInitiateResponse,
Expand Down Expand Up @@ -141,7 +141,7 @@ export class PISPTransactionModel
// call GET /parties on sdk-scheme-adapter Outbound service
const response = this.data.payeeResolved = await this.sdkOutgoingRequests.requestPartiesInformation(
partyIdType, partyIdentifier, partySubIdOrType
) as RequestPartiesInformationResponse
) as OutboundAPI.Schemas.partiesByIdResponse

this.data.partyLookupResponse = {
party: response.party,
Expand Down
1 change: 0 additions & 1 deletion src/server/plugins/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ export const StatePlugin = {

const sdkOutgoingRequests = new SDKOutgoingRequests({
logger,
dfspId: config.SHARED.DFSP_ID,
uri: config.SHARED.SDK_OUTGOING_URI,
scheme: config.SHARED.SDK_OUTGOING_HTTP_SCHEME as Scheme,
requestPartiesInformationPath: config.SHARED.SDK_PARTIES_INFORMATION_URI,
Expand Down
27 changes: 14 additions & 13 deletions src/shared/sdk-outgoing-requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ import {
OutboundRequestToPayTransferPostRequest,
OutboundRequestToPayTransferPostResponse
} from '../models/thirdparty.transactions.interface'
import {
RequestPartiesInformationResponse
} from '~/models/pispTransaction.interface'
import { OutboundAPI } from '@mojaloop/sdk-scheme-adapter'
export interface SDKOutgoingRequestsConfig extends HttpRequestsConfig {
dfspId: string
// requestAuthorizationPath: string
requestPartiesInformationPath: string
requestToPayTransferPath: string
}
Expand Down Expand Up @@ -70,14 +68,9 @@ export class SDKOutgoingRequests extends HttpRequests {
return this.config.requestToPayTransferPath
}

// dfspId getter
get dfspId (): string {
return this.config.dfspId
}

// REQUESTS
/**
* TODO: these requests will be used by DFSPTransactionModel
* TODO: these requests will be used by DFSPTransactionModel/PISPTransactionModel
* // these two will be done by calling ThirdpartyRequests interface, so not implemented here
* notifyThirdpartyAboutRejectedAuthorization
* notifyThirdpartyAboutTransfer
Expand All @@ -90,9 +83,17 @@ export class SDKOutgoingRequests extends HttpRequests {
*
* */

/**
* @method requestPartiesInformation
* @description used to retrieve information about the Party
* @param {string} type - type of party
* @param {string} id - id of party
* @param {string} [subId] - optional sub id of party
* @returns {Promise<OutboundAPI.Schemas.partiesByIdResponse | void>} information about the party
*/
async requestPartiesInformation (
type: string, id: string, subId?: string
): Promise<RequestPartiesInformationResponse | void> {
): Promise<OutboundAPI.Schemas.partiesByIdResponse | void> {
// generate uri from template
const uri = this.fullUri(
// config.SHARED.SDK_PARTIES_INFORMATION_URI
Expand All @@ -105,10 +106,10 @@ export class SDKOutgoingRequests extends HttpRequests {
subId || ''
)
)
this.logger.push({ uri, template: this.requestPartiesInformationPath }).info('requestPartiesInformation')
this.logger.push({ uri }).info('requestPartiesInformation')

// make the GET /parties/{Type}/{ID}[/{SubId}] call
return this.loggedRequest<RequestPartiesInformationResponse>({
return this.loggedRequest<OutboundAPI.Schemas.partiesByIdResponse>({
uri,
method: 'GET',
headers: this.headers,
Expand Down
22 changes: 12 additions & 10 deletions test/integration/inbound/consentRequests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { Message, PubSub } from '~/shared/pub-sub'
import Config from '~/shared/config'
import axios from 'axios'
import env from '../env'
import mockLogger from '../../unit/mockLogger'
import mockLogger from 'test/unit/mockLogger'

describe('PUT /consentRequests/{ID}/error', (): void => {
const scenarioUri = `${env.inbound.baseUri}/consentRequests/997c89f4-053c-4283-bfec-45a1a0a28fba/error`
Expand All @@ -42,7 +42,7 @@ describe('PUT /consentRequests/{ID}/error', (): void => {
}
const payload = {
errorInformation: {
errorCode: "5100",
errorCode: '5100',
errorDescription: 'This is an error description.',
extensionList: {
extension: [
Expand Down Expand Up @@ -71,14 +71,16 @@ describe('PUT /consentRequests/{ID}/error', (): void => {
await pubSub.connect()
expect(pubSub.isConnected).toBeTruthy()

pubSub.subscribe('consent_request_997c89f4-053c-4283-bfec-45a1a0a28fba', async (channel: string, message: Message, _id: number) => {
expect(channel).toEqual('consent_request_997c89f4-053c-4283-bfec-45a1a0a28fba')
expect(message).toEqual(payload)
await pubSub.disconnect()
expect(pubSub.isConnected).toBeFalsy()
pubSub.subscribe('consent_request_997c89f4-053c-4283-bfec-45a1a0a28fba',
async (channel: string, message: Message, _id: number) => {
expect(channel).toEqual('consent_request_997c89f4-053c-4283-bfec-45a1a0a28fba')
expect(message).toEqual(payload)
await pubSub.disconnect()
expect(pubSub.isConnected).toBeFalsy()

resolve()
})
resolve()
}
)

// Act
const response = await axios.put(scenarioUri, payload, axiosConfig)
Expand All @@ -94,7 +96,7 @@ describe('PATCH /consentRequests/{ID}', (): void => {
const scenarioUri = `${env.inbound.baseUri}/consentRequests/997c89f4-053c-4283-bfec-45a1a0a28fba`
describe('Inbound API', (): void => {
const payload = {
authToken: "123456"
authToken: '123456'
}

const axiosConfig = {
Expand Down
60 changes: 60 additions & 0 deletions test/integration/shared/sdk-outgoing-requests.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*****
License
--------------
Copyright © 2020 Mojaloop Foundation
The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0 (the "License")
and you may not use these files except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed
on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
Contributors
--------------
This is the official list of the Mojaloop project contributors for this file.
Names of the original copyright holders (individuals or organizations)
should be listed with a '*' in the first column. People who have
contributed from an organization can be listed under the organization
that actually holds the copyright for their contributions (see the
Gates Foundation organization for an example). Those individuals should have
their names indented and be marked with a '-'. Email address can be added
optionally within square brackets <email>.
* Gates Foundation
- Name Surname <name.surname@gatesfoundation.com>

- Paweł Marzec <pawel.marzec@modusbox.com>
--------------
******/

import { SDKOutgoingRequestsConfig, SDKOutgoingRequests } from '~/shared/sdk-outgoing-requests'
import config from '~/shared/config'
import { Scheme } from '~/shared/http-scheme'
import mockLogger from 'test/unit/mockLogger'

describe('SDKOutgoingRequests', () => {
describe('requestPartiesInformation', () => {
const sdkConfig: SDKOutgoingRequestsConfig = {
logger: mockLogger(),
scheme: Scheme.http,
uri: config.SHARED.SDK_OUTGOING_URI,
// requestAuthorizationPath: string
requestPartiesInformationPath: config.SHARED.SDK_PARTIES_INFORMATION_URI,
requestToPayTransferPath: config.SHARED.SDK_REQUEST_TO_PAY_TRANSFER_URI
}

it('should return parties information', async () => {
const sdkOutRequest = new SDKOutgoingRequests(sdkConfig)

// Act
const result = await sdkOutRequest.requestPartiesInformation('MSISDN', '4412345678')

// Assert
expect(result).toBeDefined()

// result could be void, so Typescript enforce code branching
if (result) {
expect(result.party).toBeDefined()
expect(result.currentState).toEqual('COMPLETED')
}
})
})
})
4 changes: 2 additions & 2 deletions test/unit/handlers/outbound-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ import {
v1_1 as fspiopAPI,
thirdparty as tpAPI
} from '@mojaloop/api-snippets'
import { OutboundAPI } from '@mojaloop/sdk-scheme-adapter'
import { HealthResponse } from '~/interface/types'
import { NotificationCallback, Message, PubSub } from '~/shared/pub-sub'
import {
OutboundThirdpartyAuthorizationsModelState
} from '~/models/thirdparty.authorizations.interface'
import {
RequestPartiesInformationResponse,
PISPTransactionModelState,
ThirdpartyTransactionStatus,
RequestPartiesInformationState
Expand Down Expand Up @@ -76,7 +76,7 @@ const putThirdpartyAuthResponse: tpAPI.Schemas.ThirdpartyRequestsTransactionsIDA
status: 'VERIFIED',
value: 'value'
}
const partyLookupResponse: RequestPartiesInformationResponse = {
const partyLookupResponse: OutboundAPI.Schemas.partiesByIdResponse = {
party: {
partyIdInfo: {
partyIdType: 'MSISDN',
Expand Down
1 change: 1 addition & 0 deletions test/unit/shared/dfsp-backend-requests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ describe('backendRequests', () => {
expect(typeof dfspBackendRequests.patch).toEqual('function')
expect(typeof dfspBackendRequests.post).toEqual('function')
expect(typeof dfspBackendRequests.put).toEqual('function')
expect(typeof dfspBackendRequests.getUserAccounts).toEqual('function')

/**
* TODO: check for methods
Expand Down
2 changes: 1 addition & 1 deletion test/unit/shared/sdk-outgoing-requests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ describe('SDKOutgoingRequests', () => {
let sdkRequest: SDKOutgoingRequests

const config: SDKOutgoingRequestsConfig = {
dfspId: 'the-dfsp-id',
logger: mockLogger(),
scheme: Scheme.http,
uri: 'backend-uri',
// PATHS
// requestAuthorizationPath: 'authorizations',
requestPartiesInformationPath: 'parties/{Type}/{ID}/{SubId}',
requestToPayTransferPath: 'request-to-pay-transfer'
}
Expand Down