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

Ft/national bank mw core connector #73

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d8d7ff9
chore: create national bank core connector
elijah0kello Oct 28, 2024
e3add88
docs: updated designs and added documenation
elijah0kello Oct 29, 2024
9a9b84b
chore: update docs
elijah0kello Oct 31, 2024
34caa9b
Feat: Added mock test and types for NBM
Horac3 Nov 11, 2024
72f661f
Chore: Working on update send money tests
Horac3 Nov 18, 2024
35ea2f2
Tests: Mock tests for get parties and send money
Horac3 Nov 22, 2024
03549e9
Chore: Added NBM types for API spec
Horac3 Nov 26, 2024
192ad92
Chore: Fixed NBM types and cofig files
Horac3 Nov 27, 2024
9923398
Feat: Writing mock tests
Horac3 Nov 27, 2024
14130c9
Chore: Defining api specs
Nov 29, 2024
50ebadd
Chore: Defining api specs
Nov 29, 2024
7910f56
Fix: Update send money fix
Nov 29, 2024
2247d50
Tests: Writing integration tests
Horac3 Dec 4, 2024
fd53b44
Tests: Get parties done
Horac3 Dec 5, 2024
d442cce
Tests: Get parties done
Horac3 Dec 5, 2024
5bc3961
Chore: Writing integration tests
Horac3 Dec 11, 2024
1e7645c
Chore: Writing integration tests
Horac3 Dec 11, 2024
dfd7993
Chore: Integration tests
Horac3 Dec 12, 2024
2915e62
Chore: Integration tests completed
Horac3 Dec 13, 2024
0d802b7
Docs
Horac3 Dec 20, 2024
f5ae718
Docs: Get parties update
Horac3 Jan 8, 2025
5513c21
Feat: Implemented mocks tests
Horac3 Jan 21, 2025
61bdbcd
Fix: Fixed failing unit test
Horac3 Jan 21, 2025
32214cf
Fix: Restored missing implementations for merchant pay
Horac3 Jan 22, 2025
5fd9409
Tests: Unit tests implemented
Horac3 Jan 22, 2025
c34c272
Chore: Implementing ISO mappings
Horac3 Jan 27, 2025
10f7ca1
Chore: Implemented ISO Mappings and unit tests
Horac3 Jan 28, 2025
e11824e
Merge branch 'dev' of https://github.com/Izyane-InovSolutions/ml-refe…
elijah0kello Jan 29, 2025
6c6cd3d
chore: fixed linitng error
elijah0kello Jan 29, 2025
dbb2c7c
chore: updated dependencies
elijah0kello Jan 29, 2025
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
Prev Previous commit
Next Next commit
Feat: Implemented mocks tests
  • Loading branch information
