Updated tests
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2020-09-23 11:21:25 +02:00
parent ae3d00bad1
commit 5ec5979a3e
9 changed files with 135 additions and 42 deletions

View File

@ -50,7 +50,7 @@ describe('Ticket Edit basic data path', () => {
});
it(`should edit the ticket agency then check there are no zones for it`, async() => {
await page.autocompleteSearch(selectors.ticketBasicData.agency, 'Entanglement');
await page.autocompleteSearch(selectors.ticketBasicData.agency, 'inhouse pickup');
await page.waitFor(1000);
let emptyZone = await page
.expectPropertyValue(selectors.ticketBasicData.zone, 'value', '');
@ -59,6 +59,7 @@ describe('Ticket Edit basic data path', () => {
});
it(`should edit the ticket zone then check the agency is for the new zone`, async() => {
await page.clearInput(selectors.ticketBasicData.agency);
await page.autocompleteSearch(selectors.ticketBasicData.zone, 'Zone expensive A');
let zone = await page
.waitToGetProperty(selectors.ticketBasicData.agency, 'value');

View File

@ -66,7 +66,7 @@
show-field="name"
value-field="id"
ng-model="$ctrl.agencyModeId"
where="{warehouseFk: $ctrl.warehouseId}">
where-function="$ctrl.agencyModeWhere()">
</vn-autocomplete>
<vn-autocomplete
vn-one

View File

@ -58,12 +58,6 @@ class Controller extends Component {
this.ticket.warehouseFk = value;
this.ticket.agencyModeFk = null;
this.ticket.zoneFk = null;
/* this.getShipped({
landed: this.ticket.landed,
addressFk: this.ticket.addressFk,
agencyModeFk: this.ticket.agencyModeFk,
warehouseFk: value
}); */
}
}
@ -77,8 +71,7 @@ class Controller extends Component {
shipped: value,
addressFk: this.ticket.addressFk,
agencyModeFk: this.ticket.agencyModeFk,
warehouseFk: this.ticket.warehouseFk,
showExpiredZones: false
warehouseFk: this.ticket.warehouseFk
});
}
@ -103,12 +96,14 @@ class Controller extends Component {
set agencyModeId(value) {
if (value != this.ticket.agencyModeFk) {
this.ticket.agencyModeFk = value;
if (!value) return;
this.getLanded({
shipped: this.ticket.shipped,
addressFk: this.ticket.addressFk,
agencyModeFk: value,
warehouseFk: this.ticket.warehouseFk,
showExpiredZones: false
warehouseFk: this.ticket.warehouseFk
});
}
}
@ -255,6 +250,15 @@ class Controller extends Component {
}
return {};
}
agencyModeWhere() {
if (this.warehouseId) {
return {
warehouseFk: this.warehouseId
};
}
return {};
}
}
ngModule.vnComponent('vnTicketBasicDataStepOne', {

View File

@ -94,16 +94,7 @@ describe('Ticket', () => {
jest.spyOn(controller, 'getShipped');
controller.ticket.warehouseId = 1;
controller.warehouseId = 2;
const landed = new Date();
const expectedResult = {
landed: landed,
addressFk: 121,
agencyModeFk: 7,
warehouseFk: 2
};
controller.landed = landed;
expect(controller.getShipped).toHaveBeenCalledWith(expectedResult);
expect(controller.ticket.warehouseFk).toEqual(2);
});
});
@ -125,7 +116,6 @@ describe('Ticket', () => {
shipped: shipped,
addressFk: 121,
agencyModeFk: 7,
showExpiredZones: false,
warehouseFk: 1
};
controller.shipped = shipped;
@ -176,8 +166,7 @@ describe('Ticket', () => {
shipped: shipped,
addressFk: 121,
agencyModeFk: agencyModeId,
warehouseFk: 1,
showExpiredZones: false,
warehouseFk: 1
};
controller.ticket.shipped = shipped;
controller.agencyModeId = 8;
@ -363,5 +352,31 @@ describe('Ticket', () => {
expect(controller.landed).toEqual(landed);
});
});
describe('zoneWhere() getter', () => {
it('should return an object containing filter properties', async() => {
const shipped = new Date();
controller.ticket.shipped = shipped;
const expectedResult = {
addressFk: 121,
agencyModeFk: 7,
shipped: shipped,
warehouseFk: 1
};
const result = controller.zoneWhere();
expect(result).toEqual(expect.objectContaining(expectedResult));
});
});
describe('agencyModeWhere() getter', () => {
it('should return an object containing the warehouseFk property', async() => {
const expectedResult = {warehouseFk: 1};
const result = controller.agencyModeWhere();
expect(result).toEqual(expect.objectContaining(expectedResult));
});
});
});
});

View File

@ -0,0 +1,21 @@
const app = require('vn-loopback/server/server');
describe('AgencyMode byWarehhouse()', () => {
const warehouseId = 1;
it('should return all the agencies', async() => {
const where = {};
const agencies = await app.models.AgencyMode.byWarehouse({where});
expect(agencies.length).toBeGreaterThan(10);
});
it('should return only the agencies for a warehouse', async() => {
const where = {warehouseFk: warehouseId};
const agencies = await app.models.AgencyMode.byWarehouse({where});
const validWarehouse = agencies.every(agency => agency.warehouseFk = warehouseId);
expect(agencies.length).toEqual(6);
expect(validWarehouse).toBeTruthy();
});
});

