feat: refs #7704 Major changes #2717

Merged
guillermo merged 18 commits from 7704-itemMinimalQuantity into dev 2024-07-12 07:43:46 +00:00
1 changed files with 101 additions and 0 deletions
Showing only changes of commit 9e3baeffa6 - Show all commits

View File

@ -0,0 +1,101 @@
const {models} = require('vn-loopback/server/server');
describe('itemMinimumQuantity model', () => {
const itemFk = 5;
const warehouseFk = 60;
beforeAll(async() => {
await models.ItemMinimumQuantity.destroyAll({where: {itemFk: itemFk}});
});
describe('CRUD operations', () => {
it('should create a new itemMinimumQuantity record', async() => {
const newRecord = {
itemFk: itemFk,
quantity: 100,
started: Date.vnNew(),
ended: new Date(Date.vnNew().setFullYear(Date.vnNew().getFullYear() + 1)),
warehouseFk: warehouseFk
};
const createdRecord = await models.ItemMinimumQuantity.create(newRecord);
expect(createdRecord).toBeDefined();
expect(createdRecord.quantity).toEqual(newRecord.quantity);
});
it('should read an existing itemMinimumQuantity record', async() => {
const newRecord = {
itemFk: itemFk,
quantity: 100,
started: Date.vnNew(),
ended: new Date(Date.vnNew().setFullYear(Date.vnNew().getFullYear() + 2)),
warehouseFk: warehouseFk
};
await models.ItemMinimumQuantity.create(newRecord);
const existingRecord = await models.ItemMinimumQuantity.findOne({where: {itemFk: itemFk}});
expect(existingRecord).toBeDefined();
expect(existingRecord.itemFk).toEqual(itemFk);
});
it('should update an existing itemMinimumQuantity record', async() => {
const newRecord = {
itemFk: itemFk,
quantity: 100,
started: Date.vnNew(),
ended: new Date(Date.vnNew().setFullYear(Date.vnNew().getFullYear() + 3)),
warehouseFk: warehouseFk
};
await models.ItemMinimumQuantity.create(newRecord);
const newQuantity = 150;
const existingRecord = await models.ItemMinimumQuantity.findOne({where: {itemFk: itemFk}});
existingRecord.quantity = newQuantity;
await existingRecord.save();
const updatedRecord = await models.ItemMinimumQuantity.findOne({where: {itemFk: itemFk}});
expect(updatedRecord.quantity).toEqual(newQuantity);
});
});
describe('validation and constraints', () => {
it('should enforce unique constraint on itemFk, started, ended, and warehouseFk', async() => {
const newRecord = {
itemFk: itemFk,
quantity: 100,
started: Date.vnNew(),
ended: Date.vnNew().setFullYear(Date.vnNew().getFullYear() + 5),
warehouseFk: warehouseFk
};
try {
await models.ItemMinimumQuantity.create(newRecord);
await models.ItemMinimumQuantity.create(newRecord);
} catch (e) {
expect(e).toBeDefined();
expect(e.code).toContain('ER_DUP_ENTRY');
}
});
it('should allow null values for ended and warehouseFk', async() => {
const newRecord = {
itemFk: itemFk,
quantity: 100,
started: Date.vnNew(),
ended: null,
warehouseFk: null
};
const createdRecord = await models.ItemMinimumQuantity.create(newRecord);
expect(createdRecord).toBeDefined();
expect(createdRecord.ended).toBeNull();
expect(createdRecord.warehouseFk).toBeNull();
});
});
});