feat: Publish manual journal api.

This commit is contained in:
Ahmed Bouhuolia
2020-04-08 20:18:46 +02:00
parent 4920d5f419
commit b1d924c3cc
3 changed files with 125 additions and 6 deletions

View File

@@ -560,7 +560,7 @@ describe('routes: `/accounting`', () => {
});
});
describe.only('route: GET `accounting/manual-journals/:id`', () => {
describe('route: GET `accounting/manual-journals/:id`', () => {
it('Should response not found in case manual transaction id was not exists.', async () => {
const res = await request()
.delete('/api/accounting/manual-journals/100')
@@ -608,6 +608,64 @@ describe('routes: `/accounting`', () => {
});
});
describe.only('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');
const res = await request()
.post('/api/accounting/manual-journals/123/publish')
.set('x-access-token', loginRes.body.token)
.send();
expect(res.status).equals(404);
expect(res.body.errors).include.something.that.deep.equals({
type: 'MANUAL.JOURNAL.NOT.FOUND', code: 100,
});
});
it('Should response published ready.', async () => {
const manualJournal = await create('manual_journal', { status: 0 });
const res = await request()
.post(`/api/accounting/manual-journals/${manualJournal.id}/publish`)
.set('x-access-token', loginRes.body.token)
.send();
expect(res.status).equals(400);
expect(res.body.errors).include.something.that.deep.equals({
type: 'MANUAL.JOURNAL.PUBLISHED.ALREADY', code: 200,
});
});
it('Should update all accounts transactions to not draft.', async () => {
const manualJournal = await create('manual_journal');
const transaction = await create('account_transaction', {
reference_type: 'Journal',
reference_id: manualJournal.id,
draft: 1,
});
const transaction2 = await create('account_transaction', {
reference_type: 'Journal',
reference_id: manualJournal.id,
draft: 1,
});
const res = await request()
.post(`/api/accounting/manual-journals/${manualJournal.id}/publish`)
.set('x-access-token', loginRes.body.token)
.send();
const foundTransactions = await AccountTransaction.query()
.whereIn('id', [transaction.id, transaction2.id]);
expect(foundTransactions[0].draft).equals(0);
expect(foundTransactions[1].draft).equals(0);
});
it('Should increment/decrement accounts balance.', () => {
});
});
describe('route: `/accounting/quick-journal-entries`', async () => {
it('Shoud `credit_account_id` be required', () => {