#5858 - zoneCollisions #1853

Merged
jsegarra merged 78 commits from 5858-zone_Collisions into dev 2024-03-15 12:36:38 +00:00
1 changed files with 27 additions and 3 deletions
Showing only changes of commit dddd482317 - Show all commits

View File

@ -1,6 +1,6 @@
const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('zone toggleIsIncluded()', () => {
fdescribe('zone toggleIsIncluded()', () => {
beforeAll(async() => {
const activeCtx = {
accessToken: {userId: 9},
@ -20,10 +20,12 @@ describe('zone toggleIsIncluded()', () => {
try {
const options = {transaction: tx};
await validateSchedules('before', options);
let result = await models.Zone.toggleIsIncluded(1, 20, true, options);
expect(result.isIncluded).toBeTrue();
await validateSchedules('after', options);
await tx.rollback();
} catch (e) {
@ -37,10 +39,12 @@ describe('zone toggleIsIncluded()', () => {
try {
const options = {transaction: tx};
await validateSchedules('before', options);
let result = await models.Zone.toggleIsIncluded(1, 20, false, options);
expect(result.isIncluded).toBeFalse();
await validateSchedules('after', options);
await tx.rollback();
} catch (e) {
@ -54,13 +58,14 @@ describe('zone toggleIsIncluded()', () => {
try {
const options = {transaction: tx};
await validateSchedules('before', options);
await models.Zone.toggleIsIncluded(1, 20, false, options);
let result = await models.Zone.toggleIsIncluded(1, 20, undefined, options);
const result = await models.Zone.toggleIsIncluded(1, 20, undefined, options);
expect(result).toEqual({count: 1});
await validateSchedules('after', options);
await tx.rollback();
} catch (e) {
await tx.rollback();
@ -68,3 +73,22 @@ describe('zone toggleIsIncluded()', () => {
}
});
});
async function validateSchedules(step, options = null) {
const querySchedules = `SELECT count(*) count FROM util.vn_schedules;`;
switch (step) {
case 'before': {
const [{count}] = await models.Application.rawSql(querySchedules, null, options);
expect(count).toEqual(0);
}
break;
case 'after': {
const [{count}] = await models.Application.rawSql(querySchedules, null, options);
expect(count).toEqual(1);
}
break;
}
}