View File

@ -1,7 +1,7 @@
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
module.exports = Self => {
Self.remoteMethod('getLanded', {
Self.remoteMethodCtx('getLanded', {
description: 'Returns the first shipped and landed possible for params',
accessType: 'READ',
accepts: [{
@ -23,11 +23,6 @@ module.exports = Self => {
arg: 'warehouseFk',
type: 'number',
required: true
},
{
arg: 'showExpiredZones',
type: 'boolean',
required: true
}],
returns: {
type: 'object',
@ -39,7 +34,13 @@ module.exports = Self => {
}
});
Self.getLanded = async(shipped, addressFk, agencyModeFk, warehouseFk, showExpiredZones) => {
Self.getLanded = async(ctx, shipped, addressFk, agencyModeFk, warehouseFk) => {
const userId = ctx.req.accessToken.userId;
const models = Self.app.models;
const isProductionBoss = await models.Account.hasRole(userId, 'productionBoss');
let showExpired = false;
if (isProductionBoss) showExpired = true;
let stmts = [];
stmts.push(new ParameterizedSQL(
`CALL vn.zone_getLanded(?, ?, ?, ?, ?)`, [
@ -47,7 +48,7 @@ module.exports = Self => {
addressFk,
agencyModeFk,
warehouseFk,
showExpiredZones
showExpired
]
));

View File

@ -2,13 +2,13 @@ const app = require('vn-loopback/server/server');
describe('agency getLanded()', () => {
it('should return a landing date', async() => {
const ctx = {req: {accessToken: {userId: 1}}};
const shipped = new Date();
shipped.setDate(shipped.getDate() + 1);
const addressFk = 121;
const agencyModeFk = 7;
const warehouseFk = 1;
const showExpiredZones = true;
let result = await app.models.Agency.getLanded(shipped, addressFk, agencyModeFk, warehouseFk, showExpiredZones);
let result = await app.models.Agency.getLanded(ctx, shipped, addressFk, agencyModeFk, warehouseFk);
expect(result.landed).toBeDefined();
});

View File

@ -2,7 +2,7 @@ const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
module.exports = Self => {
Self.remoteMethod('includingExpired', {
Self.remoteMethodCtx('includingExpired', {
description: 'Returns a list of agencies from a warehouse',
accepts: [{
arg: 'filter',
@ -19,33 +19,44 @@ module.exports = Self => {
}
});
Self.includingExpired = async filter => {
Self.includingExpired = async(ctx, filter) => {
const userId = ctx.req.accessToken.userId;
const conn = Self.dataSource.connector;
const models = Self.app.models;
const where = filter.where;
// filter = mergeFilters(filter, {where});
const stmts = [];
let stmt;
console.log(where);
const filterByAvailability = where.shipped && where.addressFk
&& where.agencyModeFk && where.warehouseFk;
if (filterByAvailability) {
const isProductionBoss = await models.Account.hasRole(userId, 'productionBoss');
let showExpired = false;
if (isProductionBoss) showExpired = true;
if (where.agencyModeFk) {
stmt = new ParameterizedSQL(`CALL vn.zone_getLanded(?, ?, ?, ?, ?)`, [
where.shipped,
where.addressFk,
where.agencyModeFk,
where.warehouseFk,
true]);
showExpired]);
stmts.push(stmt);
}
delete where.shipped;
delete where.addressFk;
delete where.warehouseFk;
stmt = new ParameterizedSQL(
`SELECT id, name, agencyModeFk
FROM vn.zone z`);
if (where.agencyModeFk)
if (filterByAvailability)
stmt.merge(`JOIN tmp.zoneGetLanded zgl ON zgl.zoneFk = z.id`);
stmt.merge(conn.makePagination(filter));
stmt.merge(conn.makeWhere(filter.where));
let index;
if (stmts.length)

View File

@ -0,0 +1,40 @@
const app = require('vn-loopback/server/server');
describe('zone includingExpired()', () => {
const inhousePickupId = 1;
const addressId = 101;
const warehouseId = 1;
it('should return an array containing all zones', async() => {
const ctx = {req: {accessToken: {userId: 1}}};
const where = {};
const result = await app.models.Zone.includingExpired(ctx, {where});
expect(result.length).toBeGreaterThan(2);
});
it('should return an array containing zones from the agencyMode "Inhouse pickup"', async() => {
const ctx = {req: {accessToken: {userId: 1}}};
const where = {agencyModeFk: inhousePickupId};
const result = await app.models.Zone.includingExpired(ctx, {where});
const validAgency = result.every(zone => zone.agencyModeFk = inhousePickupId);
expect(result.length).toEqual(3);
expect(validAgency).toBeTruthy();
});
it('should return an array containing available zones', async() => {
const ctx = {req: {accessToken: {userId: 1}}};
const where = {
shipped: new Date(),
addressFk: addressId,
agencyModeFk: inhousePickupId,
warehouseFk: warehouseId
};
const result = await app.models.Zone.includingExpired(ctx, {where});
const firstZone = result[0];
expect(firstZone.name).toEqual('Zone pickup A');
});
});