@spreeloop/orange_money
Version:
A orange money api integration package
77 lines • 2.91 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const https_1 = require("./https");
const axios_1 = require("axios");
describe('hash', () => {
const btoaRef = global.btoa;
it('should still Hash if the btao function is not available', () => {
global.btoa = undefined;
const hashResponse = (0, https_1.hash)('key', 'secret');
expect(hashResponse).toBe('a2V5OnNlY3JldA==');
global.btoa = btoaRef;
});
});
describe('parseAxiosError', () => {
it('should return initial obj if not instance of axios error', () => {
const initialObj = { key: 'ERROR_100' };
const parsedResponse = (0, https_1.parseAxiosError)(initialObj);
expect(parsedResponse).toBe(initialObj);
});
it('should have the configuration failed message when config failed', () => {
const message = 'configuration failed';
const parsedResponse = (0, https_1.parseAxiosError)(new axios_1.AxiosError(message));
expect(parsedResponse).toEqual({
configFailed: message,
});
});
it('should return request failed when axios is unable to send the request.', () => {
const request = {
headers: {
'Content-Type': 'application/json',
},
};
const parsedResponse = (0, https_1.parseAxiosError)(new axios_1.AxiosError('message', '400', undefined, request));
expect(parsedResponse).toEqual({
requestFailed: { data: undefined, headers: undefined },
});
});
it('should return response error when the request response fail to be retrieve.', () => {
const request = {
headers: {
'Content-Type': 'application/json',
},
body: '',
};
const response = {
data: '',
status: 201,
statusText: 'created',
headers: {},
request: request,
};
const parsedResponse = (0, https_1.parseAxiosError)(new axios_1.AxiosError('message', '400', undefined, request, response));
expect(parsedResponse).toEqual({
responseError: {
data: response.data,
status: response.status,
statusText: response.statusText,
headers: response.headers,
},
requestBody: request.body,
});
});
});
describe('Test the utils function', () => {
it('Generate the base 64 encoding', async () => {
const value = (0, https_1.encodeToBase64)('123', '123');
expect(value).toEqual('MTIzOjEyMw');
});
it('encode the body request', async () => {
const body = {
amount: '123',
};
const value = (0, https_1.encodeTheBodyOfRequest)(body);
expect(value).toEqual('amount=123');
});
});
//# sourceMappingURL=https.spec.js.map