feat: refs #7301 add inventory-config and acl #3230

Open
pablone wants to merge 4 commits from 7301-itemLastEntries into dev
3 changed files with 33 additions and 7 deletions
Showing only changes of commit e92ce939b8 - Show all commits

View File

@ -38,8 +38,9 @@ describe('Entry filter()', () => {
}; };
const result = await models.Entry.filter(ctx, options); 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(); await tx.rollback();
} catch (e) { } catch (e) {
@ -141,18 +142,21 @@ describe('Entry filter()', () => {
it('should return the entry matching the company', async() => { it('should return the entry matching the company', async() => {
const tx = await models.Entry.beginTransaction({}); const tx = await models.Entry.beginTransaction({});
const options = {transaction: tx}; const options = {transaction: tx};
const companyFk = 442;
try { try {
const ctx = { const ctx = {
args: { args: {
companyFk: 442 companyFk
}, },
req: {accessToken: {userId: 9}} req: {accessToken: {userId: 9}}
}; };
const result = await models.Entry.filter(ctx, options); 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(); await tx.rollback();
} catch (e) { } catch (e) {

View File

@ -34,10 +34,31 @@ describe('item lastEntriesFilter()', () => {
const options = {transaction: tx}; const options = {transaction: tx};
try { 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 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(); await tx.rollback();
} catch (e) { } catch (e) {

View File

@ -3,9 +3,10 @@ const models = require('vn-loopback/server/server').models;
describe('travel getEntries()', () => { describe('travel getEntries()', () => {
const travelId = 1; const travelId = 1;
it('should check the response contains the id', async() => { 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); expect(entries[0].id).toEqual(1);
}); });