2564-item_priceFixed + e2e #513

Merged
carlosjr merged 19 commits from 2564-item_priceFixed into dev 2021-01-20 14:34:07 +00:00
1 changed files with 86 additions and 0 deletions
Showing only changes of commit 3ec641f733 - Show all commits

View File

@ -0,0 +1,86 @@
const app = require('vn-loopback/server/server');
describe('fixed price filter()', () => {
it('should return 1 result filtering by item ID', async() => {
const itemID = 3;
const ctx = {
req: {accessToken: {userId: 1}},
args: {
search: itemID
}
};
const result = await app.models.FixedPrice.filter(ctx);
expect(result.length).toEqual(1);
expect(result[0].id).toEqual(2);
expect(result[0].itemFk).toEqual(itemID);
});
it('should return 1 result filtering by item type code', async() => {
const itemCode = 'CRI';
const ctx = {
req: {accessToken: {userId: 1}},
args: {
search: itemCode
}
};
const itemType = await app.models.ItemType.findOne({
where: {code: itemCode},
fields: ['id']
});
const items = await app.models.Item.find({
where: {typeFk: itemType.id},
fields: ['id']
});
const IDs = items.map(item => {
return item.id;
});
const result = await app.models.FixedPrice.filter(ctx);
const firstResult = result[0];
expect(result.length).toEqual(1);
expect(firstResult.id).toEqual(2);
expect(IDs).toContain(firstResult.itemFk);
});
it('should return 2 results filtering by warehouse', async() => {
const warehouseID = 1;
const ctx = {
req: {accessToken: {userId: 1}},
args: {
warehouseFk: warehouseID
}
};
const result = await app.models.FixedPrice.filter(ctx);
const length = result.length;
const anyResult = result[Math.floor(Math.random() * Math.floor(length))];
expect(result.length).toEqual(2);
expect(anyResult.warehouseFk).toEqual(warehouseID);
});
it('should return no results filtering by hasMinPrice', async() => {
const ctx = {
req: {accessToken: {userId: 1}},
args: {
hasMinPrice: true
}
};
const result = await app.models.FixedPrice.filter(ctx);
expect(result.length).toEqual(0);
});
it('should return no results filtering by typeFk', async() => {
const ctx = {
req: {accessToken: {userId: 1}},
args: {
typeFk: 1
}
};
const result = await app.models.FixedPrice.filter(ctx);
expect(result.length).toEqual(1);
});
});