mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 22:00:31 +00:00
WIP server side.
This commit is contained in:
31
server/tests/collection/NestedSet.test.js
Normal file
31
server/tests/collection/NestedSet.test.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import { expect } from '~/testInit';
|
||||
import NestedSet from '@/collection/NestedSet';
|
||||
|
||||
describe('NestedSet', () => {
|
||||
it('Should link parent and children nodes.', () => {
|
||||
const flattenArray = [
|
||||
{
|
||||
id: 1,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
parent_id: 1,
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
parent_id: 1,
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
parent_id: 3,
|
||||
},
|
||||
];
|
||||
|
||||
const collection = new NestedSet(flattenArray);
|
||||
|
||||
expect(collection[0].id).equals(1);
|
||||
expect(collection[0].children[0].id).equals(2);
|
||||
expect(collection[0].children[1].id).equals(3);
|
||||
expect(collection[0].children[1].children[0].id).equals(4);
|
||||
});
|
||||
});
|
||||
112
server/tests/lib/Metable/MetableCollection.test.js
Normal file
112
server/tests/lib/Metable/MetableCollection.test.js
Normal file
@@ -0,0 +1,112 @@
|
||||
import Option from '@/models/Option';
|
||||
import MetadataCollection from '@/lib/Metable/MetableCollection';
|
||||
import { create, expect } from '~/testInit';
|
||||
|
||||
describe('MetableCollection', () => {
|
||||
describe('findMeta', () => {
|
||||
it('Should retrieve the found meta object.', async () => {
|
||||
const option = await create('option');
|
||||
const options = await Option.query();
|
||||
const metadataCollection = MetadataCollection.from(options);
|
||||
|
||||
const foundMeta = metadataCollection.findMeta(option.key);
|
||||
expect(foundMeta).to.be.an('object');
|
||||
});
|
||||
});
|
||||
|
||||
describe('allMetadata', () => {
|
||||
it('Should retrieve all exists metadata entries.', async () => {
|
||||
const option = await create('option');
|
||||
const options = await Option.query();
|
||||
const metadataCollection = MetadataCollection.from(options);
|
||||
|
||||
const foundMetadata = metadataCollection.allMetadata();
|
||||
|
||||
expect(foundMetadata.length).equals(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getMeta', () => {
|
||||
it('Should retrieve the found meta value.', async () => {
|
||||
const option = await create('option');
|
||||
const options = await Option.query();
|
||||
const metadataCollection = MetadataCollection.from(options);
|
||||
|
||||
const foundMeta = metadataCollection.getMeta(option.key);
|
||||
|
||||
expect(foundMeta).equals(option.value);
|
||||
});
|
||||
|
||||
it('Should retrieve the default meta value in case the meta key was not exist.', async () => {
|
||||
const option = await create('option');
|
||||
const options = await Option.query();
|
||||
const metadataCollection = MetadataCollection.from(options);
|
||||
|
||||
const foundMeta = metadataCollection.getMeta('not-found', true);
|
||||
|
||||
expect(foundMeta).equals(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('setMeta', () => {
|
||||
it('Should sets the meta value to the stack.', async () => {
|
||||
const metadataCollection = new MetadataCollection();
|
||||
metadataCollection.setMeta('key', 'value');
|
||||
|
||||
expect(metadataCollection.metadata.length).equals(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('removeAllMeta()', () => {
|
||||
it('Should remove all metadata from the stack.', async () => {
|
||||
const metadataCollection = new MetadataCollection();
|
||||
metadataCollection.setMeta('key', 'value');
|
||||
metadataCollection.setMeta('key2', 'value2');
|
||||
|
||||
metadataCollection.removeAllMeta();
|
||||
|
||||
expect(metadataCollection.metadata.length).equals(2);
|
||||
expect(metadataCollection.allMetadata().length).equals(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('saveMeta', () => {
|
||||
it('Should save inserted new metadata.', async () => {
|
||||
const metadataCollection = new MetadataCollection();
|
||||
metadataCollection.setMeta('key', 'value');
|
||||
metadataCollection.setModel(Option);
|
||||
|
||||
await metadataCollection.saveMeta();
|
||||
|
||||
const storedMetadata = await Option.query();
|
||||
expect(storedMetadata.length).equals(1);
|
||||
});
|
||||
|
||||
it('Should save updated the exist metadata.', async () => {
|
||||
const option = await create('option');
|
||||
const metadataCollection = new MetadataCollection();
|
||||
metadataCollection.setMeta(option.key, 'value');
|
||||
metadataCollection.setModel(Option);
|
||||
|
||||
await metadataCollection.saveMeta();
|
||||
|
||||
const storedMetadata = Option.query().where('key', option.key).first();
|
||||
expect(storedMetadata.value).equals('value');
|
||||
});
|
||||
|
||||
it('Should delete the removed metadata from storage.', async () => {
|
||||
const option = await create('option');
|
||||
|
||||
const options = await Option.query();
|
||||
const metadataCollection = MetadataCollection.from(options);
|
||||
metadataCollection.setModel(Option);
|
||||
metadataCollection.removeMeta(option.key);
|
||||
|
||||
expect(metadataCollection.metadata.length).equals(1);
|
||||
await metadataCollection.saveMeta();
|
||||
|
||||
const storedMetadata = await Option.query();
|
||||
expect(storedMetadata.length).equals(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
5
server/tests/lib/Metable/MetableModel.test.js
Normal file
5
server/tests/lib/Metable/MetableModel.test.js
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
|
||||
describe('MetableModel', () => {
|
||||
|
||||
});
|
||||
@@ -1,6 +1,5 @@
|
||||
import { create, expect } from '~/testInit';
|
||||
import Account from '@/models/Account';
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
import AccountType from '@/models/AccountType';
|
||||
|
||||
describe('Model: Account', () => {
|
||||
@@ -8,9 +7,32 @@ describe('Model: Account', () => {
|
||||
const accountType = await create('account_type');
|
||||
const account = await create('account', { account_type_id: accountType.id });
|
||||
|
||||
const accountModel = await Account.where('id', account.id).fetch();
|
||||
const accountTypeModel = await accountModel.type().fetch();
|
||||
const accountModel = await Account.query()
|
||||
.where('id', account.id)
|
||||
.withGraphFetched('type')
|
||||
.first();
|
||||
|
||||
expect(accountTypeModel.attributes.id).equals(account.id);
|
||||
expect(accountModel.type.id).equals(accountType.id);
|
||||
});
|
||||
|
||||
it('Should account model has one balance model that associated to the account model.', async () => {
|
||||
const accountBalance = await create('account_balance');
|
||||
|
||||
const accountModel = await Account.query()
|
||||
.where('id', accountBalance.accountId)
|
||||
.withGraphFetched('balance')
|
||||
.first();
|
||||
|
||||
expect(accountModel.balance.amount).equals(accountBalance.amount);
|
||||
});
|
||||
|
||||
it('Should account model has many transactions models that associated to the account model.', async () => {
|
||||
const account = await create('account');
|
||||
const accountTransaction = await create('account_transaction', { account_id: account.id });
|
||||
|
||||
const accountModel = await Account.query().where('id', account.id).first();
|
||||
const transactionsModels = await accountModel.$relatedQuery('transactions');
|
||||
|
||||
expect(transactionsModels.length).equals(1);
|
||||
});
|
||||
});
|
||||
|
||||
0
server/tests/models/AccountBalance.test.js
Normal file
0
server/tests/models/AccountBalance.test.js
Normal file
@@ -8,8 +8,8 @@ describe('Model: AccountType', () => {
|
||||
await create('account', { account_type_id: accountType.id });
|
||||
await create('account', { account_type_id: accountType.id });
|
||||
|
||||
const accountTypeModel = await AccountType.where('id', accountType.id).fetch();
|
||||
const typeAccounts = await accountTypeModel.accounts().fetch();
|
||||
const accountTypeModel = await AccountType.query().where('id', accountType.id).first();
|
||||
const typeAccounts = await accountTypeModel.$relatedQuery('accounts');
|
||||
|
||||
expect(typeAccounts.length).equals(2);
|
||||
});
|
||||
|
||||
34
server/tests/models/Expense.test.js
Normal file
34
server/tests/models/Expense.test.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import { create, expect } from '~/testInit';
|
||||
import Expense from '@/models/Expense';
|
||||
import factory from '../../src/database/factories';
|
||||
|
||||
describe('Model: Expense', () => {
|
||||
describe('relations', () => {
|
||||
it('Expense model may belongs to associated payment account.', async () => {
|
||||
const expense = await factory.create('expense');
|
||||
|
||||
const expenseModel = await Expense.query().findById(expense.id);
|
||||
const paymentAccountModel = await expenseModel.$relatedQuery('paymentAccount');
|
||||
|
||||
expect(paymentAccountModel.id).equals(expense.paymentAccountId);
|
||||
});
|
||||
|
||||
it('Expense model may belongs to associated expense account.', async () => {
|
||||
const expense = await factory.create('expense');
|
||||
|
||||
const expenseModel = await Expense.query().findById(expense.id);
|
||||
const expenseAccountModel = await expenseModel.$relatedQuery('expenseAccount');
|
||||
|
||||
expect(expenseAccountModel.id).equals(expense.expenseAccountId);
|
||||
});
|
||||
|
||||
it('Expense model may belongs to associated user model.', async () => {
|
||||
const expense = await factory.create('expense');
|
||||
|
||||
const expenseModel = await Expense.query().findById(expense.id);
|
||||
const expenseUserModel = await expenseModel.$relatedQuery('user');
|
||||
|
||||
expect(expenseUserModel.id).equals(expense.userId);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -9,8 +9,8 @@ describe('Model: Item', () => {
|
||||
const category = await create('item_category');
|
||||
const item = await create('item', { category_id: category.id });
|
||||
|
||||
const itemModel = await Item.where('id', item.id).fetch();
|
||||
const itemCategoryModel = await itemModel.category().fetch();
|
||||
const itemModel = await Item.query().where('id', item.id);
|
||||
const itemCategoryModel = await itemModel.$relatedQuery('category');
|
||||
|
||||
expect(itemCategoryModel.attributes.id).equals(category.id);
|
||||
});
|
||||
@@ -20,8 +20,8 @@ describe('Model: Item', () => {
|
||||
await create('item_metadata', { item_id: item.id });
|
||||
await create('item_metadata', { item_id: item.id });
|
||||
|
||||
const itemModel = await Item.where('id', item.id).fetch();
|
||||
const itemMetadataCollection = await itemModel.metadata().fetch();
|
||||
const itemModel = await Item.query().where('id', item.id);
|
||||
const itemMetadataCollection = await itemModel.$relatedQuery('metadata');
|
||||
|
||||
expect(itemMetadataCollection.length).equals(2);
|
||||
});
|
||||
|
||||
13
server/tests/models/Option.test.js
Normal file
13
server/tests/models/Option.test.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import { create, expect } from '~/testInit';
|
||||
import Option from '@/models/Option';
|
||||
import MetableCollection from '@/lib/Metable/MetableCollection';
|
||||
|
||||
describe('Model: Option', () => {
|
||||
it('Should result collection be instance of `MetableCollection` class.', async () => {
|
||||
await create('option');
|
||||
await create('option');
|
||||
const options = await Option.query();
|
||||
|
||||
expect(options).to.be.an.instanceof(MetableCollection);
|
||||
});
|
||||
});
|
||||
@@ -6,10 +6,10 @@ import '@/models/ResourceField';
|
||||
describe('Model: Resource', () => {
|
||||
it('Resource model may has many associated views.', async () => {
|
||||
const view = await create('view');
|
||||
await create('view', { resource_id: view.resource_id });
|
||||
await create('view', { resource_id: view.resourceId });
|
||||
|
||||
const resourceModel = await Resource.where('id', view.resource_id).fetch();
|
||||
const resourceViews = await resourceModel.views().fetch();
|
||||
const resourceModel = await Resource.query().findById(view.resourceId);
|
||||
const resourceViews = await resourceModel.$relatedQuery('views');
|
||||
|
||||
expect(resourceViews).to.have.lengthOf(2);
|
||||
});
|
||||
@@ -17,8 +17,8 @@ describe('Model: Resource', () => {
|
||||
it('Resource model may has many fields.', async () => {
|
||||
const resourceField = await create('resource_field');
|
||||
|
||||
const resourceModel = await Resource.where('id', resourceField.resource_id).fetch();
|
||||
const resourceFields = await resourceModel.fields().fetch();
|
||||
const resourceModel = await Resource.query().findById(resourceField.resourceId);
|
||||
const resourceFields = await resourceModel.$relatedQuery('fields');
|
||||
|
||||
expect(resourceFields).to.have.lengthOf(1);
|
||||
});
|
||||
|
||||
@@ -6,10 +6,10 @@ import '@/models/Resource';
|
||||
describe('Model: Role', () => {
|
||||
it('Role model may has many associated users', async () => {
|
||||
const userHasRole = await create('user_has_role');
|
||||
await create('user_has_role', { role_id: userHasRole.role_id });
|
||||
await create('user_has_role', { role_id: userHasRole.roleId });
|
||||
|
||||
const roleModel = await Role.where('id', userHasRole.role_id).fetch();
|
||||
const roleUsers = await roleModel.users().fetch();
|
||||
const roleModel = await Role.query().findById(userHasRole.roleId);
|
||||
const roleUsers = await roleModel.$relatedQuery('users');
|
||||
|
||||
expect(roleUsers).to.have.lengthOf(2);
|
||||
});
|
||||
@@ -17,8 +17,8 @@ describe('Model: Role', () => {
|
||||
it('Role model may has many associated permissions.', async () => {
|
||||
const roleHasPermissions = await create('role_has_permission');
|
||||
|
||||
const roleModel = await Role.where('id', roleHasPermissions.role_id).fetch();
|
||||
const rolePermissions = await roleModel.permissions().fetch();
|
||||
const roleModel = await Role.query().findById(roleHasPermissions.roleId);
|
||||
const rolePermissions = await roleModel.$relatedQuery('permissions');
|
||||
|
||||
expect(rolePermissions).to.have.lengthOf(1);
|
||||
});
|
||||
@@ -26,8 +26,8 @@ describe('Model: Role', () => {
|
||||
it('Role model may has many associated resources that has some or all permissions.', async () => {
|
||||
const roleHasPermissions = await create('role_has_permission');
|
||||
|
||||
const roleModel = await Role.where('id', roleHasPermissions.role_id).fetch();
|
||||
const roleResources = await roleModel.resources().fetch();
|
||||
const roleModel = await Role.query().findById(roleHasPermissions.roleId);
|
||||
const roleResources = await roleModel.$relatedQuery('resources');
|
||||
|
||||
expect(roleResources).to.have.lengthOf(1);
|
||||
});
|
||||
|
||||
@@ -8,10 +8,10 @@ describe('Model: User', () => {
|
||||
const userHasRole = await create('user_has_role');
|
||||
await create('user_has_role', { user_id: userHasRole.user_id });
|
||||
|
||||
const userModel = await User.where('id', userHasRole.user_id).fetch();
|
||||
const userRoles = await userModel.roles().fetch();
|
||||
const userModel = await User.query().where('id', userHasRole.userId).first();
|
||||
const userRoles = await userModel.$relatedQuery('roles');
|
||||
|
||||
expect(userRoles).to.have.lengthOf(2);
|
||||
expect(userRoles).to.have.lengthOf(1);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
159
server/tests/routes/accounting.test.js
Normal file
159
server/tests/routes/accounting.test.js
Normal file
@@ -0,0 +1,159 @@
|
||||
import { request, expect, create, login } from '~/testInit';
|
||||
|
||||
let loginRes;
|
||||
|
||||
describe('routes: /accounting', () => {
|
||||
beforeEach(async () => {
|
||||
loginRes = await login();
|
||||
});
|
||||
afterEach(() => {
|
||||
loginRes = null;
|
||||
});
|
||||
|
||||
describe('route: `/accounting/make-journal-entries`', async () => {
|
||||
it('Should sumation of credit or debit does not equal zero.', async () => {
|
||||
const account = await create('account');
|
||||
const res = await request()
|
||||
.post('/api/accounting/make-journal-entries')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send({
|
||||
date: new Date().toISOString(),
|
||||
reference: 'ASC',
|
||||
entries: [
|
||||
{
|
||||
credit: 0,
|
||||
debit: 0,
|
||||
account_id: account.id,
|
||||
},
|
||||
{
|
||||
credit: 0,
|
||||
debit: 0,
|
||||
account_id: account.id,
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(res.status).equals(400);
|
||||
expect(res.body.errors).include.something.that.deep.equal({
|
||||
type: 'CREDIT.DEBIT.SUMATION.SHOULD.NOT.EQUAL.ZERO',
|
||||
code: 400,
|
||||
});
|
||||
});
|
||||
|
||||
it('Should all credit entries equal debit.', async () => {
|
||||
const account = await create('account');
|
||||
const res = await request()
|
||||
.post('/api/accounting/make-journal-entries')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send({
|
||||
date: new Date().toISOString(),
|
||||
reference: 'ASC',
|
||||
entries: [
|
||||
{
|
||||
credit: 1000,
|
||||
debit: 0,
|
||||
account_id: account.id,
|
||||
},
|
||||
{
|
||||
credit: 0,
|
||||
debit: 500,
|
||||
account_id: account.id,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(res.status).equals(400);
|
||||
expect(res.body.errors).include.something.that.deep.equal({
|
||||
type: 'CREDIT.DEBIT.NOT.EQUALS',
|
||||
code: 100,
|
||||
});
|
||||
});
|
||||
|
||||
it('Should journal reference be not exists.', async () => {
|
||||
const manualJournal = await create('manual_journal');
|
||||
const account = await create('account');
|
||||
|
||||
const res = await request()
|
||||
.post('/api/accounting/make-journal-entries')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send({
|
||||
date: new Date().toISOString(),
|
||||
reference: manualJournal.reference,
|
||||
entries: [
|
||||
{
|
||||
credit: 1000,
|
||||
debit: 0,
|
||||
account_id: account.id,
|
||||
},
|
||||
{
|
||||
credit: 0,
|
||||
debit: 1000,
|
||||
account_id: account.id,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(res.status).equals(400);
|
||||
expect(res.body.errors).include.something.that.deep.equal({
|
||||
type: 'REFERENCE.ALREADY.EXISTS',
|
||||
code: 300,
|
||||
});
|
||||
});
|
||||
|
||||
it('Should response error in case account id not exists.', async () => {
|
||||
const res = await request()
|
||||
.post('/api/accounting/make-journal-entries')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send({
|
||||
date: new Date().toISOString(),
|
||||
reference: '1000',
|
||||
entries: [
|
||||
{
|
||||
credit: 1000,
|
||||
debit: 0,
|
||||
account_id: 12,
|
||||
},
|
||||
{
|
||||
credit: 0,
|
||||
debit: 1000,
|
||||
account_id: 12,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(res.status).equals(400);
|
||||
expect(res.body.errors).include.something.that.deep.equal({
|
||||
type: 'ACCOUNTS.IDS.NOT.FOUND',
|
||||
code: 200,
|
||||
});
|
||||
});
|
||||
|
||||
it('Should store all journal entries to the storage.', async () => {
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('route: `/accounting/quick-journal-entries`', async () => {
|
||||
it('Shoud `credit_account_id` be required', () => {
|
||||
|
||||
});
|
||||
it('Should `debit_account_id` be required.', () => {
|
||||
|
||||
});
|
||||
|
||||
it('Should `amount` be required.', () => {
|
||||
|
||||
});
|
||||
|
||||
it('Should credit account id be exists.', () => {
|
||||
|
||||
});
|
||||
|
||||
it('Should debit account id be exists.', () => {
|
||||
|
||||
});
|
||||
|
||||
it('Should store the quick journal entry to the storage.', () => {
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,101 +1,76 @@
|
||||
import { request, expect, create } from '~/testInit';
|
||||
import { request, expect, create, login } from '~/testInit';
|
||||
import knex from '@/database/knex';
|
||||
import Account from '@/models/Account';
|
||||
|
||||
let loginRes;
|
||||
|
||||
describe('routes: /accounts/', () => {
|
||||
beforeEach(async () => {
|
||||
loginRes = await login();
|
||||
});
|
||||
afterEach(() => {
|
||||
loginRes = null;
|
||||
});
|
||||
describe('POST `/accounts`', () => {
|
||||
it('Should `name` be required.', async () => {
|
||||
const res = await request().post('/api/accounts').send();
|
||||
const res = await request()
|
||||
.post('/api/accounts')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
expect(res.status).equals(422);
|
||||
expect(res.body.code).equals('validation_error');
|
||||
});
|
||||
|
||||
it('Should `account_type_id` be required.', async () => {
|
||||
const res = await request().post('/api/accounts').send();
|
||||
const res = await request()
|
||||
.post('/api/accounts')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
expect(res.status).equals(422);
|
||||
expect(res.body.code).equals('validation_error');
|
||||
});
|
||||
|
||||
it('Should max length of `code` be limited.', async () => {
|
||||
const res = await request().post('/api/accounts').send();
|
||||
const res = await request()
|
||||
.post('/api/accounts')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
expect(res.status).equals(422);
|
||||
expect(res.body.code).equals('validation_error');
|
||||
});
|
||||
|
||||
it('Should response type not found in case `account_type_id` was not exist.', async () => {
|
||||
const res = await request().post('/api/accounts').send();
|
||||
|
||||
expect(res.status).equals(422);
|
||||
});
|
||||
|
||||
it('Should account code be unique in the storage.', async () => {
|
||||
const account = await create('account');
|
||||
const res = await request().post('/api/accounts').send({
|
||||
...account,
|
||||
});
|
||||
const res = await request()
|
||||
.post('/api/accounts')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send({
|
||||
name: 'Account Name',
|
||||
description: account.description,
|
||||
account_type_id: 22, // not found.
|
||||
code: 123,
|
||||
});
|
||||
|
||||
expect(res.status).equals(400);
|
||||
expect(res.body.errors).include.something.that.deep.equals({
|
||||
type: 'PARENT_CATEGORY_NOT_FOUND', code: 100,
|
||||
type: 'NOT_EXIST_ACCOUNT_TYPE', code: 200,
|
||||
});
|
||||
});
|
||||
|
||||
it('Should response success with correct data form.', async () => {
|
||||
const account = await create('account');
|
||||
const res = await request().post('/api/accounts').send({
|
||||
name: 'Name',
|
||||
description: 'description here',
|
||||
account_type_id: account.account_type_id,
|
||||
parent_account_id: account.id,
|
||||
});
|
||||
|
||||
expect(res.status).equals(200);
|
||||
});
|
||||
|
||||
it('Should store account data in the storage.', async () => {
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST `/accounts/:id`', () => {
|
||||
it('Should `name` be required.', async () => {
|
||||
const account = await create('account');
|
||||
const res = await request().post(`/api/accounts/${account.id}`).send();
|
||||
|
||||
expect(res.status).equals(422);
|
||||
expect(res.body.code).equals('validation_error');
|
||||
});
|
||||
|
||||
it('Should `account_type_id` be required.', async () => {
|
||||
const account = await create('account');
|
||||
const res = await request().post(`/api/accounts/${account.id}`).send();
|
||||
|
||||
expect(res.status).equals(422);
|
||||
expect(res.body.code).equals('validation_error');
|
||||
});
|
||||
|
||||
it('Should max length of `code` be limited.', async () => {
|
||||
const account = await create('account');
|
||||
const res = await request().post(`/api/accounts/${account.id}`).send();
|
||||
|
||||
expect(res.status).equals(422);
|
||||
expect(res.body.code).equals('validation_error');
|
||||
});
|
||||
|
||||
it('Should response type not found in case `account_type_id` was not exist.', async () => {
|
||||
const res = await request().post('/api/accounts').send();
|
||||
|
||||
expect(res.status).equals(422);
|
||||
});
|
||||
|
||||
it('Should account code be unique in the storage.', async () => {
|
||||
const account = await create('account', { code: 'ABCD' });
|
||||
const res = await request().post(`/api/accounts/${account.id}`).send({
|
||||
// code: ',
|
||||
...account,
|
||||
});
|
||||
const account = await create('account');
|
||||
const res = await request()
|
||||
.post('/api/accounts')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send({
|
||||
name: account.name,
|
||||
description: account.description,
|
||||
account_type_id: account.accountTypeId,
|
||||
code: account.code,
|
||||
});
|
||||
|
||||
expect(res.status).equals(400);
|
||||
expect(res.body.errors).include.something.that.deep.equals({
|
||||
@@ -105,34 +80,166 @@ describe('routes: /accounts/', () => {
|
||||
|
||||
it('Should response success with correct data form.', async () => {
|
||||
const account = await create('account');
|
||||
const res = await request().post('/api/accounts').send({
|
||||
name: 'Name',
|
||||
description: 'description here',
|
||||
account_type_id: account.account_type_id,
|
||||
parent_account_id: account.id,
|
||||
const res = await request()
|
||||
.post('/api/accounts')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send({
|
||||
name: 'Name',
|
||||
description: 'description here',
|
||||
code: 100,
|
||||
account_type_id: account.accountTypeId,
|
||||
parent_account_id: account.id,
|
||||
});
|
||||
|
||||
console.log(res.body);
|
||||
|
||||
expect(res.status).equals(200);
|
||||
});
|
||||
|
||||
it('Should store account data in the storage.', async () => {
|
||||
const account = await create('account');
|
||||
await request().post('/api/accounts')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send({
|
||||
name: 'Account Name',
|
||||
description: 'desc here',
|
||||
account_type: account.account_type_id,
|
||||
parent_account_id: account.id,
|
||||
});
|
||||
|
||||
const accountModel = await Account.query().where('name', 'Account Name');
|
||||
|
||||
expect(accountModel.description).equals('desc here');
|
||||
expect(accountModel.account_type_id).equals(account.account_type_id);
|
||||
expect(accountModel.parent_account_id).equals(account.parent_account_id);
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST `/accounts/:id`', () => {
|
||||
it('Should `name` be required.', async () => {
|
||||
const account = await create('account');
|
||||
const res = await request()
|
||||
.post(`/api/accounts/${account.id}`)
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
expect(res.status).equals(422);
|
||||
expect(res.body.code).equals('validation_error');
|
||||
});
|
||||
|
||||
it('Should `account_type_id` be required.', async () => {
|
||||
const account = await create('account');
|
||||
const res = await request()
|
||||
.post(`/api/accounts/${account.id}`)
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
expect(res.status).equals(422);
|
||||
expect(res.body.code).equals('validation_error');
|
||||
});
|
||||
|
||||
it('Should max length of `code` be limited.', async () => {
|
||||
const account = await create('account');
|
||||
const res = await request()
|
||||
.post(`/api/accounts/${account.id}`)
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
expect(res.status).equals(422);
|
||||
expect(res.body.code).equals('validation_error');
|
||||
});
|
||||
|
||||
it('Should response type not found in case `account_type_id` was not exist.', async () => {
|
||||
const res = await request()
|
||||
.post('/api/accounts')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
expect(res.status).equals(422);
|
||||
});
|
||||
|
||||
it('Should account code be unique in the storage.', async () => {
|
||||
await create('account', { code: 'ABCD' });
|
||||
const account = await create('account');
|
||||
const res = await request()
|
||||
.post(`/api/accounts/${account.id}`)
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send({
|
||||
name: 'name',
|
||||
code: 'ABCD',
|
||||
account_type_id: account.accountTypeId,
|
||||
});
|
||||
|
||||
expect(res.status).equals(400);
|
||||
expect(res.body.errors).include.something.that.deep.equals({
|
||||
type: 'NOT_UNIQUE_CODE', code: 100,
|
||||
});
|
||||
});
|
||||
|
||||
it('Should response success with correct data form.', async () => {
|
||||
const account = await create('account');
|
||||
const res = await request()
|
||||
.post('/api/accounts')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send({
|
||||
name: 'Name',
|
||||
description: 'description here',
|
||||
account_type_id: account.accountTypeId,
|
||||
parent_account_id: account.id,
|
||||
code: '123',
|
||||
});
|
||||
|
||||
expect(res.status).equals(200);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET: `/accounts`', () => {
|
||||
it('Should retrieve chart of accounts', async () => {
|
||||
const account = await create('account');
|
||||
const account2 = await create('account', { parent_account_id: account.id });
|
||||
|
||||
const res = await request()
|
||||
.get('/api/accounts')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send()
|
||||
|
||||
console.log(res.body);
|
||||
});
|
||||
});
|
||||
|
||||
describe('DELETE: `/accounts`', () => {
|
||||
it('Should response not found in case account was not exist.', async () => {
|
||||
const res = await request().delete('/api/accounts/10').send();
|
||||
const res = await request()
|
||||
.delete('/api/accounts/10')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
expect(res.status).equals(404);
|
||||
});
|
||||
|
||||
it('Should delete the give account from the storage.', async () => {
|
||||
const account = await create('account');
|
||||
await request().delete(`/api/accounts/${account.id}`);
|
||||
await request()
|
||||
.delete(`/api/accounts/${account.id}`)
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
const foundAccounts = await knex('accounts').where('id', account.id);
|
||||
expect(foundAccounts).to.have.lengthOf(1);
|
||||
const foundAccounts = await Account.query().where('id', account.id);
|
||||
expect(foundAccounts).to.have.lengthOf(0);
|
||||
});
|
||||
|
||||
it('Should not delete the given account in case account has associated transactions.', async () => {
|
||||
const accountTransaction = await create('account_transaction');
|
||||
|
||||
const res = await request()
|
||||
.delete(`/api/accounts/${accountTransaction.accountId}`)
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
expect(res.status).equals(400);
|
||||
expect(res.body.errors).include.something.that.deep.equals({
|
||||
type: 'ACCOUNT.HAS.ASSOCIATED.TRANSACTIONS', code: 100,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -59,17 +59,15 @@ describe('routes: /auth/', () => {
|
||||
});
|
||||
|
||||
it('Should not authenticate in case user was not active.', async () => {
|
||||
const user = await create('user', {
|
||||
active: false,
|
||||
});
|
||||
const user = await create('user', { active: false });
|
||||
const res = await request().post('/api/auth/login').send({
|
||||
crediential: user.email,
|
||||
password: 'admin',
|
||||
password: 'incorrect_password',
|
||||
});
|
||||
|
||||
expect(res.status).equals(400);
|
||||
expect(res.body.errors).include.something.that.deep.equals({
|
||||
type: 'INCORRECT_PASSWORD', code: 120,
|
||||
type: 'INCORRECT_PASSWORD', code: 110,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -79,6 +77,7 @@ describe('routes: /auth/', () => {
|
||||
});
|
||||
const res = await request().post('/api/auth/login').send({
|
||||
crediential: user.email,
|
||||
password: 'admin',
|
||||
});
|
||||
|
||||
expect(res.status).equals(200);
|
||||
|
||||
262
server/tests/routes/budget.test.js
Normal file
262
server/tests/routes/budget.test.js
Normal file
@@ -0,0 +1,262 @@
|
||||
import {
|
||||
request,
|
||||
expect,
|
||||
create,
|
||||
login,
|
||||
} from '~/testInit';
|
||||
import Budget from '@/models/Budget';
|
||||
import BudgetEntry from '@/models/BudgetEntry';
|
||||
|
||||
let loginRes;
|
||||
|
||||
describe('routes: `/budget`', () => {
|
||||
beforeEach(async () => {
|
||||
loginRes = await login();
|
||||
});
|
||||
afterEach(() => {
|
||||
loginRes = null;
|
||||
});
|
||||
describe('POST: `/budget', () => {
|
||||
it('Should `name` be required.', async () => {
|
||||
const res = await request()
|
||||
.post('/api/budget')
|
||||
.set('x-access-token', loginRes.body.token).send();
|
||||
|
||||
expect(res.status).equals(422);
|
||||
expect(res.body.errors).include.something.that.deep.equal({
|
||||
msg: 'Invalid value', param: 'name', location: 'body',
|
||||
});
|
||||
});
|
||||
|
||||
it('Should `period` be required.', async () => {
|
||||
const res = await request()
|
||||
.post('/api/budget')
|
||||
.set('x-access-token', loginRes.body.token).send();
|
||||
|
||||
expect(res.status).equals(422);
|
||||
expect(res.body.errors).include.something.that.deep.equal({
|
||||
msg: 'Invalid value', param: 'period', location: 'body',
|
||||
});
|
||||
});
|
||||
|
||||
it('Should `fiscal_year` be required.', async () => {
|
||||
const res = await request()
|
||||
.post('/api/budget')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
expect(res.status).equals(422);
|
||||
expect(res.body.errors).include.something.that.deep.equal({
|
||||
msg: 'Invalid value', param: 'fiscal_year', location: 'body',
|
||||
});
|
||||
});
|
||||
|
||||
it('Should `entries` alteast one item', () => {
|
||||
|
||||
});
|
||||
|
||||
it('Should account id be exist in the storage.', async () => {
|
||||
const res = await request()
|
||||
.post('/api/budget')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send({
|
||||
name: 'Budget Name',
|
||||
fiscal_year: '2020',
|
||||
period: 'year',
|
||||
accounts_type: 'profit_loss',
|
||||
accounts: [
|
||||
{
|
||||
account_id: 100,
|
||||
entries: [
|
||||
{
|
||||
amount: 1000,
|
||||
order: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(res.status).equals(400);
|
||||
expect(res.body.errors).include.something.that.deep.equals({
|
||||
type: 'ACCOUNT.NOT.FOUND', code: 200, accounts: [100],
|
||||
});
|
||||
});
|
||||
|
||||
it('Should response success with budget id after post valid data.', async () => {
|
||||
const account = await create('account');
|
||||
|
||||
const res = await request()
|
||||
.post('/api/budget')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send({
|
||||
name: 'Budget Name',
|
||||
fiscal_year: '2020',
|
||||
period: 'year',
|
||||
accounts_type: 'profit_loss',
|
||||
accounts: [
|
||||
{
|
||||
account_id: account.id,
|
||||
entries: [
|
||||
{
|
||||
amount: 1000,
|
||||
order: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(res.status).equals(200);
|
||||
});
|
||||
|
||||
it('Should save budget to the storage.', async () => {
|
||||
const account = await create('account');
|
||||
|
||||
const res = await request()
|
||||
.post('/api/budget')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send({
|
||||
name: 'Budget Name',
|
||||
fiscal_year: '2020',
|
||||
period: 'year',
|
||||
accounts_type: 'profit_loss',
|
||||
accounts: [
|
||||
{
|
||||
account_id: account.id,
|
||||
entries: [
|
||||
{
|
||||
amount: 1000,
|
||||
order: 1,
|
||||
}
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// const storedBudget = await Budget.query().findById(res.body.id);
|
||||
// expect(storedBudget.name).equals('Budget Name');
|
||||
|
||||
const storedBudgetEntries = await BudgetEntry.query()
|
||||
.where('budget_id', storedBudget.id)
|
||||
.where('account_id', account.id);
|
||||
|
||||
expect(storedBudgetEntries.length).equals(1);
|
||||
});
|
||||
|
||||
it('Should save budget entries to the storage.', () => {
|
||||
|
||||
});
|
||||
|
||||
it('Should response success with correct data format.', () => {
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET: `/budget/:id`', () => {
|
||||
it('Should response not found in case budget id was not found.', async () => {
|
||||
const budget = await create('budget');
|
||||
|
||||
const res = await request()
|
||||
.get('/api/budget/1000')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
expect(res.status).equals(404);
|
||||
});
|
||||
|
||||
it('Should retrieve columns of budget year date range with year period.', async () => {
|
||||
const budget = await create('budget', { period: 'year' });
|
||||
const res = await request()
|
||||
.get(`/api/budget/${budget.id}`)
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
expect(res.body.columns.length).equals(1);
|
||||
});
|
||||
|
||||
it('Should retrieve columns of budget year range with month period.', async () => {
|
||||
const budget = await create('budget', {
|
||||
period: 'month',
|
||||
});
|
||||
|
||||
const res = await request()
|
||||
.get(`/api/budget/${budget.id}`)
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
expect(res.body.columns.length).equals(12);
|
||||
});
|
||||
|
||||
it('Should retrieve columns of budget year range with quarter period.', async () => {
|
||||
const budget = await create('budget', {
|
||||
period: 'quarter',
|
||||
});
|
||||
|
||||
const res = await request()
|
||||
.get(`/api/budget/${budget.id}`)
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
expect(res.body.columns.length).equals(4);
|
||||
});
|
||||
|
||||
it('Should retrieve columns of budget year range with half year period.', async () => {
|
||||
const budget = await create('budget', {
|
||||
period: 'half-year',
|
||||
});
|
||||
|
||||
const res = await request()
|
||||
.get(`/api/budget/${budget.id}`)
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
expect(res.body.columns.length).equals(2);
|
||||
});
|
||||
|
||||
it('Should retrieve budget accounts with associated entries.', async () => {
|
||||
const budget = await create('budget', { period: 'year' });
|
||||
const budgetEntry = await create('budget_entry', {
|
||||
budget_id: budget.id,
|
||||
});
|
||||
|
||||
const res = await request()
|
||||
.get(`/api/budget/${budget.id}`)
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
expect(res.body);
|
||||
});
|
||||
});
|
||||
|
||||
describe('DELETE: `/budget/:id`', () => {
|
||||
it('Should response not found in case budget id was not found.', () => {
|
||||
|
||||
});
|
||||
|
||||
it('Should delete budget from the storage', () => {
|
||||
|
||||
});
|
||||
|
||||
it('Should delete budget entries from the storage.', () => {
|
||||
|
||||
});
|
||||
|
||||
it('Should response success in case budget was exists before the delete.', () => {
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe.only('GET: `/budget`', () => {
|
||||
it('Should retrieve all budgets with pagination metadata.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/budget')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
console.log(res.body);
|
||||
|
||||
expect(res.status).equals(200);
|
||||
})
|
||||
})
|
||||
});
|
||||
67
server/tests/routes/budget_reports.test.js
Normal file
67
server/tests/routes/budget_reports.test.js
Normal file
@@ -0,0 +1,67 @@
|
||||
import {
|
||||
request,
|
||||
expect,
|
||||
create,
|
||||
login,
|
||||
} from '~/testInit';
|
||||
let loginRes;
|
||||
|
||||
describe('routes: `/budget_reports`', () => {
|
||||
beforeEach(async () => {
|
||||
loginRes = await login();
|
||||
});
|
||||
afterEach(() => {
|
||||
loginRes = null;
|
||||
});
|
||||
|
||||
describe.only('GET: `/budget_verses_actual/:reportId`', () => {
|
||||
it('Should retrieve columns of budget year range with quarter period.', async () => {
|
||||
const budget = await create('budget', { period: 'quarter' });
|
||||
const budgetEntry = await create('budget_entry', { budget_id: budget.id });
|
||||
|
||||
const res = await request()
|
||||
.get(`/api/budget_reports/budget_verses_actual/${budget.id}`)
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
expect(res.body.columns.length).equals(4);
|
||||
});
|
||||
|
||||
it('Should retrieve columns of budget year range with month period.', async () => {
|
||||
const budget = await create('budget', { period: 'month' });
|
||||
const budgetEntry = await create('budget_entry', { budget_id: budget.id });
|
||||
|
||||
const res = await request()
|
||||
.get(`/api/budget_reports/budget_verses_actual/${budget.id}`)
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
expect(res.body.columns.length).equals(12);
|
||||
});
|
||||
|
||||
it('Should retrieve columns of budget year range with year period.', async () => {
|
||||
const budget = await create('budget', { period: 'year' });
|
||||
const budgetEntry = await create('budget_entry', { budget_id: budget.id });
|
||||
|
||||
const res = await request()
|
||||
.get(`/api/budget_reports/budget_verses_actual/${budget.id}`)
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
expect(res.body.columns.length).equals(1);
|
||||
});
|
||||
|
||||
it('Should retrieve columns of budget year range with half-year period.', async () => {
|
||||
const budget = await create('budget', { period: 'half-year' });
|
||||
const budgetEntry = await create('budget_entry', { budget_id: budget.id });
|
||||
|
||||
const res = await request()
|
||||
.get(`/api/budget_reports/budget_verses_actual/${budget.id}`)
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
expect(res.body.columns.length).equals(2);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
309
server/tests/routes/expenses.test.js
Normal file
309
server/tests/routes/expenses.test.js
Normal file
@@ -0,0 +1,309 @@
|
||||
import { request, expect, create, login } from '~/testInit';
|
||||
import AccountTransaction from '@/models/AccountTransaction';
|
||||
import Expense from '@/models/Expense';
|
||||
|
||||
let loginRes;
|
||||
let expenseType;
|
||||
let cashType;
|
||||
let expenseAccount;
|
||||
let cashAccount;
|
||||
|
||||
describe('routes: /expenses/', () => {
|
||||
beforeEach(async () => {
|
||||
loginRes = await login();
|
||||
|
||||
expenseType = await create('account_type', { normal: 'debit' });
|
||||
cashType = await create('account_type', { normal: 'debit' });
|
||||
|
||||
expenseAccount = await create('account', { account_type_id: expenseType.id });
|
||||
cashAccount = await create('account', { account_type_id: cashType.id });
|
||||
});
|
||||
afterEach(() => {
|
||||
loginRes = null;
|
||||
});
|
||||
|
||||
describe('POST: `/expenses`', () => {
|
||||
it('Should response unauthorized in case user was not authorized.', async () => {
|
||||
const res = await request().post('/api/expenses').send();
|
||||
|
||||
expect(res.status).equals(401);
|
||||
expect(res.body.message).equals('unauthorized');
|
||||
});
|
||||
|
||||
it('Should `payment_account_id` be required.', async () => {
|
||||
const res = await request().post('/api/expenses')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
expect(res.body.errors).include.something.that.deep.equals({
|
||||
msg: 'Invalid value',
|
||||
param: 'payment_account_id',
|
||||
location: 'body',
|
||||
});
|
||||
});
|
||||
|
||||
it('Should `expense_account_id` be required.', async () => {
|
||||
const res = await request().post('/api/expenses')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
expect(res.body.errors).include.something.that.deep.equals({
|
||||
msg: 'Invalid value',
|
||||
param: 'expense_account_id',
|
||||
location: 'body',
|
||||
});
|
||||
});
|
||||
|
||||
it('Should `amount` be required.', async () => {
|
||||
const res = await request().post('/api/expenses')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
expect(res.body.errors).include.something.that.deep.equals({
|
||||
msg: 'Invalid value',
|
||||
param: 'amount',
|
||||
location: 'body',
|
||||
});
|
||||
});
|
||||
|
||||
it('Should `exchange_rate` be required in case `currency_code` not equal default one.', () => {
|
||||
|
||||
});
|
||||
|
||||
it('Should response bad request in case expense account was not found.', async () => {
|
||||
const res = await request().post('/api/expenses')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send({
|
||||
expense_account_id: 100,
|
||||
payment_account_id: 100,
|
||||
amount: 100,
|
||||
});
|
||||
|
||||
expect(res.body.errors).include.something.that.deep.equals({
|
||||
type: 'EXPENSE.ACCOUNT.NOT.FOUND', code: 200,
|
||||
});
|
||||
});
|
||||
|
||||
it('Should response bad request in case payment account was not found.', async () => {
|
||||
const res = await request().post('/api/expenses')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send({
|
||||
expense_account_id: 100,
|
||||
payment_account_id: 100,
|
||||
amount: 100,
|
||||
});
|
||||
|
||||
expect(res.body.errors).include.something.that.deep.equals({
|
||||
type: 'PAYMENT.ACCOUNT.NOT.FOUND', code: 100,
|
||||
});
|
||||
});
|
||||
|
||||
it('Should response success with valid required data.', async () => {
|
||||
const res = await request().post('/api/expenses')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send({
|
||||
expense_account_id: expenseAccount.id,
|
||||
payment_account_id: cashAccount.id,
|
||||
amount: 100,
|
||||
});
|
||||
|
||||
expect(res.status).equals(200);
|
||||
});
|
||||
|
||||
it('Should record journal entries of expense transaction.', async () => {
|
||||
const res = await request().post('/api/expenses')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send({
|
||||
expense_account_id: expenseAccount.id,
|
||||
payment_account_id: cashAccount.id,
|
||||
amount: 100,
|
||||
});
|
||||
|
||||
const expensesEntries = await AccountTransaction.query()
|
||||
.where('reference_type', 'Expense')
|
||||
.where('reference_id', res.body.id);
|
||||
|
||||
expect(expensesEntries.length).equals(2);
|
||||
});
|
||||
|
||||
it('Should save expense transaction to the storage.', () => {
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST: `/expenses/:id`', () => {
|
||||
it('Should response unauthorized in case user was not authorized.', () => {
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('DELETE: `/expenses/:id`', () => {
|
||||
it('Should response not found in case expense not found.', async () => {
|
||||
const res = await request()
|
||||
.delete('/api/expense/1000')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
expect(res.body.reasons).include.something.that.deep.equals({
|
||||
type: 'EXPENSE.NOT.FOUND', code: 100,
|
||||
});
|
||||
});
|
||||
|
||||
it('Should response success in case expense transaction was exist.', async () => {
|
||||
const expense = await create('expense');
|
||||
const res = await request()
|
||||
.delete(`/api/expense/${expense.id}`)
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
expect(res.status).equals(200);
|
||||
});
|
||||
|
||||
it('Should delete the expense transaction from the storage.', async () => {
|
||||
const expense = await create('expense');
|
||||
await request()
|
||||
.delete(`/api/expense/${expense.id}`)
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
const storedExpense = await Expense.query().findById(expense.id);
|
||||
expect(storedExpense).equals(undefined);
|
||||
});
|
||||
|
||||
it('Should delete the journal entries that associated to expense transaction from the storage.', async () => {
|
||||
const expense = await create('expense');
|
||||
await request()
|
||||
.delete(`/api/expense/${expense.id}`)
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
const expenseEntries = await AccountTransaction.query()
|
||||
.where('reference_type', 'Expense')
|
||||
.where('reference_id', expense.id);
|
||||
|
||||
expect(expenseEntries.length).equals(0);
|
||||
});
|
||||
|
||||
it('Should reverse accounts balance that associated to expense transaction.', () => {
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST: `/expenses/bulk`', () => {
|
||||
it('Should response unauthorized in case user was not authorized.', async () => {
|
||||
const res = await request().post('/api/expenses/bluk').send();
|
||||
|
||||
expect(res.status).equals(401);
|
||||
expect(res.body.message).equals('unauthorized');
|
||||
});
|
||||
|
||||
it('Should response bad request in case expenses was not array.', async () => {
|
||||
const res = await request()
|
||||
.post('/api/expenses/bulk')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send({
|
||||
expenses: 'Not array :(',
|
||||
});
|
||||
|
||||
expect(res.body.errors).include.something.that.deep.equals({
|
||||
value: 'Not array :(',
|
||||
msg: 'Invalid value',
|
||||
param: 'expenses',
|
||||
location: 'body',
|
||||
});
|
||||
});
|
||||
|
||||
it('Should response bad request in case one expense account was not found.', async () => {
|
||||
const res = await request()
|
||||
.post('/api/expenses/bulk')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send({
|
||||
expenses: [
|
||||
{
|
||||
payment_account_id: 100,
|
||||
expense_account_id: 100,
|
||||
amount: 1000,
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(res.body.reasons).include.something.that.deep.equals({
|
||||
type: 'EXPENSE.ACCOUNTS.NOT.FOUND', code: 200, accounts: [100],
|
||||
});
|
||||
});
|
||||
|
||||
it('Should response bad request in case one of payment account was not found.', async () => {
|
||||
const res = await request()
|
||||
.post('/api/expenses/bulk')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send({
|
||||
expenses: [
|
||||
{
|
||||
payment_account_id: 100,
|
||||
expense_account_id: 100,
|
||||
amount: 1000,
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(res.body.reasons).include.something.that.deep.equals({
|
||||
type: 'PAYMENY.ACCOUNTS.NOT.FOUND', code: 100, accounts: [100],
|
||||
});
|
||||
});
|
||||
|
||||
it('Should store expenses transactions to the storage.', async () => {
|
||||
const res = await request()
|
||||
.post('/api/expenses/bulk')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send({
|
||||
expenses: [
|
||||
{
|
||||
payment_account_id: cashAccount.id,
|
||||
expense_account_id: expenseAccount.id,
|
||||
amount: 1000,
|
||||
},
|
||||
{
|
||||
payment_account_id: cashAccount.id,
|
||||
expense_account_id: expenseAccount.id,
|
||||
amount: 1000,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const expenseTransactions = await Expense.query();
|
||||
expect(expenseTransactions.length).equals(2);
|
||||
});
|
||||
|
||||
it('Should store journal entries of expenses transactions to the storage.', async () => {
|
||||
const res = await request()
|
||||
.post('/api/expenses/bulk')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send({
|
||||
expenses: [
|
||||
{
|
||||
payment_account_id: cashAccount.id,
|
||||
expense_account_id: expenseAccount.id,
|
||||
amount: 1000,
|
||||
},
|
||||
{
|
||||
payment_account_id: cashAccount.id,
|
||||
expense_account_id: expenseAccount.id,
|
||||
amount: 1000,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const expenseJournalEntries = await AccountTransaction.query();
|
||||
expect(expenseJournalEntries.length).equals(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET: `/expenses/:id`', () => {
|
||||
it('Should response view not found in case the custom view id was not exist.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/expenses')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
console.log(res.status);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -187,7 +187,6 @@ describe('route: `/fields`', () => {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('DELETE: `/fields/:field_id`', () => {
|
||||
it('Should response not found in case field id was not exist.', async () => {
|
||||
const res = await request().delete('/api/fields/100').send();
|
||||
|
||||
648
server/tests/routes/financial_statements.test.js
Normal file
648
server/tests/routes/financial_statements.test.js
Normal file
@@ -0,0 +1,648 @@
|
||||
import {
|
||||
expect,
|
||||
request,
|
||||
login,
|
||||
create,
|
||||
} from '~/testInit';
|
||||
|
||||
let loginRes;
|
||||
let creditAccount;
|
||||
let debitAccount;
|
||||
|
||||
describe('routes: `/financial_statements`', () => {
|
||||
beforeEach(async () => {
|
||||
loginRes = await login();
|
||||
|
||||
// Balance sheet types.
|
||||
const creditAccType = await create('account_type', { normal: 'credit', balance_sheet: true });
|
||||
const debitAccType = await create('account_type', { normal: 'debit', balance_sheet: true });
|
||||
|
||||
// Income statement types.
|
||||
const incomeType = await create('account_type', { normal: 'credit', income_sheet: true });
|
||||
const expenseType = await create('account_type', { normal: 'debit', income_sheet: true });
|
||||
|
||||
// Assets & liabilites accounts.
|
||||
creditAccount = await create('account', { account_type_id: creditAccType.id });
|
||||
debitAccount = await create('account', { account_type_id: debitAccType.id });
|
||||
|
||||
// Income && expenses accounts.
|
||||
const incomeAccount = await create('account', { account_type_id: incomeType.id });
|
||||
const expenseAccount = await create('account', { account_type_id: expenseType.id });
|
||||
const income2Account = await create('account', { account_type_id: incomeType.id });
|
||||
|
||||
const accountTransactionMixied = { date: '2020-1-10' };
|
||||
|
||||
await create('account_transaction', {
|
||||
credit: 1000, debit: 0, account_id: creditAccount.id, referenceType: 'Expense', ...accountTransactionMixied,
|
||||
});
|
||||
await create('account_transaction', {
|
||||
credit: 1000, debit: 0, account_id: creditAccount.id, ...accountTransactionMixied,
|
||||
});
|
||||
await create('account_transaction', {
|
||||
debit: 2000, credit: 0, account_id: debitAccount.id, ...accountTransactionMixied,
|
||||
});
|
||||
await create('account_transaction', {
|
||||
debit: 2000, credit: 0, account_id: debitAccount.id, ...accountTransactionMixied,
|
||||
});
|
||||
await create('account_transaction', { credit: 2000, account_id: incomeAccount.id, ...accountTransactionMixied });
|
||||
await create('account_transaction', { debit: 6000, account_id: expenseAccount.id, ...accountTransactionMixied });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
loginRes = null;
|
||||
});
|
||||
describe('routes: `/financial_statements/ledger`', () => {
|
||||
it('Should response unauthorized in case the user was not authorized.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/ledger')
|
||||
.send();
|
||||
|
||||
expect(res.status).equals(400);
|
||||
});
|
||||
|
||||
it('Should retrieve ledger transactions grouped by accounts.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/ledger')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
expect(res.status).equals(200);
|
||||
expect(res.body.items.length).to.be.at.least(1);
|
||||
|
||||
expect(res.body.items[0]).to.have.property('id');
|
||||
expect(res.body.items[0]).to.have.property('referenceType');
|
||||
expect(res.body.items[0]).to.have.property('referenceId');
|
||||
expect(res.body.items[0]).to.have.property('date');
|
||||
expect(res.body.items[0]).to.have.property('account');
|
||||
expect(res.body.items[0]).to.have.property('note');
|
||||
});
|
||||
|
||||
it('Should retrieve transactions between date range.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/ledger')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.query({
|
||||
from_date: '2018-01-01',
|
||||
to_date: '2019-01-01',
|
||||
})
|
||||
.send();
|
||||
|
||||
expect(res.body.items.length).equals(0);
|
||||
});
|
||||
|
||||
it('Should retrieve transactions that associated to the queried accounts.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/ledger')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.query({
|
||||
account_ids: [creditAccount.id, debitAccount.id],
|
||||
})
|
||||
.send();
|
||||
|
||||
expect(res.body.items.length).equals(4);
|
||||
});
|
||||
|
||||
it('Should retrieve tranasactions with the given types.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/ledger')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.query({
|
||||
transaction_types: ['Expense'],
|
||||
});
|
||||
|
||||
expect(res.body.items.length).equals(1);
|
||||
});
|
||||
|
||||
it('Should retrieve transactions with range amount.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/ledger')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.query({
|
||||
from_range: 1000,
|
||||
to_range: 2000,
|
||||
});
|
||||
});
|
||||
|
||||
it('Should format credit and debit to no cents of retrieved transactions.', async () => {
|
||||
|
||||
});
|
||||
|
||||
it('Should divide credit/debit amount on 1000', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/ledger')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.query({
|
||||
number_format: {
|
||||
divide_1000: true,
|
||||
},
|
||||
})
|
||||
.send();
|
||||
|
||||
res.body.items.forEach((item) => {
|
||||
expect(item.credit).to.be.at.most(100);
|
||||
expect(item.debit).to.be.at.most(100);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('routes: `/financial_statements/general_ledger`', () => {
|
||||
it('Should response unauthorized in case the user was not authorized.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/general_ledger')
|
||||
.send();
|
||||
|
||||
expect(res.status).equals(400);
|
||||
});
|
||||
|
||||
it('Should retrieve the genereal ledger transactions.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/general_ledger')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
expect(res.body.items).to.be.a('array');
|
||||
expect(res.body.items.length).equals(4);
|
||||
});
|
||||
|
||||
it('Should retrieve opeing and closing balance in each account.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/general_ledger')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
const foundCreditAccount = res.body.items.find((a) => a.id === creditAccount.id);
|
||||
|
||||
expect(foundCreditAccount.closing.balance).equals(2000);
|
||||
expect(foundCreditAccount.opening.balance).equals(0);
|
||||
});
|
||||
|
||||
it('Should retrieve the general ledger transactions between date range.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/general_ledger')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.query({
|
||||
from_date: '2020-04-04',
|
||||
to_date: '2020-05-05',
|
||||
})
|
||||
.send();
|
||||
|
||||
const foundCreditAccount = res.body.items.find((a) => a.id === creditAccount.id);
|
||||
expect(foundCreditAccount.transactions.length).equals(0);
|
||||
});
|
||||
|
||||
it('Should retrieve the general ledger transactions with no cents numbers.', () => {
|
||||
|
||||
});
|
||||
|
||||
it('Should retrieve the transacvtions divided on 1000.', () => {
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('routes: `financial_statements/balance_sheet`', () => {
|
||||
it('Should response unauthorzied in case the user was not authorized.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/balance_sheet')
|
||||
.send();
|
||||
|
||||
expect(res.status).equals(401);
|
||||
});
|
||||
|
||||
it('Should retrieve the asset accounts balance.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/balance_sheet')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.query({
|
||||
display_columns_by: 'year',
|
||||
})
|
||||
.send();
|
||||
|
||||
expect(res.body.balance_sheet.assets).to.be.a('array');
|
||||
expect(res.body.balance_sheet.liabilities_equity).to.be.a('array');
|
||||
});
|
||||
|
||||
it('Should retrieve asset/liabilities balance sheet between the given date range.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/balance_sheet')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.query({
|
||||
display_columns_by: 'year',
|
||||
from_date: '2012-01-01',
|
||||
to_date: '2018-02-02',
|
||||
})
|
||||
.send();
|
||||
|
||||
const { balance_sheet: balanceSheet } = res.body;
|
||||
const foundCreditAccount = balanceSheet.assets.find((account) => {
|
||||
return account.id === debitAccount.id;
|
||||
});
|
||||
|
||||
expect(foundCreditAccount.transactions.length).equals(6);
|
||||
foundCreditAccount.transactions.forEach((transaction) => {
|
||||
expect(transaction.balance).equals(0);
|
||||
});
|
||||
|
||||
const foundDebitAccount = balanceSheet.liabilities_equity.find((account) => {
|
||||
return account.id === creditAccount.id;
|
||||
});
|
||||
|
||||
expect(foundDebitAccount.transactions.length).equals(6);
|
||||
foundDebitAccount.transactions.forEach((transaction) => {
|
||||
expect(transaction.balance).equals(0);
|
||||
});
|
||||
});
|
||||
|
||||
it('Should retrieve balance sheet with display columns day.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/balance_sheet')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.query({
|
||||
display_columns_by: 'day',
|
||||
from_date: '2020-03-01',
|
||||
to_date: '2020-04-01',
|
||||
})
|
||||
.send();
|
||||
|
||||
const { balance_sheet: balanceSheet } = res.body;
|
||||
|
||||
const foundDebitAccount = balanceSheet.assets.find((account) => {
|
||||
return account.id === debitAccount.id;
|
||||
});
|
||||
const foundCreditAccount = balanceSheet.liabilities_equity.find((account) => {
|
||||
return account.id === creditAccount.id;
|
||||
});
|
||||
|
||||
expect(foundDebitAccount.transactions.length).equals(31);
|
||||
expect(foundCreditAccount.transactions.length).equals(31);
|
||||
|
||||
foundDebitAccount.transactions.forEach((transaction) => {
|
||||
expect(transaction.balance).equals(4000);
|
||||
});
|
||||
foundCreditAccount.transactions.forEach((transaction) => {
|
||||
expect(transaction.balance).equals(2000);
|
||||
});
|
||||
});
|
||||
|
||||
it('Should retrieve the balance sheet with display columns month.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/balance_sheet')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.query({
|
||||
display_columns_by: 'month',
|
||||
from_date: '2020',
|
||||
to_date: '2021',
|
||||
})
|
||||
.send();
|
||||
|
||||
const { balance_sheet: balanceSheet } = res.body;
|
||||
|
||||
const foundDebitAccount = balanceSheet.assets.find((account) => {
|
||||
return account.id === debitAccount.id;
|
||||
});
|
||||
const foundCreditAccount = balanceSheet.liabilities_equity.find((account) => {
|
||||
return account.id === creditAccount.id;
|
||||
});
|
||||
|
||||
expect(foundDebitAccount.transactions.length).equals(12);
|
||||
expect(foundCreditAccount.transactions.length).equals(12);
|
||||
|
||||
foundDebitAccount.transactions.forEach((transaction) => {
|
||||
expect(transaction.balance).equals(4000);
|
||||
});
|
||||
foundCreditAccount.transactions.forEach((transaction) => {
|
||||
expect(transaction.balance).equals(2000);
|
||||
});
|
||||
});
|
||||
|
||||
it('Should retrieve the balance sheet with display columns quarter.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/balance_sheet')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.query({
|
||||
display_columns_by: 'quarter',
|
||||
from_date: '2020',
|
||||
to_date: '2021',
|
||||
})
|
||||
.send();
|
||||
|
||||
const { balance_sheet: balanceSheet } = res.body;
|
||||
|
||||
const foundDebitAccount = balanceSheet.assets.find((account) => {
|
||||
return account.id === debitAccount.id;
|
||||
});
|
||||
const foundCreditAccount = balanceSheet.liabilities_equity.find((account) => {
|
||||
return account.id === creditAccount.id;
|
||||
});
|
||||
|
||||
expect(foundDebitAccount.transactions.length).equals(4);
|
||||
expect(foundCreditAccount.transactions.length).equals(4);
|
||||
|
||||
foundDebitAccount.transactions.forEach((transaction) => {
|
||||
expect(transaction.balance).equals(4000);
|
||||
});
|
||||
foundCreditAccount.transactions.forEach((transaction) => {
|
||||
expect(transaction.balance).equals(2000);
|
||||
});
|
||||
});
|
||||
|
||||
it('Should retrieve the balance sheet amounts without cents.', () => {
|
||||
|
||||
});
|
||||
|
||||
it('Should retrieve the balance sheet amounts divided on 1000.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/balance_sheet')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.query({
|
||||
display_columns_by: 'quarter',
|
||||
from_date: '2020',
|
||||
to_date: '2021',
|
||||
number_format: {
|
||||
divide_1000: true,
|
||||
},
|
||||
})
|
||||
.send();
|
||||
|
||||
const { balance_sheet: balanceSheet } = res.body;
|
||||
const foundDebitAccount = balanceSheet.assets.find((account) => {
|
||||
return account.id === debitAccount.id;
|
||||
});
|
||||
const foundCreditAccount = balanceSheet.liabilities_equity.find((account) => {
|
||||
return account.id === creditAccount.id;
|
||||
});
|
||||
|
||||
expect(foundDebitAccount.transactions.length).equals(4);
|
||||
expect(foundCreditAccount.transactions.length).equals(4);
|
||||
|
||||
foundDebitAccount.transactions.forEach((transaction) => {
|
||||
expect(transaction.balance).equals(4);
|
||||
});
|
||||
foundCreditAccount.transactions.forEach((transaction) => {
|
||||
expect(transaction.balance).equals(2);
|
||||
});
|
||||
});
|
||||
|
||||
it('Should not retrieve accounts has no transactions between the given date range in case query none_zero is true.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/balance_sheet')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.query({
|
||||
display_columns_by: 'quarter',
|
||||
from_date: '2002',
|
||||
to_date: '2003',
|
||||
number_format: {
|
||||
divide_1000: true,
|
||||
},
|
||||
none_zero: true,
|
||||
})
|
||||
.send();
|
||||
|
||||
const { balance_sheet: balanceSheet } = res.body;
|
||||
const foundDebitAccount = balanceSheet.assets.find((account) => {
|
||||
return account.id === debitAccount.id;
|
||||
});
|
||||
|
||||
const foundCreditAccount = balanceSheet.liabilities_equity.find((account) => {
|
||||
return account.id === creditAccount.id;
|
||||
});
|
||||
expect(foundDebitAccount).equals(undefined);
|
||||
expect(foundCreditAccount).equals(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe('routes: `/financial_statements/trial_balance`', () => {
|
||||
it('Should response unauthorized in case the user was not authorized.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/trial_balance_sheet')
|
||||
.send();
|
||||
|
||||
expect(res.status).equals(401);
|
||||
});
|
||||
|
||||
it('Should retrieve the trial balance of accounts.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/trial_balance_sheet')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.send();
|
||||
|
||||
const foundCreditAccount = res.body.items.find((item) => {
|
||||
return item.account_id === creditAccount.id;
|
||||
});
|
||||
expect(foundCreditAccount.credit).equals(2000);
|
||||
expect(foundCreditAccount.debit).equals(0);
|
||||
expect(foundCreditAccount.balance).equals(2000);
|
||||
});
|
||||
|
||||
it('Should not retrieve accounts has no transactions between the given date range.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/trial_balance_sheet')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.query({
|
||||
// There is no transactions between these dates.
|
||||
from_date: '2002-01-01',
|
||||
to_date: '2003-01-01',
|
||||
})
|
||||
.send();
|
||||
|
||||
res.body.items.forEach((item) => {
|
||||
expect(item.credit).equals(0);
|
||||
expect(item.debit).equals(0);
|
||||
expect(item.balance).equals(0);
|
||||
});
|
||||
});
|
||||
|
||||
it('Should retrieve trial balance of accounts between the given date range.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/trial_balance_sheet')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.query({
|
||||
// There is no transactions between these dates.
|
||||
from_date: '2020-01-05',
|
||||
to_date: '2020-01-10',
|
||||
})
|
||||
.send();
|
||||
|
||||
const foundCreditAccount = res.body.items.find((item) => {
|
||||
return item.account_id === creditAccount.id;
|
||||
});
|
||||
expect(foundCreditAccount.credit).equals(2000);
|
||||
expect(foundCreditAccount.debit).equals(0);
|
||||
expect(foundCreditAccount.balance).equals(2000);
|
||||
});
|
||||
|
||||
it('Should credit, debit and balance amount be divided on 1000.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/trial_balance_sheet')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.query({
|
||||
// There is no transactions between these dates.
|
||||
from_date: '2020-01-05',
|
||||
to_date: '2020-01-10',
|
||||
number_format: {
|
||||
divide_1000: true,
|
||||
},
|
||||
})
|
||||
.send();
|
||||
|
||||
const foundCreditAccount = res.body.items.find((item) => {
|
||||
return item.account_id === creditAccount.id;
|
||||
});
|
||||
expect(foundCreditAccount.credit).equals(2);
|
||||
expect(foundCreditAccount.debit).equals(0);
|
||||
expect(foundCreditAccount.balance).equals(2);
|
||||
});
|
||||
|
||||
it('Should credit, debit and balance amount rounded without cents.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/trial_balance_sheet')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.query({
|
||||
// There is no transactions between these dates.
|
||||
from_date: '2020-01-05',
|
||||
to_date: '2020-01-10',
|
||||
number_format: {
|
||||
no_cents: true,
|
||||
},
|
||||
})
|
||||
.send();
|
||||
});
|
||||
});
|
||||
|
||||
describe('routes: `/api/financial_statements/profit_loss_sheet`', () => {
|
||||
it('Should response unauthorized in case the user was not authorized.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/profit_loos_sheet')
|
||||
.send();
|
||||
|
||||
expect(res.status).equals(401);
|
||||
expect(res.body.message).equals('unauthorzied');
|
||||
});
|
||||
|
||||
it('Should retrieve credit sumation of income accounts.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/profit_loss_sheet')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.query({
|
||||
from_date: '2020-01-01',
|
||||
to_date: '2021-01-01',
|
||||
number_format: {
|
||||
divide_1000: true,
|
||||
},
|
||||
})
|
||||
.send();
|
||||
|
||||
res.body.income.accounts[0].dates.forEach((item) => {
|
||||
expect(item.rawAmount).equals(2000);
|
||||
});
|
||||
});
|
||||
|
||||
it('Should retrieve debit sumation of expenses accounts.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/profit_loss_sheet')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.query({
|
||||
from_date: '2020-01-01',
|
||||
to_date: '2021-01-01',
|
||||
number_format: {
|
||||
divide_1000: true,
|
||||
},
|
||||
})
|
||||
.send();
|
||||
|
||||
res.body.expenses.accounts[0].dates.forEach((item) => {
|
||||
expect(item.rawAmount).equals(4000);
|
||||
});
|
||||
});
|
||||
|
||||
it('Should retrieve credit sumation of income accounts between the given date range.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/profit_loss_sheet')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.query({
|
||||
from_date: '2020-01-01',
|
||||
to_date: '2021-01-01',
|
||||
display_columns_by: 'month',
|
||||
number_format: {
|
||||
divide_1000: true,
|
||||
},
|
||||
})
|
||||
.send();
|
||||
|
||||
expect(res.body.income.accounts[0].dates.length).equals(12);
|
||||
});
|
||||
|
||||
it('Should retrieve debit sumation of expenses accounts between the given date range.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/profit_loss_sheet')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.query({
|
||||
from_date: '2020-01-01',
|
||||
to_date: '2021-01-01',
|
||||
display_columns_by: 'month',
|
||||
number_format: {
|
||||
divide_1000: true,
|
||||
},
|
||||
})
|
||||
.send();
|
||||
|
||||
expect(res.body.expenses.accounts[0].dates.length).equals(12);
|
||||
});
|
||||
|
||||
it('Should retrieve total income of income accounts between the given date range.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/profit_loss_sheet')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.query({
|
||||
from_date: '2020-01-01',
|
||||
to_date: '2021-01-01',
|
||||
display_columns_by: 'month',
|
||||
})
|
||||
.send();
|
||||
|
||||
expect(res.body.total_income[0].rawAmount).equals(2000);
|
||||
});
|
||||
|
||||
it('Should retrieve total expenses of expenses accounts between the given date range.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/profit_loss_sheet')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.query({
|
||||
from_date: '2020-01-01',
|
||||
to_date: '2021-01-01',
|
||||
display_columns_by: 'month',
|
||||
})
|
||||
.send();
|
||||
|
||||
expect(res.body.total_expenses[0].rawAmount).equals(6000);
|
||||
});
|
||||
|
||||
it('Should retrieve total net income between the given date range.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/profit_loss_sheet')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.query({
|
||||
from_date: '2020-01-01',
|
||||
to_date: '2021-01-01',
|
||||
display_columns_by: 'month',
|
||||
})
|
||||
.send();
|
||||
|
||||
expect(res.body.total_net_income[0].rawAmount).equals(-4000);
|
||||
});
|
||||
|
||||
it('Should not retrieve income or expenses accounts that has no transactions between the given date range in case none_zero equals true.', async () => {
|
||||
const res = await request()
|
||||
.get('/api/financial_statements/profit_loss_sheet')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.query({
|
||||
from_date: '2020-01-01',
|
||||
to_date: '2021-01-01',
|
||||
display_columns_by: 'month',
|
||||
none_zero: true
|
||||
})
|
||||
.send();
|
||||
|
||||
expect(res.body.income.accounts.length).equals(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -6,8 +6,8 @@ import {
|
||||
} from '~/testInit';
|
||||
import knex from '@/database/knex';
|
||||
|
||||
describe.only('routes: `/items`', () => {
|
||||
describe.only('POST: `/items`', () => {
|
||||
describe('routes: `/items`', () => {
|
||||
describe('POST: `/items`', () => {
|
||||
it('Should not create a new item if the user was not authorized.', async () => {
|
||||
const res = await request().post('/api/items').send();
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ describe('routes: /oauth2/', () => {
|
||||
describe('POST `/api/oauth/token`', () => {
|
||||
it('Should `crediential` be required.', async () => {
|
||||
const res = await request().post('/api/oauth2/token').send({});
|
||||
console.log(res.body);
|
||||
expect(res.status).equals(200);
|
||||
});
|
||||
});
|
||||
|
||||
0
server/tests/routes/options.test.js
Normal file
0
server/tests/routes/options.test.js
Normal file
@@ -4,10 +4,10 @@ import ViewRole from '@/models/ViewRole';
|
||||
import '@/models/ResourceField';
|
||||
|
||||
describe('routes: `/views`', () => {
|
||||
describe('POST: `/views/:resource_id`', () => {
|
||||
describe('POST: `/views`', () => {
|
||||
it('Should `label` be required.', async () => {
|
||||
const resource = await create('resource');
|
||||
const res = await request().post(`/api/views/resource/${resource.id}`);
|
||||
await create('resource');
|
||||
const res = await request().post('/api/views');
|
||||
|
||||
expect(res.status).equals(422);
|
||||
expect(res.body.code).equals('validation_error');
|
||||
@@ -16,9 +16,17 @@ describe('routes: `/views`', () => {
|
||||
expect(paramsErrors).to.include('label');
|
||||
});
|
||||
|
||||
it('Should columns be minimum limited', async () => {
|
||||
const resource = await create('resource');
|
||||
const res = await request().post(`/api/views/resource/${resource.id}`, {
|
||||
it('Should `resource_name` be required.', async () => {
|
||||
await create('resource');
|
||||
const res = await request().post('/api/views');
|
||||
|
||||
expect(res.status).equals(422);
|
||||
expect(res.body.code).equals('validation_error');
|
||||
});
|
||||
|
||||
it('Should `columns` be minimum limited', async () => {
|
||||
await create('resource');
|
||||
const res = await request().post('/api/views', {
|
||||
label: 'View Label',
|
||||
columns: [],
|
||||
});
|
||||
@@ -30,9 +38,9 @@ describe('routes: `/views`', () => {
|
||||
expect(paramsErrors).to.include('columns');
|
||||
});
|
||||
|
||||
it('Should columns be array.', async () => {
|
||||
const resource = await create('resource');
|
||||
const res = await request().post(`/api/views/resource/${resource.id}`, {
|
||||
it('Should `columns` be array.', async () => {
|
||||
await create('resource');
|
||||
const res = await request().post('/api/views', {
|
||||
label: 'View Label',
|
||||
columns: 'not_array',
|
||||
});
|
||||
@@ -46,7 +54,8 @@ describe('routes: `/views`', () => {
|
||||
|
||||
it('Should `roles.*.field` be required.', async () => {
|
||||
const resource = await create('resource');
|
||||
const res = await request().post(`/api/views/resource/${resource.id}`).send({
|
||||
const res = await request().post('/api/views').send({
|
||||
resource_name: resource.name,
|
||||
label: 'View Label',
|
||||
roles: [{}],
|
||||
});
|
||||
@@ -60,7 +69,8 @@ describe('routes: `/views`', () => {
|
||||
|
||||
it('Should `roles.*.comparator` be valid.', async () => {
|
||||
const resource = await create('resource');
|
||||
const res = await request().post(`/api/views/resource/${resource.id}`).send({
|
||||
const res = await request().post('/api/views').send({
|
||||
resource_name: resource.name,
|
||||
label: 'View Label',
|
||||
roles: [{}],
|
||||
});
|
||||
@@ -74,7 +84,8 @@ describe('routes: `/views`', () => {
|
||||
|
||||
it('Should `roles.*.index` be number as integer.', async () => {
|
||||
const resource = await create('resource');
|
||||
const res = await request().post(`/api/views/resource/${resource.id}`).send({
|
||||
const res = await request().post('/api/views').send({
|
||||
resource_name: resource.name,
|
||||
label: 'View Label',
|
||||
roles: [{ index: 'not_numeric' }],
|
||||
});
|
||||
@@ -87,7 +98,8 @@ describe('routes: `/views`', () => {
|
||||
});
|
||||
|
||||
it('Should response not found in case resource was not exist.', async () => {
|
||||
const res = await request().post('/api/views/resource/100').send({
|
||||
const res = await request().post('/api/views').send({
|
||||
resource_name: 'not_found',
|
||||
label: 'View Label',
|
||||
columns: ['amount', 'thumbnail', 'status'],
|
||||
roles: [{
|
||||
@@ -99,15 +111,17 @@ describe('routes: `/views`', () => {
|
||||
});
|
||||
|
||||
expect(res.status).equals(404);
|
||||
expect(res.body.errors).include.something.that.deep.equals({
|
||||
type: 'RESOURCE_NOT_FOUND', code: 100,
|
||||
});
|
||||
});
|
||||
|
||||
it('Should response the roles fields not exist in case role field was not exist.', async () => {
|
||||
const resource = await create('resource');
|
||||
await create('resource_field', {
|
||||
resource_id: resource.id,
|
||||
label_name: 'Amount',
|
||||
});
|
||||
const res = await request().post(`/api/views/resource/${resource.id}`).send({
|
||||
await create('resource_field', { resource_id: resource.id, label_name: 'Amount' });
|
||||
|
||||
const res = await request().post('/api/views').send({
|
||||
resource_name: resource.name,
|
||||
label: 'View Label',
|
||||
columns: ['amount', 'thumbnail', 'status'],
|
||||
roles: [{
|
||||
@@ -119,19 +133,17 @@ describe('routes: `/views`', () => {
|
||||
});
|
||||
|
||||
expect(res.body.errors).include.something.that.deep.equals({
|
||||
type: 'RESOURCE_FIELDS_NOT_EXIST',
|
||||
code: 100,
|
||||
fields: ['price'],
|
||||
type: 'RESOURCE_FIELDS_NOT_EXIST', code: 100, fields: ['price'],
|
||||
});
|
||||
});
|
||||
|
||||
it('Should response the columns not exists in case column was not exist.', async () => {
|
||||
const resource = await create('resource');
|
||||
await create('resource_field', {
|
||||
resource_id: resource.id,
|
||||
label_name: 'Amount',
|
||||
resource_id: resource.id, label_name: 'Amount', slug: 'amount',
|
||||
});
|
||||
const res = await request().post(`/api/views/resource/${resource.id}`).send({
|
||||
const res = await request().post('/api/views').send({
|
||||
resource_name: resource.name,
|
||||
label: 'View Label',
|
||||
columns: ['amount', 'thumbnail', 'status'],
|
||||
roles: [{
|
||||
@@ -145,11 +157,39 @@ describe('routes: `/views`', () => {
|
||||
expect(res.body.errors).include.something.that.deep.equals({
|
||||
type: 'COLUMNS_NOT_EXIST',
|
||||
code: 200,
|
||||
fields: ['thumbnail', 'status'],
|
||||
columns: ['thumbnail', 'status'],
|
||||
});
|
||||
});
|
||||
|
||||
it('Should save the given details with associated roles and columns.', async () => {
|
||||
it('Should save the given details of the view.', async () => {
|
||||
const resource = await create('resource');
|
||||
await create('resource_field', {
|
||||
resource_id: resource.id, label_name: 'Amount', slug: 'amount',
|
||||
});
|
||||
const res = await request().post('/api/views').send({
|
||||
resource_name: resource.name,
|
||||
label: 'View Label',
|
||||
columns: ['amount'],
|
||||
roles: [{
|
||||
index: 1,
|
||||
field: 'amount',
|
||||
comparator: 'equals',
|
||||
value: '100',
|
||||
}],
|
||||
});
|
||||
|
||||
const storedView = await View.query().where('name', 'View Label').first();
|
||||
|
||||
expect(storedView.name).equals('View Label');
|
||||
expect(storedView.predefined).equals(0);
|
||||
expect(storedView.resourceId).equals(resource.id);
|
||||
});
|
||||
|
||||
it('Should save the given details of view fields that associated to the given view id.', () => {
|
||||
|
||||
});
|
||||
|
||||
it('Should save the given details of view roles that associated to the given view.', async () => {
|
||||
|
||||
});
|
||||
});
|
||||
@@ -269,9 +309,7 @@ describe('routes: `/views`', () => {
|
||||
});
|
||||
|
||||
expect(res.body.errors).include.something.that.deep.equals({
|
||||
type: 'RESOURCE_FIELDS_NOT_EXIST',
|
||||
code: 100,
|
||||
fields: ['price'],
|
||||
type: 'RESOURCE_FIELDS_NOT_EXIST', code: 100, fields: ['price'],
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -282,6 +320,9 @@ describe('routes: `/views`', () => {
|
||||
const res = await request().delete(`/api/views/${view.id}`).send();
|
||||
|
||||
expect(res.status).equals(400);
|
||||
expect(res.body.errors).include.something.that.deep.equals({
|
||||
type: 'PREDEFINED_VIEW', code: 200,
|
||||
});
|
||||
});
|
||||
|
||||
it('Should response not found in case view was not exist.', async () => {
|
||||
@@ -300,8 +341,8 @@ describe('routes: `/views`', () => {
|
||||
|
||||
await request().delete(`/api/views/${view.id}`).send();
|
||||
|
||||
const foundViews = await View.where('id', view.id).fetchAll();
|
||||
const foundViewRoles = await ViewRole.where('view_id', view.id).fetchAll();
|
||||
const foundViews = await View.query().where('id', view.id).first();
|
||||
const foundViewRoles = await ViewRole.query().where('view_id', view.id).first();
|
||||
|
||||
expect(foundViews).to.have.lengthOf(0);
|
||||
expect(foundViewRoles).to.have.lengthOf(0);
|
||||
|
||||
234
server/tests/services/JournalPoster.test.js
Normal file
234
server/tests/services/JournalPoster.test.js
Normal file
@@ -0,0 +1,234 @@
|
||||
import { expect, create } from '~/testInit';
|
||||
import JournalPoster from '@/services/Accounting/JournalPoster';
|
||||
import JournalEntry from '@/services/Accounting/JournalEntry';
|
||||
import AccountBalance from '@/models/AccountBalance';
|
||||
import AccountTransaction from '@/models/AccountTransaction';
|
||||
|
||||
describe('JournalPoster', () => {
|
||||
describe('credit()', () => {
|
||||
it('Should write credit entry to journal entries stack.', () => {
|
||||
const journalEntries = new JournalPoster();
|
||||
const journalEntry = new JournalEntry({
|
||||
referenceId: 1,
|
||||
referenceType: 'Expense',
|
||||
credit: 100,
|
||||
account: 1,
|
||||
});
|
||||
journalEntries.credit(journalEntry);
|
||||
expect(journalEntries.entries.length).equals(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('debit()', () => {
|
||||
it('Should write debit entry to journal entries stack.', () => {
|
||||
const journalEntries = new JournalPoster();
|
||||
const journalEntry = new JournalEntry({
|
||||
referenceId: 1,
|
||||
referenceType: 'Expense',
|
||||
debit: 100,
|
||||
account: 1,
|
||||
});
|
||||
|
||||
journalEntries.debit(journalEntry);
|
||||
expect(journalEntries.entries.length).equals(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('setBalanceChange()', () => {
|
||||
it('Should increment balance amount after credit entry with credit normal account.', () => {
|
||||
const journalEntries = new JournalPoster();
|
||||
const journalEntry = new JournalEntry({
|
||||
referenceId: 1,
|
||||
referenceType: 'Expense',
|
||||
credit: 100,
|
||||
debit: 0,
|
||||
account: 1,
|
||||
accountNormal: 'debit',
|
||||
});
|
||||
journalEntries.credit(journalEntry);
|
||||
expect(journalEntries.balancesChange).to.have.property(1, -100);
|
||||
});
|
||||
|
||||
it('Should decrement balance amount after debit entry wiht debit normal account.', () => {
|
||||
const journalEntries = new JournalPoster();
|
||||
const journalEntry = new JournalEntry({
|
||||
referenceId: 1,
|
||||
referenceType: 'Expense',
|
||||
debit: 100,
|
||||
account: 1,
|
||||
accountNormal: 'debit',
|
||||
});
|
||||
journalEntries.debit(journalEntry);
|
||||
expect(journalEntries.balancesChange).to.have.property(1, 100);
|
||||
});
|
||||
});
|
||||
|
||||
describe('saveEntries()', () => {
|
||||
it('Should save all stacked entries to the storage.', async () => {
|
||||
const journalEntries = new JournalPoster();
|
||||
const journalEntry = new JournalEntry({
|
||||
referenceId: 1,
|
||||
referenceType: 'Expense',
|
||||
debit: 100,
|
||||
account: 1,
|
||||
accountNormal: 'debit',
|
||||
});
|
||||
|
||||
journalEntries.debit(journalEntry);
|
||||
await journalEntries.saveEntries();
|
||||
|
||||
const storedJournalEntries = await AccountTransaction.query();
|
||||
|
||||
expect(storedJournalEntries.length).equals(1);
|
||||
expect(storedJournalEntries[0]).to.deep.include({
|
||||
referenceType: 'Expense',
|
||||
referenceId: 1,
|
||||
debit: 100,
|
||||
credit: 0,
|
||||
accountId: 1,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('saveBalance()', () => {
|
||||
it('Should save account balance increment.', async () => {
|
||||
const account = await create('account');
|
||||
|
||||
const journalEntries = new JournalPoster();
|
||||
const journalEntry = new JournalEntry({
|
||||
referenceId: 1,
|
||||
referenceType: 'Expense',
|
||||
debit: 100,
|
||||
account: account.id,
|
||||
accountNormal: 'debit',
|
||||
});
|
||||
journalEntries.debit(journalEntry);
|
||||
|
||||
await journalEntries.saveBalance();
|
||||
|
||||
const storedAccountBalance = await AccountBalance.query();
|
||||
|
||||
expect(storedAccountBalance.length).equals(1);
|
||||
expect(storedAccountBalance[0].amount).equals(100);
|
||||
});
|
||||
|
||||
it('Should save account balance decrement.', async () => {
|
||||
const account = await create('account');
|
||||
|
||||
const journalEntries = new JournalPoster();
|
||||
const journalEntry = new JournalEntry({
|
||||
referenceId: 1,
|
||||
referenceType: 'Expense',
|
||||
credit: 100,
|
||||
account: account.id,
|
||||
accountNormal: 'debit',
|
||||
});
|
||||
journalEntries.credit(journalEntry);
|
||||
|
||||
await journalEntries.saveBalance();
|
||||
|
||||
const storedAccountBalance = await AccountBalance.query();
|
||||
|
||||
expect(storedAccountBalance.length).equals(1);
|
||||
expect(storedAccountBalance[0].amount).equals(-100);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getClosingBalance', () => {
|
||||
it('Should retrieve closing balance the given account id.', () => {
|
||||
const journalEntries = new JournalPoster();
|
||||
const journalEntry = new JournalEntry({
|
||||
referenceId: 1,
|
||||
referenceType: 'Expense',
|
||||
debit: 100,
|
||||
account: 1,
|
||||
accountNormal: 'debit',
|
||||
date: '2020-1-10',
|
||||
});
|
||||
const journalEntry2 = new JournalEntry({
|
||||
referenceId: 1,
|
||||
referenceType: 'Income',
|
||||
credit: 100,
|
||||
account: 2,
|
||||
accountNormal: 'credit',
|
||||
date: '2020-1-12',
|
||||
});
|
||||
journalEntries.credit(journalEntry);
|
||||
journalEntries.credit(journalEntry2);
|
||||
|
||||
const closingBalance = journalEntries.getClosingBalance(1, '2020-1-30');
|
||||
expect(closingBalance).equals(100);
|
||||
});
|
||||
|
||||
it('Should retrieve closing balance the given closing date period.', () => {
|
||||
const journalEntries = new JournalPoster();
|
||||
const journalEntry = new JournalEntry({
|
||||
referenceId: 1,
|
||||
referenceType: 'Expense',
|
||||
debit: 100,
|
||||
account: 1,
|
||||
accountNormal: 'debit',
|
||||
date: '2020-1-10',
|
||||
});
|
||||
const journalEntry2 = new JournalEntry({
|
||||
referenceId: 1,
|
||||
referenceType: 'Income',
|
||||
credit: 100,
|
||||
account: 2,
|
||||
accountNormal: 'credit',
|
||||
date: '2020-1-12',
|
||||
});
|
||||
journalEntries.credit(journalEntry);
|
||||
journalEntries.credit(journalEntry2);
|
||||
|
||||
const closingBalance = journalEntries.getClosingBalance(1, '2020-1-2');
|
||||
expect(closingBalance).equals(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getTrialBalance(account, closeDate, dateType)', () => {
|
||||
it('Should retrieve the trial balance of the given account id.', () => {
|
||||
const journalEntries = new JournalPoster();
|
||||
const journalEntry = new JournalEntry({
|
||||
referenceId: 1,
|
||||
referenceType: 'Expense',
|
||||
debit: 200,
|
||||
account: 1,
|
||||
accountNormal: 'debit',
|
||||
date: '2020-1-10',
|
||||
});
|
||||
const journalEntry2 = new JournalEntry({
|
||||
referenceId: 1,
|
||||
referenceType: 'Income',
|
||||
credit: 100,
|
||||
account: 1,
|
||||
accountNormal: 'credit',
|
||||
date: '2020-1-12',
|
||||
});
|
||||
|
||||
journalEntries.debit(journalEntry);
|
||||
journalEntries.credit(journalEntry2);
|
||||
|
||||
const trialBalance = journalEntries.getTrialBalance(1);
|
||||
|
||||
expect(trialBalance.credit).equals(100);
|
||||
expect(trialBalance.debit).equals(200);
|
||||
});
|
||||
});
|
||||
|
||||
describe('groupingEntriesByDate(accountId, dateGroupType)', () => {
|
||||
|
||||
});
|
||||
|
||||
describe('deleteEntries', () => {
|
||||
|
||||
});
|
||||
|
||||
describe('reverseEntries()', () => {
|
||||
|
||||
});
|
||||
|
||||
describe('loadFromCollection', () => {
|
||||
|
||||
});
|
||||
});
|
||||
@@ -1,8 +1,9 @@
|
||||
import chai from 'chai';
|
||||
import chaiHttp from 'chai-http';
|
||||
import chaiThings from 'chai-things';
|
||||
import app from '@/app';
|
||||
import knex from '@/database/knex';
|
||||
import '@/models';
|
||||
import app from '@/app';
|
||||
import factory from '@/database/factories';
|
||||
// import { hashPassword } from '@/utils';
|
||||
|
||||
|
||||
16
server/tests/utils/utils.test.js
Normal file
16
server/tests/utils/utils.test.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import { dateRangeCollection } from '@/utils';
|
||||
import { expect } from '../testInit';
|
||||
|
||||
describe('utils', () => {
|
||||
|
||||
describe('dateRangeCollection()', () => {
|
||||
it('Should retrieve all range dates.', () => {
|
||||
const fromDate = new Date('2020-1-1');
|
||||
const toDate = new Date('2020-1-25');
|
||||
|
||||
const range = dateRangeCollection(fromDate, toDate);
|
||||
|
||||
expect(range.length).equals(25);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user