refs #5858 test: execute test

This commit is contained in:
Javier Segarra 2023-12-19 12:57:10 +01:00
parent 243319b113
commit 38a5337f68
1 changed files with 48 additions and 0 deletions

View File

@ -30,11 +30,59 @@ describe('zone deletezone()', () => {
} }
}); });
it('should NOT delete a zone if is included', async() => {
const tx = await models.Zone.beginTransaction({});
let isIncluded = false;
try {
const options = {transaction: tx};
const zoneIncluded = await models.ZoneIncluded.find({where: {zoneFk: zoneId}});
isIncluded = zoneIncluded.length > 0;
await models.Zone.deleteZone(ctx, zoneId, options);
} catch (e) {
expect(isIncluded).toBeTrue();
expect(e).not.toBeNull();
await tx.rollback();
}
});
it('should NOT delete a zone if is included check', async() => {
const tx = await models.Zone.beginTransaction({});
let isIncluded = false;
try {
const options = {transaction: tx};
const zoneIncludedCheck = await models.ZoneIncludedCheck.find({where: {zoneFk: zoneId}});
isIncluded = zoneIncludedCheck.length > 0;
await models.Zone.deleteZone(ctx, zoneId, options);
} catch (e) {
expect(isIncluded).toBeTrue();
expect(e).not.toBeNull();
await tx.rollback();
}
});
it('should delete a zone and update their tickets', async() => { it('should delete a zone and update their tickets', async() => {
const tx = await models.Zone.beginTransaction({}); const tx = await models.Zone.beginTransaction({});
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
const zoneIncluded = await models.ZoneIncluded.find({where: {zoneFk: zoneId}}, options);
await models.ZoneIncluded.destroyById(zoneIncluded[0].id, options);
const zoneIncludedDeleted = await models.ZoneIncluded.find({where: {zoneFk: zoneId}}, options);
expect(zoneIncludedDeleted.length).toEqual(0);
const zoneIncludedCheck = await models.ZoneIncludedCheck.find({where: {zoneFk: zoneId}}, options);
expect(zoneIncludedCheck.length).toEqual(2);
// Insert
await models.ZoneIncludedCheck.destroyById(zoneIncludedCheck[0].id, options);
// Delete
await models.ZoneIncludedCheck.destroyById(zoneIncludedCheck[1].id, options);
const zoneIncludedCheckDeleted = await models.ZoneIncludedCheck.find({where: {zoneFk: zoneId}}, options);
expect(zoneIncludedCheckDeleted.length).toEqual(0);
await models.Zone.deleteZone(ctx, zoneId, options); await models.Zone.deleteZone(ctx, zoneId, options);
const updatedZone = await models.Zone.findById(zoneId, null, options); const updatedZone = await models.Zone.findById(zoneId, null, options);