From 59ea47a8c33acf5d4de6beea36a46eeb9248c282 Mon Sep 17 00:00:00 2001 From: carlossa Date: Fri, 16 Feb 2024 13:06:33 +0100 Subject: [PATCH 1/2] refs #6414 tback --- .../back/methods/worker/specs/new.spec.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/modules/worker/back/methods/worker/specs/new.spec.js b/modules/worker/back/methods/worker/specs/new.spec.js index d0830b00f..f5deb86ef 100644 --- a/modules/worker/back/methods/worker/specs/new.spec.js +++ b/modules/worker/back/methods/worker/specs/new.spec.js @@ -36,6 +36,26 @@ describe('Worker new', () => { payMethodFk: 1, roleFk: 1 }; + + const clientWorker = { + fi: '09412983A', + name: 'CLIENTWORKER', + firstName: 'CLIENT', + lastNames: 'WORKER', + email: 'clientWorker@mydomain.com', + street: 'S/ DEFAULTWORKERSTREET', + city: 'defaultWorkerCity', + provinceFk: 1, + companyFk: 442, + postcode: '46680', + phone: '123456489', + code: 'CCW', + bossFk: 9, + birth: '2022-12-11T23:00:00.000Z', + payMethodFk: 1, + roleFk: 1 + }; + const req = {accessToken: {userId: 9}}; it('should return error if personal mail already exists', async() => { @@ -149,6 +169,18 @@ describe('Worker new', () => { expect(newWorker.id).toBeDefined(); }); + it('should create a new client', async() => { + const newWorker = await models.Worker.new({args: clientWorker, req}); + + await models.Worker.destroyById(newWorker.id); + await models.Address.destroyAll({clientFk: newWorker.id}); + await models.Mandate.destroyAll({clientFk: newWorker.id}); + await models.Client.destroyById(newWorker.id); + await models.VnUser.destroyById(newWorker.id); + + expect(newWorker.id).toBeDefined(); + }); + it('should create a new worker in client', async() => { const bruceWayneId = 1101; const client = await models.Client.findById(bruceWayneId, {fields: ['fi', 'email']}); From f3511d4a43b010e273668a861fa84d994d95b94b Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 20 Feb 2024 09:53:28 +0100 Subject: [PATCH 2/2] refs #6414 tback --- .../back/methods/worker/specs/new.spec.js | 50 +++++++------------ 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/modules/worker/back/methods/worker/specs/new.spec.js b/modules/worker/back/methods/worker/specs/new.spec.js index f5deb86ef..1f74e9b95 100644 --- a/modules/worker/back/methods/worker/specs/new.spec.js +++ b/modules/worker/back/methods/worker/specs/new.spec.js @@ -37,25 +37,6 @@ describe('Worker new', () => { roleFk: 1 }; - const clientWorker = { - fi: '09412983A', - name: 'CLIENTWORKER', - firstName: 'CLIENT', - lastNames: 'WORKER', - email: 'clientWorker@mydomain.com', - street: 'S/ DEFAULTWORKERSTREET', - city: 'defaultWorkerCity', - provinceFk: 1, - companyFk: 442, - postcode: '46680', - phone: '123456489', - code: 'CCW', - bossFk: 9, - birth: '2022-12-11T23:00:00.000Z', - payMethodFk: 1, - roleFk: 1 - }; - const req = {accessToken: {userId: 9}}; it('should return error if personal mail already exists', async() => { @@ -160,25 +141,22 @@ describe('Worker new', () => { it('should create a new worker', async() => { const newWorker = await models.Worker.new({args: defaultWorker, req}); - await models.Worker.destroyById(newWorker.id); - await models.Address.destroyAll({clientFk: newWorker.id}); - await models.Mandate.destroyAll({clientFk: newWorker.id}); - await models.Client.destroyById(newWorker.id); - await models.VnUser.destroyById(newWorker.id); + await removeWorker(newWorker.id); expect(newWorker.id).toBeDefined(); }); it('should create a new client', async() => { - const newWorker = await models.Worker.new({args: clientWorker, req}); + let newWorker; + let client; + try { + newWorker = await models.Worker.new({args: defaultWorker, req}); + client = await models.Client.findById(newWorker.id); + } finally { + await removeWorker(newWorker.id); + } - await models.Worker.destroyById(newWorker.id); - await models.Address.destroyAll({clientFk: newWorker.id}); - await models.Mandate.destroyAll({clientFk: newWorker.id}); - await models.Client.destroyById(newWorker.id); - await models.VnUser.destroyById(newWorker.id); - - expect(newWorker.id).toBeDefined(); + expect(client).toBeDefined(); }); it('should create a new worker in client', async() => { @@ -202,3 +180,11 @@ describe('Worker new', () => { expect(newWorker.id).toEqual(bruceWayneId); }); }); + +async function removeWorker(id) { + await models.Worker.destroyById(id); + await models.Address.destroyAll({clientFk: id}); + await models.Mandate.destroyAll({clientFk: id}); + await models.Client.destroyById(id); + await models.VnUser.destroyById(id); +}