mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 15:20:34 +00:00
fix api global options.
This commit is contained in:
@@ -608,7 +608,7 @@ describe('routes: `/accounting`', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe.only('route: POST `accounting/manual-journals/:id/publish`', () => {
|
||||
describe('route: POST `accounting/manual-journals/:id/publish`', () => {
|
||||
|
||||
it('Should response not found in case the manual journal id was not exists.', async () => {
|
||||
const manualJournal = await create('manual_journal');
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
import knex from '@/database/knex';
|
||||
import {
|
||||
request,
|
||||
expect,
|
||||
create,
|
||||
make,
|
||||
login,
|
||||
} from '~/testInit';
|
||||
import Option from '@/models/Option';
|
||||
|
||||
let loginRes;
|
||||
|
||||
describe('routes: `/options`', () => {
|
||||
beforeEach(async () => {
|
||||
loginRes = await login();
|
||||
});
|
||||
afterEach(() => {
|
||||
loginRes = null;
|
||||
});
|
||||
|
||||
describe('POST: `/options/`', () => {
|
||||
it('Should response unauthorized if the user was not logged in.', async () => {
|
||||
const res = await request()
|
||||
.post('/api/options')
|
||||
.send();
|
||||
|
||||
expect(res.status).equals(401);
|
||||
expect(res.body.message).equals('unauthorized');
|
||||
});
|
||||
|
||||
it('Should response the options key and group is not defined.', async () => {
|
||||
const res = await request()
|
||||
.post('/api/options')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send({
|
||||
options: [
|
||||
{
|
||||
key: 'key',
|
||||
value: 'hello world',
|
||||
group: 'group',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(res.status).equals(400);
|
||||
expect(res.body.errors).include.something.that.deep.equals({
|
||||
type: 'OPTIONS.KEY.NOT.DEFINED',
|
||||
code: 200,
|
||||
keys: [
|
||||
{ key: 'key', group: 'group' },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it('Should save options to the storage.', async () => {
|
||||
const res = await request()
|
||||
.post('/api/options')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send({
|
||||
options: [{
|
||||
key: 'name',
|
||||
group: 'organization',
|
||||
value: 'hello world',
|
||||
}],
|
||||
});
|
||||
expect(res.status).equals(200);
|
||||
|
||||
const storedOptions = await Option.query()
|
||||
.where('group', 'organization')
|
||||
.where('key', 'name');
|
||||
|
||||
expect(storedOptions.metadata.length).equals(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET: `/options`', () => {
|
||||
it('Should response unauthorized if the user was not unauthorized.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/options')
|
||||
.query({
|
||||
group: 'organization',
|
||||
})
|
||||
.send();
|
||||
|
||||
expect(res.status).equals(401);
|
||||
expect(res.body.message).equals('unauthorized');
|
||||
});
|
||||
|
||||
it('Should retrieve options the associated to the given group.', async () => {
|
||||
await create('option', { group: 'organization', key: 'name' });
|
||||
await create('option', { group: 'organization', key: 'base_currency' });
|
||||
|
||||
const res = await request()
|
||||
.get('/api/options')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.query({
|
||||
group: 'organization',
|
||||
})
|
||||
.send();
|
||||
|
||||
expect(res.status).equals(200);
|
||||
expect(res.body.options).is.an('array');
|
||||
expect(res.body.options.length).equals(2);
|
||||
});
|
||||
|
||||
it('Should retrieve options that associated to the given key.', async () => {
|
||||
await create('option', { group: 'organization', key: 'base_currency' });
|
||||
await create('option', { group: 'organization', key: 'name' });
|
||||
|
||||
const res = await request()
|
||||
.get('/api/options')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.query({
|
||||
key: 'name',
|
||||
})
|
||||
.send();
|
||||
|
||||
expect(res.status).equals(200);
|
||||
expect(res.body.options).is.an('array');
|
||||
expect(res.body.options.length).equals(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user