WIP pass the failed tests.

This commit is contained in:
Ahmed Bouhuolia
2020-05-17 07:08:12 +02:00
parent 00de156c9f
commit 10f636d2bc
77 changed files with 2164 additions and 1403 deletions

View File

@@ -1,36 +1,31 @@
import {
request,
create,
expect,
login,
} from '~/testInit';
import Currency from '@/models/Currency';
import {
tenantWebsite,
tenantFactory,
loginRes
} from '~/dbInit';
let loginRes;
describe('route: /currencies/', () => {
beforeEach(async () => {
loginRes = await login();
});
afterEach(() => {
loginRes = null;
});
describe('POST: `/api/currencies`', () => {
it('Should response unauthorized in case user was not logged in.', async () => {
const res = await request()
.post('/api/currencies')
.send();
expect(res.status).equals(401);
expect(res.body.message).equals('unauthorized');
expect(res.body.message).equals('Unauthorized');
});
it('Should `currency_name` be required.', async () => {
const res = await request()
.post('/api/currencies')
.set('x-access-token', loginRes.body.token)
.set('organization-id', tenantWebsite.organizationId)
.send();
expect(res.status).equals(422);
@@ -44,6 +39,7 @@ describe('route: /currencies/', () => {
const res = await request()
.post('/api/currencies')
.set('x-access-token', loginRes.body.token)
.set('organization-id', tenantWebsite.organizationId)
.send();
expect(res.status).equals(422);
@@ -54,11 +50,12 @@ describe('route: /currencies/', () => {
});
it('Should response currency code is duplicated.', async () => {
create('currency', { currency_code: 'USD' });
tenantFactory.create('currency', { currency_code: 'USD' });
const res = await request()
.post('/api/currencies')
.set('x-access-token', loginRes.body.token)
.set('organization-id', tenantWebsite.organizationId)
.send({
currency_code: 'USD',
currency_name: 'Dollar',
@@ -74,12 +71,13 @@ describe('route: /currencies/', () => {
const res = await request()
.post('/api/currencies')
.set('x-access-token', loginRes.body.token)
.set('organization-id', tenantWebsite.organizationId)
.send({
currency_code: 'USD',
currency_name: 'Dollar',
});
const foundCurrency = await Currency.query().where('currency_code', 'USD');
const foundCurrency = await Currency.tenant().query().where('currency_code', 'USD');
expect(foundCurrency.length).equals(1);
expect(foundCurrency[0].currencyCode).equals('USD');
@@ -90,6 +88,7 @@ describe('route: /currencies/', () => {
const res = await request()
.post('/api/currencies')
.set('x-access-token', loginRes.body.token)
.set('organization-id', tenantWebsite.organizationId)
.send({
currency_code: 'USD',
currency_name: 'Dollar',
@@ -100,27 +99,28 @@ describe('route: /currencies/', () => {
});
describe('DELETE: `/api/currencies/:currency_code`', () => {
it('Should delete the given currency code from the storage.', async () => {
const currency = await create('currency');
const currency = await tenantFactory.create('currency');
const res = await request()
.delete(`/api/currencies/${currency.currencyCode}`)
.set('x-access-token', loginRes.body.token)
.set('organization-id', tenantWebsite.organizationId)
.send();
expect(res.status).equals(200);
const foundCurrency = await Currency.query().where('currency_code', 'USD');
const foundCurrency = await Currency.tenant().query().where('currency_code', 'USD');
expect(foundCurrency.length).equals(0);
});
});
describe('POST: `/api/currencies/:id`', () => {
it('Should `currency_name` be required.', async () => {
const currency = await create('currency');
const currency = await tenantFactory.create('currency');
const res = await request()
.post(`/api/currencies/${currency.code}`)
.set('x-access-token', loginRes.body.token)
.set('organization-id', tenantWebsite.organizationId)
.send();
expect(res.status).equals(422);
@@ -131,10 +131,11 @@ describe('route: /currencies/', () => {
});
it('Should `currency_code` be required.', async () => {
const currency = await create('currency');
const currency = await tenantFactory.create('currency');
const res = await request()
.post(`/api/currencies/${currency.code}`)
.set('x-access-token', loginRes.body.token)
.set('organization-id', tenantWebsite.organizationId)
.send();
expect(res.status).equals(422);
@@ -145,12 +146,13 @@ describe('route: /currencies/', () => {
});
it('Should response currency code is duplicated.', async () => {
const currency1 = await create('currency');
const currency2 = await create('currency');
const currency1 = await tenantFactory.create('currency');
const currency2 = await tenantFactory.create('currency');
const res = await request()
.post(`/api/currencies/${currency2.id}`)
.set('x-access-token', loginRes.body.token)
.set('organization-id', tenantWebsite.organizationId)
.send({
currency_code: currency1.currencyCode,
currency_name: 'Dollar',
@@ -163,18 +165,19 @@ describe('route: /currencies/', () => {
});
it('Should update currency details of the given currency on the storage.', async () => {
const currency1 = await create('currency');
const currency2 = await create('currency');
const currency1 = await tenantFactory.create('currency');
const currency2 = await tenantFactory.create('currency');
const res = await request()
.post(`/api/currencies/${currency2.id}`)
.set('x-access-token', loginRes.body.token)
.set('organization-id', tenantWebsite.organizationId)
.send({
currency_code: 'ABC',
currency_name: 'Name',
});
const foundCurrency = await Currency.query().where('currency_code', 'ABC');
const foundCurrency = await Currency.tenant().query().where('currency_code', 'ABC');
expect(foundCurrency.length).equals(1);
expect(foundCurrency[0].currencyCode).equals('ABC');