Skip to content

Commit

Permalink
feat: coverage on successful or erroneous requests
Browse files Browse the repository at this point in the history
  • Loading branch information
caioagiani committed Feb 17, 2021
1 parent 2a4d9b1 commit 98c730c
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 143 deletions.
2 changes: 0 additions & 2 deletions .env.example

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.env
*.lock
coverage
9 changes: 9 additions & 0 deletions __tests__/balance.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const mobizon = require('./config');

describe('Mobizon balance', () => {
it('should receive the account balance', async () => {
const response = await mobizon.getBalance();

expect(response.code).toBe(0);
});
});
9 changes: 9 additions & 0 deletions __tests__/config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const mobizon = require('../../src/index');

mobizon.setConfig({
apiServer: 'https://api.mobizon.com.br',
apiKey: process.env.API_KEY,
format: 'json',
});

module.exports = mobizon;
67 changes: 67 additions & 0 deletions __tests__/shortlink.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const mobizon = require('./config');

describe('Mobizon short methods', () => {
const responseValues = [];

it('should create short link', async () => {
const response = await mobizon.shortCreate({
fullLink: 'https://mobizon.com.br',
status: 1,
expirationDate: '',
comment: 'Created short link.',
});

responseValues.push(response.data);

expect(response.code).toBe(0);
});

it('should throw error when creating short link', async () => {
const response = await mobizon.shortCreate({});

expect(response.code).not.toBe(0);
});

it('should get short link', async () => {
const response = await mobizon.shortGet([responseValues[0].code]);

expect(response.code).toBe(0);
});

it('should throw error when getting short link', async () => {
const response = await mobizon.shortGet([]);

expect(response.code).not.toBe(0);
});

it('should update short link', async () => {
const response = await mobizon.shortUpdate({
id: responseValues[0].id,
data: {
status: 0,
expirationDate: '',
comment: 'Updated short link.',
},
});

expect(response.code).toBe(0);
});

it('should throw an error when updating a short link', async () => {
const response = await mobizon.shortUpdate({});

expect(response.code).not.toBe(0);
});

it('should delete short link', async () => {
const response = await mobizon.shortDelete([responseValues[0].id]);

expect(response.code).toBe(0);
});

it('should throw an error when deleting a short link', async () => {
const response = await mobizon.shortDelete();

expect(response.code).not.toBe(0);
});
});
53 changes: 53 additions & 0 deletions __tests__/sms.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const mobizon = require('./config');

describe('Mobizon sms methods', () => {
const recipient = process.env.NUMBER;
const responseValues = [];

it('should send a sms', async () => {
const response = await mobizon.sendSms({
recipient,
from: '',
text: 'Sent sms.',
});

responseValues.push(response.data);

expect(response.code).toBe(0);
});

it('should throw error when sending sms', async () => {
const response = await mobizon.sendSms({});

expect(response.code).not.toBe(0);
});

it('should list the sms sent by id', async () => {
const response = await mobizon.getSms(responseValues[0].messageId);

expect(response.code).toBe(0);
});

it('should throw error when listing sms by id', async () => {
const response = await mobizon.getSms([]);

expect(response.code).not.toBe(0);
});

it('should list the all sms sent', async () => {
const response = await mobizon.listSms({
criteria: {
from: '',
},
pagination: {
currentPage: '2',
pageSize: '50',
},
sort: {
campaignId: 'ASC',
},
});

expect(response.code).toBe(0);
});
});
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ module.exports = {
coverageDirectory: 'coverage',
coverageProvider: 'v8',
testEnvironment: 'node',
testMatch: ['**/tests/**/*.test.js?(x)'],
testMatch: ['**/__tests__/**/*.test.js?(x)'],
};
140 changes: 0 additions & 140 deletions tests/mobizon.test.js

This file was deleted.

0 comments on commit 98c730c

Please sign in to comment.