mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
WIP pass the failed tests.
This commit is contained in:
@@ -1,21 +1,17 @@
|
||||
import moment from 'moment';
|
||||
import {
|
||||
request,
|
||||
create,
|
||||
expect,
|
||||
login,
|
||||
} from '~/testInit';
|
||||
import ExchangeRate from '../../src/models/ExchangeRate';
|
||||
import {
|
||||
tenantWebsite,
|
||||
tenantFactory,
|
||||
loginRes
|
||||
} from '~/dbInit';
|
||||
|
||||
let loginRes;
|
||||
|
||||
describe.only('route: /exchange_rates/', () => {
|
||||
beforeEach(async () => {
|
||||
loginRes = await login();
|
||||
});
|
||||
afterEach(() => {
|
||||
loginRes = null;
|
||||
});
|
||||
describe('route: /exchange_rates/', () => {
|
||||
describe('POST: `/api/exchange_rates`', () => {
|
||||
it('Should response unauthorized in case the user was not logged in.', async () => {
|
||||
const res = await request()
|
||||
@@ -23,13 +19,14 @@ describe.only('route: /exchange_rates/', () => {
|
||||
.send();
|
||||
|
||||
expect(res.status).equals(401);
|
||||
expect(res.body.message).equals('unauthorized');
|
||||
expect(res.body.message).equals('Unauthorized');
|
||||
});
|
||||
|
||||
it('Should `currency_code` be required.', async () => {
|
||||
const res = await request()
|
||||
.post('/api/exchange_rates')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.set('organization-id', tenantWebsite.organizationId)
|
||||
.send();
|
||||
|
||||
expect(res.status).equals(422);
|
||||
@@ -43,6 +40,7 @@ describe.only('route: /exchange_rates/', () => {
|
||||
const res = await request()
|
||||
.post('/api/exchange_rates')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.set('organization-id', tenantWebsite.organizationId)
|
||||
.send();
|
||||
|
||||
expect(res.status).equals(422);
|
||||
@@ -56,6 +54,7 @@ describe.only('route: /exchange_rates/', () => {
|
||||
const res = await request()
|
||||
.post('/api/exchange_rates')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.set('organization-id', tenantWebsite.organizationId)
|
||||
.send();
|
||||
|
||||
expect(res.status).equals(422);
|
||||
@@ -66,7 +65,7 @@ describe.only('route: /exchange_rates/', () => {
|
||||
});
|
||||
|
||||
it('Should response date and currency code is already exists.', async () => {
|
||||
await create('exchange_rate', {
|
||||
await tenantFactory.create('exchange_rate', {
|
||||
date: '2020-02-02',
|
||||
currency_code: 'USD',
|
||||
exchange_rate: 4.4,
|
||||
@@ -74,6 +73,7 @@ describe.only('route: /exchange_rates/', () => {
|
||||
const res = await request()
|
||||
.post('/api/exchange_rates')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.set('organization-id', tenantWebsite.organizationId)
|
||||
.send({
|
||||
date: '2020-02-02',
|
||||
currency_code: 'USD',
|
||||
@@ -90,6 +90,7 @@ describe.only('route: /exchange_rates/', () => {
|
||||
const res = await request()
|
||||
.post('/api/exchange_rates')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.set('organization-id', tenantWebsite.organizationId)
|
||||
.send({
|
||||
date: '2020-02-02',
|
||||
currency_code: 'USD',
|
||||
@@ -97,7 +98,7 @@ describe.only('route: /exchange_rates/', () => {
|
||||
});
|
||||
expect(res.status).equals(200);
|
||||
|
||||
const foundExchangeRate = await ExchangeRate.query()
|
||||
const foundExchangeRate = await ExchangeRate.tenant().query()
|
||||
.where('currency_code', 'USD');
|
||||
|
||||
expect(foundExchangeRate.length).equals(1);
|
||||
@@ -111,13 +112,14 @@ describe.only('route: /exchange_rates/', () => {
|
||||
|
||||
describe('GET: `/api/exchange_rates', () => {
|
||||
it('Should retrieve all exchange rates with pagination meta.', async () => {
|
||||
await create('exchange_rate');
|
||||
await create('exchange_rate');
|
||||
await create('exchange_rate');
|
||||
await tenantFactory.create('exchange_rate');
|
||||
await tenantFactory.create('exchange_rate');
|
||||
await tenantFactory.create('exchange_rate');
|
||||
|
||||
const res = await request()
|
||||
.get('/api/exchange_rates')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.set('organization-id', tenantWebsite.organizationId)
|
||||
.send();
|
||||
|
||||
expect(res.status).equals(200);
|
||||
@@ -130,6 +132,7 @@ describe.only('route: /exchange_rates/', () => {
|
||||
const res = await request()
|
||||
.post('/api/exchange_rates/100')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.set('organization-id', tenantWebsite.organizationId)
|
||||
.send({
|
||||
date: '2020-02-02',
|
||||
currency_code: 'USD',
|
||||
@@ -143,16 +146,17 @@ describe.only('route: /exchange_rates/', () => {
|
||||
});
|
||||
|
||||
it('Should update exchange rate of the given id on the storage.', async () => {
|
||||
const exRate = await create('exchange_rate');
|
||||
const exRate = await tenantFactory.create('exchange_rate');
|
||||
const res = await request()
|
||||
.post(`/api/exchange_rates/${exRate.id}`)
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.set('organization-id', tenantWebsite.organizationId)
|
||||
.send({
|
||||
exchange_rate: 4.4,
|
||||
});
|
||||
expect(res.status).equals(200);
|
||||
|
||||
const foundExchangeRate = await ExchangeRate.query()
|
||||
const foundExchangeRate = await ExchangeRate.tenant().query()
|
||||
.where('id', exRate.id);
|
||||
|
||||
expect(foundExchangeRate.length).equals(1);
|
||||
@@ -165,7 +169,9 @@ describe.only('route: /exchange_rates/', () => {
|
||||
const res = await request()
|
||||
.delete('/api/exchange_rates/100')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.set('organization-id', tenantWebsite.organizationId)
|
||||
.send();
|
||||
|
||||
expect(res.status).equals(404);
|
||||
expect(res.body.errors).include.something.deep.equals({
|
||||
type: 'EXCHANGE.RATE.NOT.FOUND', code: 200,
|
||||
@@ -173,14 +179,52 @@ describe.only('route: /exchange_rates/', () => {
|
||||
});
|
||||
|
||||
it('Should delete the given exchange rate id from the storage.', async () => {
|
||||
const exRate = await create('exchange_rate');
|
||||
const exRate = await tenantFactory.create('exchange_rate');
|
||||
const res = await request()
|
||||
.delete(`/api/exchange_rates/${exRate.id}`)
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.set('organization-id', tenantWebsite.organizationId)
|
||||
.send();
|
||||
|
||||
const foundRates = await ExchangeRate.query();
|
||||
const foundRates = await ExchangeRate.tenant().query();
|
||||
expect(foundRates.length).equals(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('DELETE: `/api/exchange_rates/bulk`', () => {
|
||||
it('Should response the given exchange rates ids where not found.', async () => {
|
||||
const res = await request()
|
||||
.delete('/api/exchange_rates/bulk')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.set('organization-id', tenantWebsite.organizationId)
|
||||
.query({
|
||||
ids: [12332, 32432],
|
||||
})
|
||||
.send();
|
||||
|
||||
expect(res.status).equals(400);
|
||||
expect(res.body.errors).include.something.deep.equals({
|
||||
type: 'EXCHANGE.RATES.IS.NOT.FOUND', code: 200, ids: [12332, 32432],
|
||||
})
|
||||
});
|
||||
|
||||
it('Should delete the given excahnge rates ids.', async () => {
|
||||
const exRate = await tenantFactory.create('exchange_rate');
|
||||
const exRate2 = await tenantFactory.create('exchange_rate');
|
||||
|
||||
const res = await request()
|
||||
.delete('/api/exchange_rates/bulk')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.set('organization-id', tenantWebsite.organizationId)
|
||||
.query({
|
||||
ids: [exRate.id, exRate2.id],
|
||||
})
|
||||
.send();
|
||||
|
||||
const foundExchangeRate = await ExchangeRate.tenant().query()
|
||||
.whereIn('id', [exRate.id, exRate2.id]);
|
||||
|
||||
expect(foundExchangeRate.length).equals(0);
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user