test(salix): refs #7648 #7648 test travels and entries
gitea/salix/pipeline/pr-master Build queued... Details

This commit is contained in:
Javier Segarra 2024-07-16 12:45:51 +02:00
parent 8fe94772f3
commit d558e3d9f4
4 changed files with 151 additions and 41 deletions

View File

@ -9,7 +9,8 @@ describe('Entry filter()', () => {
const ctx = { const ctx = {
args: { args: {
search: 1 search: 1
} },
req: {accessToken: {userId: 9}}
}; };
const result = await models.Entry.filter(ctx, options); const result = await models.Entry.filter(ctx, options);
@ -32,12 +33,13 @@ describe('Entry filter()', () => {
const ctx = { const ctx = {
args: { args: {
currencyFk: 1 currencyFk: 1
} },
req: {accessToken: {userId: 9}}
}; };
const result = await models.Entry.filter(ctx, options); const result = await models.Entry.filter(ctx, options);
expect(result.length).toEqual(9); expect(result.length).toEqual(11);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {
@ -46,7 +48,52 @@ describe('Entry filter()', () => {
} }
}); });
it('should return the entry matching the supplier', async() => { describe('should return the entry matching the supplier', () => {
it('when userId is supplier ', async() => {
const tx = await models.Entry.beginTransaction({});
const options = {transaction: tx};
try {
const ctx = {
args: {days: 6},
req: {accessToken: {userId: 1102}}
};
const result = await models.Entry.filter(ctx, options);
expect(result.length).toEqual(2);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('when userId is supplier fetching other supplier', async() => {
const tx = await models.Entry.beginTransaction({});
const options = {transaction: tx};
try {
const ctx = {
args: {
supplierFk: 1
},
req: {accessToken: {userId: 1102}}
};
const result = await models.Entry.filter(ctx, options);
expect(result.length).toEqual(8);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('when userId is not supplier', async() => {
const tx = await models.Entry.beginTransaction({}); const tx = await models.Entry.beginTransaction({});
const options = {transaction: tx}; const options = {transaction: tx};
@ -54,12 +101,13 @@ describe('Entry filter()', () => {
const ctx = { const ctx = {
args: { args: {
supplierFk: 2 supplierFk: 2
} },
req: {accessToken: {userId: 9}}
}; };
const result = await models.Entry.filter(ctx, options); const result = await models.Entry.filter(ctx, options);
expect(result.length).toEqual(6); expect(result.length).toEqual(8);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {
@ -67,6 +115,7 @@ describe('Entry filter()', () => {
throw e; throw e;
} }
}); });
});
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({});
@ -76,12 +125,13 @@ describe('Entry filter()', () => {
const ctx = { const ctx = {
args: { args: {
companyFk: 442 companyFk: 442
} },
req: {accessToken: {userId: 9}}
}; };
const result = await models.Entry.filter(ctx, options); const result = await models.Entry.filter(ctx, options);
expect(result.length).toEqual(8); expect(result.length).toEqual(10);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {
@ -98,7 +148,8 @@ describe('Entry filter()', () => {
const ctx = { const ctx = {
args: { args: {
isBooked: true, isBooked: true,
} },
req: {accessToken: {userId: 9}}
}; };
const result = await models.Entry.filter(ctx, options); const result = await models.Entry.filter(ctx, options);
@ -121,7 +172,8 @@ describe('Entry filter()', () => {
args: { args: {
reference: 'movement', reference: 'movement',
travelFk: '2' travelFk: '2'
} },
req: {accessToken: {userId: 9}}
}; };
const result = await models.Entry.filter(ctx, options); const result = await models.Entry.filter(ctx, options);

View File

@ -1,13 +1,70 @@
const UserError = require('vn-loopback/util/user-error');
const models = require('vn-loopback/server/server').models; const models = require('vn-loopback/server/server').models;
describe('entry getBuys()', () => { describe('entry getBuys()', () => {
const entryId = 4; const entryId = 4;
it('should get the buys and items of an entry', async() => { describe('should get the buys and items of an entry ', () => {
it('when is supplier and entry owner', async() => {
const tx = await models.Entry.beginTransaction({}); const tx = await models.Entry.beginTransaction({});
const options = {transaction: tx}; const options = {transaction: tx};
try { try {
const result = await models.Entry.getBuys(entryId, options); const ctx = {
args: {
search: 1
},
req: {accessToken: {userId: 2}}
};
const result = await models.Entry.getBuys(ctx, entryId, options);
const length = result.length;
const anyResult = result[Math.floor(Math.random() * Math.floor(length))];
expect(result.length).toEqual(4);
expect(anyResult.item).toBeDefined();
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('when is supplier but not entry owner', async() => {
const tx = await models.Entry.beginTransaction({});
const options = {transaction: tx};
const entryId = 1;
try {
const ctx = {
args: {
search: 1
},
req: {accessToken: {userId: 1102}}
};
const result = await models.Entry.getBuys(ctx, entryId, options);
expect(result).toBeUndefined();
} catch (error) {
expect(error).toBeInstanceOf(UserError);
expect(error.message).toBe('Access Denied');
}
});
it('when is not supplier', async() => {
const tx = await models.Entry.beginTransaction({});
const options = {transaction: tx};
try {
const ctx = {
args: {
search: 1
},
req: {accessToken: {userId: 9}}
};
const result = await models.Entry.getBuys(ctx, entryId, options);
const length = result.length; const length = result.length;
const anyResult = result[Math.floor(Math.random() * Math.floor(length))]; const anyResult = result[Math.floor(Math.random() * Math.floor(length))];
@ -22,3 +79,4 @@ describe('entry getBuys()', () => {
} }
}); });
}); });
});

View File

@ -79,7 +79,7 @@ describe('Travel extraCommunityFilter()', () => {
const result = await app.models.Travel.extraCommunityFilter(ctx, filter); const result = await app.models.Travel.extraCommunityFilter(ctx, filter);
expect(result.length).toEqual(8); expect(result.length).toEqual(9);
}); });
it('should return the travel matching "cargoSupplierFk"', async() => { it('should return the travel matching "cargoSupplierFk"', async() => {
@ -110,6 +110,6 @@ describe('Travel extraCommunityFilter()', () => {
const result = await app.models.Travel.extraCommunityFilter(ctx, filter); const result = await app.models.Travel.extraCommunityFilter(ctx, filter);
expect(result.length).toEqual(1); expect(result.length).toEqual(2);
}); });
}); });

View File

@ -50,7 +50,7 @@ describe('Travel filter()', () => {
const result = await app.models.Travel.filter(ctx); const result = await app.models.Travel.filter(ctx);
expect(result.length).toEqual(5); expect(result.length).toEqual(6);
}); });
it('should return the routes matching "shipped from" and "shipped to"', async() => { it('should return the routes matching "shipped from" and "shipped to"', async() => {
@ -80,6 +80,6 @@ describe('Travel filter()', () => {
const result = await app.models.Travel.filter(ctx); const result = await app.models.Travel.filter(ctx);
expect(result.length).toEqual(5); expect(result.length).toEqual(6);
}); });
}); });