Skip to content

Commit

Permalink
add BulkTransfersCallbackReceived domain handler
Browse files Browse the repository at this point in the history
  • Loading branch information
kleyow committed Sep 20, 2022
1 parent b88fde0 commit bcf49e4
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { ILogger } from '@mojaloop/logging-bc-public-types-lib';
import {
DomainEvent,
BulkTransfersCallbackReceivedDmEvt,
ProcessBulkTransfersCallbackCmdEvt,
IProcessBulkTransfersCallbackCmdEvtData,
} from '@mojaloop/sdk-scheme-adapter-private-shared-lib';
import { IDomainEventHandlerOptions } from '../../types';

Expand All @@ -9,8 +12,28 @@ export async function handleBulkTransfersCallbackReceived(
options: IDomainEventHandlerOptions,
logger: ILogger,
): Promise<void> {
const bulkTransfersCallbackReceivedMessage
= BulkTransfersCallbackReceivedDmEvt.CreateFromDomainEvent(message);
try {
const processPartyInfoCallbackMessageData: IProcessBulkTransfersCallbackCmdEvtData = {
bulkId: bulkTransfersCallbackReceivedMessage.getKey(),
content: {
batchId: bulkTransfersCallbackReceivedMessage.batchId,
bulkTransferId: bulkTransfersCallbackReceivedMessage.bulkTransferId,
bulkTransfersResult: bulkTransfersCallbackReceivedMessage.bulkTransfersResult,
},
timestamp: Date.now(),
headers: bulkTransfersCallbackReceivedMessage.getHeaders(),
};

const processBulkTransfersCallbackMessage
= new ProcessBulkTransfersCallbackCmdEvt(processPartyInfoCallbackMessageData);

await options.commandProducer.sendCommandEvent(processBulkTransfersCallbackMessage);

logger.info(`Sent command event ${processBulkTransfersCallbackMessage.getName()}`);
console.log(processBulkTransfersCallbackMessage);
} catch (err) {
logger.info(`Failed to send command event . ${(err as Error).message}`);
logger.info(`Failed to send command event ProcessBulkTransfersCallbackCmdEvt. ${(err as Error).message}`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ export * from './sdk_outbound_bulk_accept_party_info_processed';
export * from './bulk-quotes-callback-received';
export * from './party-info-callback-processed';
export * from './sdk_outbound_bulk_accept_quote_processed';
export * from './bulk_transfers_callback_received';
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*****
License
--------------
Copyright © 2017 Bill & Melinda Gates Foundation
The Mojaloop files are made available by the Bill & Melinda Gates 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 (alphabetical ordering) 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>
* Modusbox
- Kevin Leyow <kevin.leyow@modusbox.com>
--------------
******/

'use strict'

import { DefaultLogger } from "@mojaloop/logging-bc-client-lib";
import { ILogger } from "@mojaloop/logging-bc-public-types-lib";
import {
DomainEvent,
EventType,
IDomainEventData,
BulkTransfersCallbackReceivedDmEvt,
ProcessBulkTransfersCallbackCmdEvt,
} from "@mojaloop/sdk-scheme-adapter-private-shared-lib"
import { randomUUID } from "crypto";
import { handleBulkTransfersCallbackReceived } from "../../../../src/application/handlers"
import { IDomainEventHandlerOptions } from "../../../../src/types";


describe('handleBulkTransfersCallbackReceived', () => {
const logger: ILogger = new DefaultLogger('bc', 'appName', 'appVersion');
const domainEventHandlerOptions = {
commandProducer: {
init: jest.fn(),
sendCommandEvent: jest.fn()
}
} as unknown as IDomainEventHandlerOptions

let sampleBulkTransfersCallbackReceivedMessageData: IDomainEventData;
let key: string;

beforeEach(async () => {
key = `${randomUUID()}_${randomUUID()}`
sampleBulkTransfersCallbackReceivedMessageData = {
key,
name: BulkTransfersCallbackReceivedDmEvt.name,
content: {
batchId: '61c35bae-77d0-4f7d-b894-be375b838ff6',
bulkTransferId: '81c35bae-77d0-4f7d-b894-be375b838ff6',
bulkTransfersResult: {
bulkTransferId: '81c35bae-77d0-4f7d-b894-be375b838ff6',
currentState: 'COMPLETED',
individualTransferResults: [
{
transferId: 'individual-transfer-id',
to: {
partyIdInfo: {
partyIdType: 'MSISDN',
partyIdentifier: '1'
},
},
amountType: 'SEND',
currency: 'USD',
amount: '1'
},
]
}
},
timestamp: Date.now(),
headers: [],
}
});


test('emits a ProcessBulkTransfersCallback message', async () => {
const sampleDomainEventDataObj = new DomainEvent(sampleBulkTransfersCallbackReceivedMessageData);
handleBulkTransfersCallbackReceived(sampleDomainEventDataObj, domainEventHandlerOptions, logger)
expect(domainEventHandlerOptions.commandProducer.sendCommandEvent)
.toBeCalledWith(
expect.objectContaining({
_data: expect.objectContaining({
key,
name: ProcessBulkTransfersCallbackCmdEvt.name,
type: EventType.COMMAND_EVENT,
content: sampleBulkTransfersCallbackReceivedMessageData.content
})
})
)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ export * from './process_sdk_outbound_bulk_quotes_request';
export * from './process_sdk_outbound_bulk_accept_quote';
export * from './process_bulk_quotes_callback';
export * from './process_sdk_outbound_bulk_transfers_request';
export * from './process_bulk_transfers_callback';
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

import { CommandEvent } from '../command_event';
import { IMessageHeader } from '@mojaloop/platform-shared-lib-messaging-types-lib';
import { SDKSchemeAdapter } from '@mojaloop/api-snippets';

export interface IProcessBulkTransfersCallbackCmdEvtData {
bulkId: string;
content: null;
content: {
batchId: string;
bulkTransferId: string;
bulkTransfersResult: SDKSchemeAdapter.Outbound.V2_0_0.Types.bulkTransferResponse
},
timestamp: number | null;
headers: IMessageHeader[] | null;
}
Expand All @@ -15,7 +20,7 @@ export class ProcessBulkTransfersCallbackCmdEvt extends CommandEvent {
key: data.bulkId,
timestamp: data.timestamp,
headers: data.headers,
content: null,
content: data.content,
name: ProcessBulkTransfersCallbackCmdEvt.name,
});
}
Expand All @@ -32,4 +37,19 @@ export class ProcessBulkTransfersCallbackCmdEvt extends CommandEvent {
};
return new ProcessBulkTransfersCallbackCmdEvt(data);
}

get batchId(): string {
const content = this.getContent() as IProcessBulkTransfersCallbackCmdEvtData['content'];
return content.batchId;
}

get bulkTransferId(): string {
const content = this.getContent() as IProcessBulkTransfersCallbackCmdEvtData['content'];
return content.bulkTransferId;
}

get bulkTransfersResult(): SDKSchemeAdapter.Outbound.V2_0_0.Types.bulkTransferResponse {
const content = this.getContent() as IProcessBulkTransfersCallbackCmdEvtData['content'];
return content.bulkTransfersResult;
}
}

0 comments on commit bcf49e4

Please sign in to comment.