add server to monorepo.

This commit is contained in:
a.bouhuolia
2023-02-03 11:57:50 +02:00
parent 28e309981b
commit 80b97b5fdc
1303 changed files with 137049 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
import {
expect,
} from '~/testInit';
import Account from 'models/Account';
import AccountType from 'models/AccountType';
import {
tenantFactory,
tenantWebsite
} from '~/dbInit';
import DependencyGraph from '@/lib/DependencyGraph';
describe('Model: Account', () => {
it('Should account model belongs to the associated account type model.', async () => {
const accountType = await tenantFactory.create('account_type');
const account = await tenantFactory.create('account', { account_type_id: accountType.id });
const accountModel = await Account.tenant().query()
.where('id', account.id)
.withGraphFetched('type')
.first();
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 tenantFactory.create('account_balance');
const accountModel = await Account.tenant().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 tenantFactory.create('account');
const accountTransaction = await tenantFactory.create('account_transaction', { account_id: account.id });
const accountModel = await Account.tenant().query().where('id', account.id).first();
const transactionsModels = await accountModel.$relatedQuery('transactions');
expect(transactionsModels.length).equals(1);
});
it('Should retrieve dependency graph.', async () => {
const accountsDepGraph = await Account.tenant().depGraph().query();
expect(accountsDepGraph).to.be.an.instanceOf(DependencyGraph);
});
});

View File

@@ -0,0 +1,22 @@
import { create, expect } from '~/testInit';
import 'models/Account';
import AccountType from 'models/AccountType';
import {
tenantWebsite,
tenantFactory,
loginRes
} from '~/dbInit';
describe('Model: AccountType', () => {
it('Shoud account type model has many associated accounts.', async () => {
const accountType = await tenantFactory.create('account_type');
await tenantFactory.create('account', { account_type_id: accountType.id });
await tenantFactory.create('account', { account_type_id: accountType.id });
const accountTypeModel = await AccountType.tenant().query().where('id', accountType.id).first();
const typeAccounts = await accountTypeModel.$relatedQuery('accounts');
expect(typeAccounts.length).equals(2);
});
});

View File

@@ -0,0 +1,39 @@
import { create, expect } from '~/testInit';
import Expense from 'models/Expense';
import ExpenseCategory from 'models/ExpenseCategory';
import {
tenantFactory,
tenantWebsite
} from '~/dbInit';
describe('Model: Expense', () => {
describe('relations', () => {
it('Expense model may belongs to associated payment account.', async () => {
const expense = await tenantFactory.create('expense');
const expenseModel = await Expense.tenant().query().findById(expense.id);
const paymentAccountModel = await expenseModel.$relatedQuery('paymentAccount');
expect(paymentAccountModel.id).equals(expense.paymentAccountId);
});
it('Expense model may has many associated expense categories.', async () => {
const expenseCategory = await tenantFactory.create('expense_category');
const expenseModel = await Expense.tenant().query().findById(expenseCategory.expenseId);
const expenseCategories = await expenseModel.$relatedQuery('categories');
expect(expenseCategories.length).equals(1);
expect(expenseCategories[0].expenseId).equals(expenseModel.id);
});
it('Expense model may belongs to associated user model.', async () => {
const expense = await tenantFactory.create('expense');
const expenseModel = await Expense.tenant().query().findById(expense.id);
const expenseUserModel = await expenseModel.$relatedQuery('user');
expect(expenseUserModel.id).equals(expense.userId);
});
});
});

View File

@@ -0,0 +1,5 @@
describe('ExpenseCategory', () => {
});

View File

@@ -0,0 +1,22 @@
import { create, expect } from '~/testInit';
import Item from 'models/Item';
// eslint-disable-next-line no-unused-vars
import itemCategory from 'models/ItemCategory';
import {
tenantWebsite,
tenantFactory,
loginRes
} from '~/dbInit';
describe('Model: Item', () => {
it('Should item model belongs to the associated category model.', async () => {
const category = await tenantFactory.create('item_category');
const item = await tenantFactory.create('item', { category_id: category.id });
const itemModel = await Item.tenant().query().where('id', item.id).first();
const itemCategoryModel = await itemModel.$relatedQuery('category');
expect(itemCategoryModel.id).equals(category.id);
});
});

