refactor: refs #7301 update entry and item filter tests to validate results against specific criteria
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Pablo Natek 2024-11-22 06:27:00 +01:00
parent c17069a909
commit e92ce939b8
3 changed files with 33 additions and 7 deletions

View File

@ -38,8 +38,9 @@ describe('Entry filter()', () => {
};
const result = await models.Entry.filter(ctx, options);
const resultWithCurrency = result.filter(entry => entry.currencyFk === 1);
expect(result.length).toEqual(12);
expect(result.length).toEqual(resultWithCurrency.length);
await tx.rollback();
} catch (e) {
@ -141,18 +142,21 @@ describe('Entry filter()', () => {
it('should return the entry matching the company', async() => {
const tx = await models.Entry.beginTransaction({});
const options = {transaction: tx};
const companyFk = 442;
try {
const ctx = {
args: {
companyFk: 442
companyFk
},
req: {accessToken: {userId: 9}}
};
const result = await models.Entry.filter(ctx, options);
expect(result.length).toEqual(11);
const resultWithCurrency = result.filter(entry => entry.companyFk === companyFk);
expect(result.length).toEqual(resultWithCurrency.length);
await tx.rollback();
} catch (e) {

View File

@ -34,10 +34,31 @@ describe('item lastEntriesFilter()', () => {
const options = {transaction: tx};
try {
const filter = {where: {itemFk: 1, landed: {between: [minDate, maxDate]}}};
const itemFk = 1;
const filter = {where: {itemFk, landed: {between: [minDate, maxDate]}}};
const result = await models.Item.lastEntriesFilter(filter, options);
const minDateUtc = new Date(minDate).getTime();
const maxDateUtc = new Date(maxDate).getTime();
expect(result.length).toEqual(6);
const resultMatch = (
await Promise.all(
result.map(async item => {
const itemRecord = await models.Buy.findOne({
fields: ['id'],
where: {id: item.id},
options,
});
const isItemFkValid = itemRecord?.id === itemFk;
const landedDate = new Date(item.landed).getTime();
const isLandedValid = landedDate >= minDateUtc && landedDate <= maxDateUtc;
return isItemFkValid && isLandedValid;
})
)
).filter(Boolean).length;
expect(result.length).toEqual(resultMatch);
await tx.rollback();
} catch (e) {

View File

@ -3,9 +3,10 @@ const models = require('vn-loopback/server/server').models;
describe('travel getEntries()', () => {
const travelId = 1;
it('should check the response contains the id', async() => {
const entries = await models.Travel.getEntries(travelId);
const result = await models.Travel.getEntries(travelId);
const entries = await models.Entry.find({where: {travelFk: travelId}});
expect(entries.length).toEqual(1);
expect(entries.length).toEqual(result.length);
expect(entries[0].id).toEqual(1);
});