mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 06:10:31 +00:00
WIP Items module.
This commit is contained in:
28
server/tests/models/Item.test.js
Normal file
28
server/tests/models/Item.test.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import { create, expect } from '~/testInit';
|
||||
import Item from '@/models/Item';
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
import itemCategory from '@/models/ItemCategory';
|
||||
import '@/models/ItemMetadata';
|
||||
|
||||
describe('Model: Item', () => {
|
||||
it('Should item model belongs to the associated category model.', async () => {
|
||||
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();
|
||||
|
||||
expect(itemCategoryModel.attributes.id).equals(category.id);
|
||||
});
|
||||
|
||||
it('Should item model has many metadata that assciated to the item model.', async () => {
|
||||
const item = await create('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();
|
||||
|
||||
expect(itemMetadataCollection.length).equals(2);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user