76 lines
2.2 KiB
JavaScript
76 lines
2.2 KiB
JavaScript
const models = require('vn-loopback/server/server').models;
|
|
|
|
describe('zone includingExpired()', () => {
|
|
const inhousePickupId = 1;
|
|
const addressId = 101;
|
|
const warehouseId = 1;
|
|
|
|
it('should return an array containing all zones', async() => {
|
|
const tx = await models.Zone.beginTransaction({});
|
|
const ctx = {req: {accessToken: {userId: 1}}};
|
|
const where = {};
|
|
|
|
try {
|
|
const options = {transaction: tx};
|
|
|
|
const result = await models.Zone.includingExpired(ctx, {where}, options);
|
|
|
|
expect(result.length).toBeGreaterThan(2);
|
|
|
|
await tx.rollback();
|
|
} catch (e) {
|
|
await tx.rollback();
|
|
throw e;
|
|
}
|
|
});
|
|
|
|
it('should return an array containing zones from the agencyMode "Inhouse pickup"', async() => {
|
|
const ctx = {req: {accessToken: {userId: 1}}};
|
|
const where = {agencyModeFk: inhousePickupId};
|
|
|
|
const tx = await models.Zone.beginTransaction({});
|
|
|
|
try {
|
|
const options = {transaction: tx};
|
|
|
|
const result = await models.Zone.includingExpired(ctx, {where}, options);
|
|
|
|
const validAgency = result.every(zone => zone.agencyModeFk = inhousePickupId);
|
|
|
|
expect(result.length).toEqual(3);
|
|
expect(validAgency).toBeTruthy();
|
|
|
|
await tx.rollback();
|
|
} catch (e) {
|
|
await tx.rollback();
|
|
throw e;
|
|
}
|
|
});
|
|
|
|
it('should return an array containing available zones', async() => {
|
|
const ctx = {req: {accessToken: {userId: 1}}};
|
|
const where = {
|
|
shipped: Date.vnNew(),
|
|
addressFk: addressId,
|
|
agencyModeFk: inhousePickupId,
|
|
warehouseFk: warehouseId
|
|
};
|
|
|
|
const tx = await models.Zone.beginTransaction({});
|
|
|
|
try {
|
|
const options = {transaction: tx};
|
|
|
|
const result = await models.Zone.includingExpired(ctx, {where}, options);
|
|
const firstZone = result[0];
|
|
|
|
expect(firstZone.name).toEqual('Zone pickup A');
|
|
|
|
await tx.rollback();
|
|
} catch (e) {
|
|
await tx.rollback();
|
|
throw e;
|
|
}
|
|
});
|
|
});
|