View File

@@ -0,0 +1,24 @@
import { create, expect } from '~/testInit';
import 'models/Item';
import ItemCategory from 'models/ItemCategory';
import {
tenantWebsite,
tenantFactory,
loginRes
} from '~/dbInit';
describe('Model: ItemCategories', () => {
it('Shoud item category model has many associated items.', async () => {
const category = await tenantFactory.create('item_category');
await tenantFactory.create('item', { category_id: category.id });
await tenantFactory.create('item', { category_id: category.id });
const categoryModel = await ItemCategory.tenant().query()
.where('id', category.id).first();
const categoryItems = await categoryModel.$relatedQuery('items');
expect(categoryItems.length).equals(2);
});
});

View File

@@ -0,0 +1,31 @@
import { create, expect } from '~/testInit';
import Resource from 'models/Resource';
import 'models/View';
import 'models/ResourceField';
import {
tenantWebsite,
tenantFactory,
loginRes
} from '~/dbInit';
describe('Model: Resource', () => {
it('Resource model may has many associated views.', async () => {
const view = await tenantFactory.create('view');
await tenantFactory.create('view', { resource_id: view.resourceId });
const resourceModel = await Resource.tenant().query().findById(view.resourceId);
const resourceViews = await resourceModel.$relatedQuery('views');
expect(resourceViews).to.have.lengthOf(2);
});
it('Resource model may has many fields.', async () => {
const resourceField = await tenantFactory.create('resource_field');
const resourceModel = await Resource.tenant().query().findById(resourceField.resourceId);
const resourceFields = await resourceModel.$relatedQuery('fields');
expect(resourceFields).to.have.lengthOf(1);
});
});

View File

@@ -0,0 +1,23 @@
import { create, expect } from '~/testInit';
import User from 'models/TenantUser';
import 'models/Role';
import {
tenantWebsite,
tenantFactory,
loginRes
} from '~/dbInit';
describe('Model: User', () => {
describe('relations', () => {
it('User model may has many associated roles.', async () => {
const userHasRole = await tenantFactory.create('user_has_role');
await tenantFactory.create('user_has_role', { user_id: userHasRole.user_id });
const userModel = await User.tenant().query().where('id', userHasRole.userId).first();
const userRoles = await userModel.$relatedQuery('roles');
expect(userRoles).to.have.lengthOf(1);
});
});
});

View File

@@ -0,0 +1,47 @@
import { create, expect } from '~/testInit';
import View from 'models/View';
import Resource from 'models/Resource';
import ResourceField from 'models/ResourceField';
import ViewRole from 'models/ViewRole';
import {
tenantWebsite,
tenantFactory,
loginRes
} from '~/dbInit';
describe('Model: View', () => {
it('View model may has many associated resource.', async () => {
const view = await tenantFactory.create('view');
const viewModel = await View.tenant().query().findById(view.id);
const viewResource = await viewModel.$relatedQuery('resource');
const foundResource = await Resource.tenant().query().findById(view.resourceId);
expect(viewResource.id).equals(foundResource.id);
expect(viewResource.name).equals(foundResource.name);
});
it('View model may has many associated view roles.', async () => {
const view = await tenantFactory.create('view');
await tenantFactory.create('view_role', { view_id: view.id });
await tenantFactory.create('view_role', { view_id: view.id });
const viewModel = await View.tenant().query().findById(view.id);
const viewRoles = await viewModel.$relatedQuery('roles');
expect(viewRoles).to.have.lengthOf(2);
});
it('View model may has many associated view columns', async () => {
const view = await tenantFactory.create('view');
await tenantFactory.create('view_column', { view_id: view.id });
await tenantFactory.create('view_column', { view_id: view.id });
const viewModel = await View.tenant().query().findById(view.id);
const viewColumns = await viewModel.$relatedQuery('columns');
expect(viewColumns).to.have.lengthOf(2);
});
});