UNPKG

@spreeloop/orange_money

Version:
177 lines 6.86 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const requests = __importStar(require("../../utils/https")); const constants_1 = require("../utils/constants"); const transfer_1 = require("./transfer"); describe('transfer', () => { it('should fail on invalid parameter provided', async () => { const { error, data, raw } = await (0, transfer_1.transfer)({ configs: { channelUserMsisdn: '', clientId: '', clientSecret: '', customerKey: '', customerSecret: '', pin: '', environment: constants_1.DisbursementXTargetEnvironmentType.sandbox, logger: console, }, params: { webhook: '', amount: 0, customerPhone: '', customerName: '', token: '', }, endPoint: '', }); expect(data).not.toBeDefined(); expect(raw).not.toBeDefined(); expect(error).toBeDefined(); }); it('should fail on invalid phone number provided provided', async () => { const { error, data, raw } = await (0, transfer_1.transfer)({ configs: { channelUserMsisdn: '237699947943', clientId: 'clientId', clientSecret: 'clientSecret', customerKey: 'customerKey', customerSecret: 'customerSecret', pin: 'pin', environment: constants_1.DisbursementXTargetEnvironmentType.sandbox, logger: console, }, params: { webhook: 'https://example.com', amount: 100, customerPhone: '69532652', customerName: 'itachi uchiwa', token: 'token', }, endPoint: 'https://example.com', }); expect(data).not.toBeDefined(); expect(raw).not.toBeDefined(); expect(error).toBeDefined(); }); it('should fail on request failure', async () => { const postSpy = jest .spyOn(requests, 'postRequest') .mockImplementation() .mockResolvedValue({ error: {}, }); const { error, data, raw } = await (0, transfer_1.transfer)({ configs: { channelUserMsisdn: '237699947943', clientId: 'clientId', clientSecret: 'clientSecret', customerKey: 'customerKey', customerSecret: 'customerSecret', pin: 'pin', environment: constants_1.DisbursementXTargetEnvironmentType.sandbox, logger: console, }, params: { webhook: 'https://example.com', amount: 100, customerPhone: '695326522', customerName: 'itachi uchiwa', token: 'token', }, endPoint: 'https://example.com', }); expect(data).not.toBeDefined(); expect(raw).not.toBeDefined(); expect(postSpy).toHaveBeenCalledTimes(1); expect(error).toBeDefined(); }); it('should succeed on request succeed', async () => { const postSpy = jest .spyOn(requests, 'postRequest') .mockImplementation() .mockResolvedValue({ response: { data: { MD5OfMessageBody: 'MD5OfMessageBody', MD5OfMessageAttributes: 'MD5OfMessageAttributes', MessageId: 'MessageId', ResponseMetadata: { RequestId: 'RequestId', HTTPStatusCode: 200, HTTPHeaders: { 'x-amzn-requestid': 'x-amzn-requestid', 'x-amzn-trace-id': 'x-amzn-trace-id', 'content-type': 'content-type', 'content-length': 'content-length', }, RetryAttempts: 2, }, }, }, }); const { error, data, raw } = await (0, transfer_1.transfer)({ configs: { channelUserMsisdn: '237699947943', clientId: 'clientId', clientSecret: 'clientSecret', customerKey: 'customerKey', customerSecret: 'customerSecret', pin: 'pin', environment: constants_1.DisbursementXTargetEnvironmentType.sandbox, logger: console, }, params: { webhook: 'https://example.com', amount: 100, customerPhone: '695326522', customerName: 'itachi uchiwa', token: 'token', }, endPoint: 'https://example.com', }); expect(error).not.toBeDefined(); expect(postSpy).toHaveBeenCalledTimes(1); expect(raw).toEqual({ MD5OfMessageBody: 'MD5OfMessageBody', MD5OfMessageAttributes: 'MD5OfMessageAttributes', MessageId: 'MessageId', ResponseMetadata: { RequestId: 'RequestId', HTTPStatusCode: 200, HTTPHeaders: { 'x-amzn-requestid': 'x-amzn-requestid', 'x-amzn-trace-id': 'x-amzn-trace-id', 'content-type': 'content-type', 'content-length': 'content-length', }, RetryAttempts: 2, }, }); expect(data).toBe('MessageId'); }); }); //# sourceMappingURL=transfer.spec.js.map