Skip to content
Open
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
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
.gitignore
package-lock.json
tsconfig.json
jest.config.json
src
node_modules
docs
__test__
443 changes: 13 additions & 430 deletions README.md

Large diffs are not rendered by default.

52 changes: 33 additions & 19 deletions __test__/auth/login.test.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
import 'dotenv/config';
import { Login, Me } from '../../src/interfaces';

import { Login } from '../../src/interfaces';
import { login } from '../../src';

describe('login', () => {
it('should return a LoginResponse when the request is successful', async () => {
test('should return a LoginResponse when the request is successful', async () => {
const loginData: Login = {
email: <string>process.env.EMAIL,
password: <string>process.env.PASSWORD,
};

const expectedResult: Me = {
uuid: 'fcc52d8c-e37d-49ad-a276-4613664c9a88',
username: 'd3vqba',
name: 'David',
lastname: '',
bio: 'Ingeniero de Software',
profile_photo_path: '',
balance: 0,
complete_name: 'David ',
name_verified: 'David',
profile_photo_url:
'https://ui-avatars.com/api/?name=D&color=7F9CF5&background=EBF4FF',
average_rating: '0.00',
};
const expectedResult = [
'uuid',
'username',
'name',
'lastname',
'bio',
'profile_photo_path',
'balance',
'complete_name',
'name_verified',
'profile_photo_url',
'average_rating',
];

const { me } = await login(loginData);
const result = Object.keys(me);

expect(me).toEqual(expectedResult);
expect(result).toEqual(expectedResult);
});

it('should return an AxiosResponse when the request fails', async () => {
test('should return an AxiosResponse when the email fails', async () => {
const loginData: Login = {
email: 'asd@asd.asd',
password: <string>process.env.PASSWORD,
Expand All @@ -44,4 +43,19 @@ describe('login', () => {

expect(result).toEqual(expectedResult);
});

test('should return an AxiosResponse when the password fails', async () => {
const loginData: Login = {
email: <string>process.env.EMAIL,
password: '123test',
};

const expectedResult = {
error: 'Password mismatch',
};

const result = await login(loginData);

expect(result).toEqual(expectedResult);
});
});
30 changes: 30 additions & 0 deletions __test__/auth/logout.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'dotenv/config';
import { login, logout } from '../../src/api/auth';
import { Login } from '../../src/interfaces';

const loginData: Login = {
email: <string>process.env.EMAIL,
password: <string>process.env.PASSWORD,
};

describe('logout', () => {
test('should return a successful response', async () => {
const expectedResponse = {
message: 'You have been successfully logged out!',
};

const { accessToken } = await login(loginData);
const response = await logout(accessToken);

expect(response).toEqual(expectedResponse);
});

test('should return an error response', async () => {
const expectedErrorResponse = { message: 'Unauthenticated.' };

const accessToken = '123456789';
const response = await logout(accessToken);

expect(response).toEqual(expectedErrorResponse);
});
});
6 changes: 0 additions & 6 deletions __test__/auth/suma.test.ts

This file was deleted.

30 changes: 30 additions & 0 deletions __test__/merchants/appBalance.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'dotenv/config';
import { AppAuth } from '../../src/interfaces';
import { appBalance } from '../../src';

const authApp: AppAuth = {
app_id: <string>process.env.APP_ID,
app_secret: <string>process.env.APP_SECRET,
};

describe('app balance', () => {
test('should return a app balance', async () => {
const result = await appBalance(authApp);

expect(typeof result).toEqual('number');
});

test('should return an AxiosResponse when the request fails', async () => {
const expectedResult = {
error: 'APP no existe',
};

const authApp: AppAuth = {
app_id: 'test',
app_secret: 'test',
};
const result = await appBalance(authApp);

expect(result).toEqual(expectedResult);
});
});
42 changes: 42 additions & 0 deletions __test__/merchants/appInfo.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'dotenv/config';
import { AppAuth } from '../../src/interfaces';
import { appInfo } from '../../src';

const authApp: AppAuth = {
app_id: <string>process.env.APP_ID,
app_secret: <string>process.env.APP_SECRET,
};

describe('app info', () => {
test('should return a successful response', async () => {
const expectedResult = [
'name',
'url',
'desc',
'logo',
'uuid',
'active',
'enabled',
'created_at',
'updated_at',
'app_photo_url',
];
const result = await appInfo(authApp);

expect(Object.keys(result)).toEqual(expectedResult);
});

test('should return an AxiosResponse when the request fails', async () => {
const expectedResult = {
error: 'APP no existe',
};

const authApp: AppAuth = {
app_id: 'test',
app_secret: 'test',
};
const result = await appInfo(authApp);

expect(result).toEqual(expectedResult);
});
});
51 changes: 51 additions & 0 deletions __test__/merchants/createInvoice.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import 'dotenv/config';
import { AppAuth, Invoice, InvoiceResponse } from '../../src/interfaces';
import { createInvoice } from '../../src';

const authApp: AppAuth = {
app_id: <string>process.env.APP_ID,
app_secret: <string>process.env.APP_SECRET,
};

describe('create invoice', () => {
test('should return the invoice created', async () => {
const expectedResult: InvoiceResponse = {
app_id: '',
amount: 0,
description: '',
remote_id: '',
signed: 0,
transation_uuid: '',
url: '',
signedUrl: '',
};
const invoice: Invoice = {
...authApp,
amount: 99.99,
description: 'Enanitos verdes',
remote_id: 'MY_OWN_CUSTOM_ID',
signed: 1,
};

const result = await createInvoice(invoice);

expect(Object.keys(result)).toEqual(Object.keys(expectedResult));
});

test('should return an AxiosResponse when the request fails', async () => {
const expectedResult = {
error: 'APP no existe',
};
const invoice: Invoice = {
app_id: 'test',
app_secret: 'test',
amount: 99.99,
description: 'Enanitos verdes',
remote_id: 'MY_OWN_CUSTOM_ID',
signed: 1,
};
const result = await createInvoice(invoice);

expect(result).toEqual(expectedResult);
});
});
32 changes: 32 additions & 0 deletions __test__/merchants/getOneTransactionFromApp.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'dotenv/config';
import { AppAuth } from '../../src/interfaces';
import { getOneTransactionFromApp } from '../../src';

const authApp: AppAuth = {
app_id: <string>process.env.APP_ID,
app_secret: <string>process.env.APP_SECRET,
};

describe('get Transactions From App', () => {
test('should return the invoice created', async () => {
const id = 'ae06dce6-309c-4f96-9ef3-01b14938e8d7';
const result = await getOneTransactionFromApp(authApp, id);

expect(result).toBeInstanceOf(Object);
});

test('should return an AxiosResponse when the request fails', async () => {
const expectedResult = {
error: 'APP no existe',
};

const authApp: AppAuth = {
app_id: 'test',
app_secret: 'test',
};
const id = 'ae06dce6-309c-4f96-9ef3-01b14938e8d7';
const result = await getOneTransactionFromApp(authApp, id);

expect(result).toEqual(expectedResult);
});
});
45 changes: 45 additions & 0 deletions __test__/merchants/getTransactionsFromApp.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import 'dotenv/config';
import { AppAuth } from '../../src/interfaces';
import { getTransactionsFromApp } from '../../src';

const authApp: AppAuth = {
app_id: <string>process.env.APP_ID,
app_secret: <string>process.env.APP_SECRET,
};

describe('get Transactions From App', () => {
test('should return the invoice created', async () => {
const expectedResult = [
'current_page',
'data',
'first_page_url',
'from',
'last_page',
'last_page_url',
'links',
'next_page_url',
'path',
'per_page',
'prev_page_url',
'to',
'total',
];
const result = await getTransactionsFromApp(authApp);

expect(Object.keys(result)).toEqual(expectedResult);
});

test('should return an AxiosResponse when the request fails', async () => {
const expectedResult = {
error: 'APP no existe',
};

const authApp: AppAuth = {
app_id: 'test',
app_secret: 'test',
};
const result = await getTransactionsFromApp(authApp);

expect(result).toEqual(expectedResult);
});
});
9 changes: 9 additions & 0 deletions __test__/p2p/getEnabledCurrencies.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { getEnabledCurrencies } from '../../src';

describe('get Enabled Currencies', () => {
test('should return an array with the list of available currencies', async () => {
const result = await getEnabledCurrencies();

expect(result).toBeInstanceOf(Array);
});
});
32 changes: 32 additions & 0 deletions __test__/p2p/getOffers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'dotenv/config';
import { login, getOffers } from '../../src';
import { Login, OffersParams } from '../../src/interfaces';

const loginData: Login = {
email: <string>process.env.EMAIL,
password: <string>process.env.PASSWORD,
};
const props: OffersParams = {
coin: 'ETECSA',
min: 1,
max: 50,
type: 'buy'
};

describe('get Offers', () => {
test('should return an object with the data of the offers in an array', async () => {
const { accessToken } = await login(loginData);
const result = await getOffers(accessToken, props);

expect(Object.keys(result)).toContain('data');
});

test('should return an AxiosResponse when the request fails', async () => {
const expectedResult = {
message: 'Unauthenticated.',
};
const result = await getOffers('test', props);

expect(result).toEqual(expectedResult);
});
});
27 changes: 27 additions & 0 deletions __test__/p2p/getOneOffer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'dotenv/config';
import { login, getOneOffer } from '../../src';
import { Login } from '../../src/interfaces';

const loginData: Login = {
email: <string>process.env.EMAIL,
password: <string>process.env.PASSWORD,
};
const id = '9e94e64d-3f4c-4010-9c3d-a855fbf0f04f';

describe('get one offer', () => {
test('should return an object with the data of the offers in an array', async () => {
const { accessToken } = await login(loginData);
const result = await getOneOffer(accessToken, id);

expect(Object.keys(result)).toContain('data');
});

test('should return an AxiosResponse when the request fails', async () => {
const expectedResult = {
message: 'Unauthenticated.',
};
const result = await getOneOffer('test', id);

expect(result).toEqual(expectedResult);
});
});
Loading