Horac3 committed Jan 21, 2025
commit 5513c2136e88b746550b9a128cb3690d03a5c847
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ export type TNBMDisbursementResponse = {
"data": {
"transaction": {
"reference_id": string,
"airtel_money_id": string,
"id": string,
"status": string,
"message": string,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
/*****
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 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>

* Elijah Okello <elijahokello90@gmail.com>
* Horace Lwanda <lwandahorace@gmail.com>
--------------
**********/

import config from 'src/config';
import { CoreConnectorAggregate, TQuoteRequest, TtransferPatchNotificationRequest, TtransferRequest } from '../../../src/domain';
import { INBMClient, NBMClientFactory, TNBMSendMoneyRequest, TNBMUpdateSendMoneyRequest } from '../../../src/domain/CBSClient';
import { ISDKClient, SDKClientFactory } from '../../../src/domain/SDKClient';
import { loggerFactory } from '../../../src/infra/logger';
import {
transferPatchNotificationRequestDto,
transferRequestDto,
quoteRequestDto,
sendMoneyDTO,
updateSendMoneyDTO
} from '../../fixtures';
import { AxiosClientFactory } from 'src/infra/axiosHttpClient';

// Mock implementations
let mockNBMClient: INBMClient;
let mockSDKClient: ISDKClient;
const mockNBMConfig = config.get('nbm');
const mockLogger = loggerFactory({ context: 'ccAgg tests' });
describe('CoreConnectorAggregate Unit Tests', () => {
let ccAggregate: CoreConnectorAggregate;

beforeEach(() => {
jest.clearAllMocks();
const httpClient = AxiosClientFactory.createAxiosClientInstance();
mockSDKClient = SDKClientFactory.getSDKClientInstance(mockLogger, httpClient, SDK_URL);
mockNBMClient = NBMClientFactory.createClient({ mockNBMConfig, httpClient, mockLogger });
ccAggregate = new CoreConnectorAggregate(
mockSDKClient,
mockNBMClient,
mockNBMConfig,
mockLogger
);
});

describe('Payee Flow Tests', () => {
const ACCOUNT_NO = "100100200";
const idType = "ACCOUNT_NO";

test('getParties should return party information when successful', async () => {
const mockPartyResponse = {
partyId: ACCOUNT_NO,
name: 'Test User',
// Add other party details
};

mockSDKClient.getParties.mockResolvedValueOnce(mockPartyResponse);

const result = await ccAggregate.getParties(idType, ACCOUNT_NO);

expect(mockSDKClient.getParties).toHaveBeenCalledWith(idType, ACCOUNT_NO);
expect(result).toEqual(mockPartyResponse);
});

test('quoteRequest should process quote when party exists', async () => {
const quoteRequest: TQuoteRequest = quoteRequestDto();
const mockQuoteResponse = {
quoteId: 'mock-quote-id',
// Add other quote response details
};

mockSDKClient.sendQuoteRequest.mockResolvedValueOnce(mockQuoteResponse);

const result = await ccAggregate.processQuoteRequest(quoteRequest);

expect(mockSDKClient.sendQuoteRequest).toHaveBeenCalledWith(quoteRequest);
expect(result).toEqual(mockQuoteResponse);
});

test('transferRequest should process transfer when party exists', async () => {
const transferRequest: TtransferRequest = transferRequestDto(idType, ACCOUNT_NO, "103");
const mockTransferResponse = {
transferId: 'mock-transfer-id',
// Add other transfer response details
};

mockSDKClient.sendTransferRequest.mockResolvedValueOnce(mockTransferResponse);

const result = await ccAggregate.processTransferRequest(transferRequest);

expect(mockSDKClient.sendTransferRequest).toHaveBeenCalledWith(transferRequest);
expect(result).toEqual(mockTransferResponse);
});

test('transferPatchNotification should update transfer status successfully', async () => {
const transferId = 'mock-transfer-id';
const patchNotification: TtransferPatchNotificationRequest = transferPatchNotificationRequestDto(
"COMPLETED",
idType,
ACCOUNT_NO,
"500"
);
const mockPatchResponse = {
status: 'COMPLETED',
// Add other patch response details
};

mockSDKClient.sendTransferPatchNotification.mockResolvedValueOnce(mockPatchResponse);

const result = await ccAggregate.processTransferPatchNotification(transferId, patchNotification);

expect(mockSDKClient.sendTransferPatchNotification).toHaveBeenCalledWith(transferId, patchNotification);
expect(result).toEqual(mockPatchResponse);
});
});

describe('Payer Flow Tests', () => {
const ACCOUNT_NO = "100100200";

test('sendMoney should process payer request successfully', async () => {
const sendMoneyRequest: TNBMSendMoneyRequest = sendMoneyDTO(ACCOUNT_NO, "103");
const mockSendMoneyResponse = {
transactionId: 'mock-transaction-id',
// Add other response details
};

mockNBMClient.sendMoney.mockResolvedValueOnce(mockSendMoneyResponse);

const result = await ccAggregate.processSendMoneyRequest(sendMoneyRequest);

expect(mockNBMClient.sendMoney).toHaveBeenCalledWith(sendMoneyRequest);
expect(result).toEqual(mockSendMoneyResponse);
});

test('updateSendMoney should update transaction status successfully', async () => {
const transactionId = 'mock-transaction-id';
const updateRequest: TNBMUpdateSendMoneyRequest = updateSendMoneyDTO(true);
const mockUpdateResponse = {
status: 'SUCCESS',

};

mockNBMClient.updateSendMoney.mockResolvedValueOnce(mockUpdateResponse);

const result = await ccAggregate.processUpdateSendMoneyRequest(transactionId, updateRequest);

expect(mockNBMClient.updateSendMoney).toHaveBeenCalledWith(transactionId, updateRequest);
expect(result).toEqual(mockUpdateResponse);
});
});

describe('Error Handling', () => {
test('should handle SDK client errors appropriately', async () => {
const error = new Error('SDK Client Error');
mockSDKClient.getParties.mockRejectedValueOnce(error);

await expect(ccAggregate.getParties('ACCOUNT_NO', '12345'))
.rejects
.toThrow('SDK Client Error');

expect(mockLogger.error).toHaveBeenCalled();
});

test('should handle NBM client errors appropriately', async () => {
const error = new Error('NBM Client Error');
mockNBMClient.sendMoney.mockRejectedValueOnce(error);

const sendMoneyRequest = sendMoneyDTO('12345', '100');
await expect(ccAggregate.processSendMoneyRequest(sendMoneyRequest))
.rejects
.toThrow('NBM Client Error');

expect(mockLogger.error).toHaveBeenCalled();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe('CoreConnectorAggregate Tests -->', () => {
});

// Send Money - Payer
test('Test POST/ send-money: response should be payee details ', async ()=>{
test('Test POST /send-money: response should be payee details ', async ()=>{
const sendMoneyRequest: TNBMSendMoneyRequest= sendMoneyDTO(ACCOUNT_NO, "103");
const url = `${DFSP_URL}/send-money`;

Expand All @@ -154,7 +154,6 @@ describe('CoreConnectorAggregate Tests -->', () => {
'Content-Type': 'application/json',
},
});

logger.info(JSON.stringify(res.data));
expect(res.status).toEqual(200);
});
Expand Down
Loading