From dddd482317132011497ffc0f5008266d322829d0 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 21 Feb 2024 14:22:19 +0100 Subject: [PATCH] refs #5858 test: check vn_schedules --- .../zone/specs/toggleIsIncluded.spec.js | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js b/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js index 86c04f844..ccd1abb80 100644 --- a/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js +++ b/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js @@ -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; + } +}