From ca1f5480ae5d8d31888effac8e2cba58e0f9da6c Mon Sep 17 00:00:00 2001 From: alexandre Date: Wed, 22 Feb 2023 13:04:27 +0100 Subject: [PATCH] refs #5235 added setClientSample(), fixed tests --- modules/client/front/sample/create/index.js | 19 +++++++++---------- .../client/front/sample/create/index.spec.js | 8 ++++++-- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/modules/client/front/sample/create/index.js b/modules/client/front/sample/create/index.js index 13ef875da..b25bf7919 100644 --- a/modules/client/front/sample/create/index.js +++ b/modules/client/front/sample/create/index.js @@ -5,10 +5,6 @@ import './style.scss'; class Controller extends Section { constructor($element, $, vnEmail) { super($element, $); - this.clientSample = { - clientFk: this.$params.id, - companyId: this.vnConfig.companyFk - }; this.vnEmail = vnEmail; } @@ -19,10 +15,8 @@ class Controller extends Section { set client(value) { this._client = value; - if (value) { - this.clientSample.recipient = value.email; - this.getWorkerEmail(); - } + if (value) + this.setClientSample(value); } get companyId() { @@ -119,12 +113,17 @@ class Controller extends Section { .then(() => this.$state.go('client.card.sample.index')); } - getWorkerEmail() { + setClientSample(client) { const userId = window.localStorage.currentUserWorkerId; const params = {filter: {where: {userFk: userId}}}; this.$http.get('EmailUsers', params).then(res => { const [worker] = res && res.data; - this.clientSample.replyTo = worker.email; + this.clientSample = { + clientFk: this.$params.id, + companyId: this.vnConfig.companyFk, + recipient: client.email, + replyTo: worker.email + }; }); } } diff --git a/modules/client/front/sample/create/index.spec.js b/modules/client/front/sample/create/index.spec.js index 8e33a1075..ecaf038fa 100644 --- a/modules/client/front/sample/create/index.spec.js +++ b/modules/client/front/sample/create/index.spec.js @@ -191,15 +191,19 @@ describe('Client', () => { }); }); - describe('getWorkerEmail()', () => { + describe('setClientSample()', () => { it(`should perform a query and then set the replyTo property to the clientSample object`, () => { + const client = {email: 'test@example.com'}; const expectedEmail = 'batman@arkhamcity.com'; const serializedParams = $httpParamSerializer({filter: {where: {}}}); $httpBackend.expect('GET', `EmailUsers?${serializedParams}`).respond([{email: expectedEmail}]); - controller.getWorkerEmail(); + controller.setClientSample(client); $httpBackend.flush(); expect(controller.clientSample.replyTo).toEqual(expectedEmail); + expect(controller.clientSample.clientFk).toEqual(controller.$params.id); + expect(controller.clientSample.recipient).toEqual(client.email); + expect(controller.clientSample.companyId).toEqual(controller.vnConfig.companyFk); }); }); });