diff --git a/modules/entry/back/methods/entry/specs/filter.spec.js b/modules/entry/back/methods/entry/specs/filter.spec.js index 4bf5127b0..b139b00b6 100644 --- a/modules/entry/back/methods/entry/specs/filter.spec.js +++ b/modules/entry/back/methods/entry/specs/filter.spec.js @@ -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) { diff --git a/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js b/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js index 2fd30c2ca..d4429e158 100644 --- a/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js +++ b/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js @@ -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) { diff --git a/modules/travel/back/methods/travel/specs/getEntries.spec.js b/modules/travel/back/methods/travel/specs/getEntries.spec.js index fcaa80d02..9286a9d55 100644 --- a/modules/travel/back/methods/travel/specs/getEntries.spec.js +++ b/modules/travel/back/methods/travel/specs/getEntries.spec.js @@ -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); });