fix: refs #7917 userId tests
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Carlos Satorres 2024-12-03 13:38:55 +01:00
parent 223ccb9a9a
commit 80e8071ae0
2 changed files with 20 additions and 2 deletions

View File

@ -83,7 +83,7 @@ module.exports = Self => {
filter = mergeFilters(ctx.args?.filter ?? {}, {where}); filter = mergeFilters(ctx.args?.filter ?? {}, {where});
const getRouteByAgency = await models.ACL.checkAccessAcl(ctx, 'Route', 'getRouteByAgency', 'WRITE'); const getRouteByAgency = await models.ACL.checkAccessAcl(ctx, 'Route', 'getRouteByAgency', 'WRITE');
const supplier = await models.Supplier.isSupplier(ctx.req.accessToken.userId, myOptions); const supplier = await models.Supplier.isSupplier(userId, myOptions);
if (supplier && getRouteByAgency) { if (supplier && getRouteByAgency) {
if (!filter.where) filter.where = {}; if (!filter.where) filter.where = {};
filter.where[`a.supplierFk`] = supplier.id; filter.where[`a.supplierFk`] = supplier.id;

View File

@ -1,6 +1,6 @@
const app = require('vn-loopback/server/server'); const app = require('vn-loopback/server/server');
describe('route getTickets()', () => { fdescribe('route getTickets()', () => {
const ctx = beforeAll.getCtx(); const ctx = beforeAll.getCtx();
it('should return the tickets for a given route', async() => { it('should return the tickets for a given route', async() => {
@ -9,4 +9,22 @@ describe('route getTickets()', () => {
expect(result.length).toEqual(1); expect(result.length).toEqual(1);
}); });
it('should return only routes belonging to the supplier', async() => {
const filter = {}; // No especificamos un filtro específico, se debería aplicar el de supplier automáticamente
// Mock para simular que el usuario es un supplier específico
spyOn(app.models.Supplier, 'isSupplier').and.returnValue({
id: 1101 // ID del proveedor ficticio
});
let result = await app.models.Route.getTickets(ctx, filter, options);
console.log('ctx: ', ctx);
// Verifica que todas las rutas pertenecen al proveedor simulado
expect(result.length).toBeGreaterThan(0);
// result.forEach(route => {
// expect(route.supplierFk).toEqual(123); // Asegúrate de comparar con el campo adecuado
// });
});
}); });