From b7e3e9fa713bbfb120a4dd3bc493e77693217078 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 23 May 2023 13:08:10 +0200 Subject: [PATCH] refs #5468 feat: add testBack --- .../account/specs/add-mail-alias.spec.js | 26 ++++++++++++++ .../specs/change-mail-forwarding.spec.js | 35 +++++++++++++++++++ .../account/specs/delete-mail-alias.spec.js | 24 +++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 modules/account/back/methods/account/specs/add-mail-alias.spec.js create mode 100644 modules/account/back/methods/account/specs/change-mail-forwarding.spec.js create mode 100644 modules/account/back/methods/account/specs/delete-mail-alias.spec.js diff --git a/modules/account/back/methods/account/specs/add-mail-alias.spec.js b/modules/account/back/methods/account/specs/add-mail-alias.spec.js new file mode 100644 index 000000000..bb59719cd --- /dev/null +++ b/modules/account/back/methods/account/specs/add-mail-alias.spec.js @@ -0,0 +1,26 @@ +const {models} = require('vn-loopback/server/server'); + +describe('Account addMailAlias()', () => { + it('should throw an error when the user is not a superior', async() => { + const ctx = {req: {accessToken: {userId: 1}}}; + const employeeId = 1; + + let error; + try { + await models.Account.addMailAlias(ctx, employeeId, 1); + } catch (e) { + error = e.message; + } + + expect(error).toEqual(`You don't have enough privileges`); + }); + + it('should add a mail alias', async() => { + const ctx = {req: {accessToken: {userId: 9}}}; + const employeeId = 1; + + const result = await models.Account.addMailAlias(ctx, employeeId, 2); + + expect(result).toBeDefined(); + }); +}); diff --git a/modules/account/back/methods/account/specs/change-mail-forwarding.spec.js b/modules/account/back/methods/account/specs/change-mail-forwarding.spec.js new file mode 100644 index 000000000..ba1a80806 --- /dev/null +++ b/modules/account/back/methods/account/specs/change-mail-forwarding.spec.js @@ -0,0 +1,35 @@ +const {models} = require('vn-loopback/server/server'); + +describe('Account changeMailForwarding()', () => { + it('should throw an error when the user is not himself or a superior', async() => { + const ctx = {req: {accessToken: {userId: 1}}}; + const developerId = 9; + + let error; + try { + await models.Account.changeMailForwarding(ctx, developerId, 'alias@test.test'); + } catch (e) { + error = e.message; + } + + expect(error).toEqual(`You don't have enough privileges`); + }); + + it('should change a mail forwarding when the user is himself', async() => { + const ctx = {req: {accessToken: {userId: 1}}}; + const employeeId = 1; + + const result = await models.Account.changeMailForwarding(ctx, employeeId, 'alias@test.test'); + + expect(result).toBeDefined(); + }); + + it('should change a mail forwarding when the user is a superior', async() => { + const ctx = {req: {accessToken: {userId: 9}}}; + const employeeId = 1; + + const result = await models.Account.changeMailForwarding(ctx, employeeId, 'alias@test.test'); + + expect(result).toBeDefined(); + }); +}); diff --git a/modules/account/back/methods/account/specs/delete-mail-alias.spec.js b/modules/account/back/methods/account/specs/delete-mail-alias.spec.js new file mode 100644 index 000000000..fb69fe9c9 --- /dev/null +++ b/modules/account/back/methods/account/specs/delete-mail-alias.spec.js @@ -0,0 +1,24 @@ +const {models} = require('vn-loopback/server/server'); + +describe('Account deleteMailAlias()', () => { + it('should throw an error when the user is not a superior', async() => { + const ctx = {req: {accessToken: {userId: 1}}}; + + let error; + try { + await models.Account.deleteMailAlias(ctx, 1); + } catch (e) { + error = e.message; + } + + expect(error).toEqual(`You don't have enough privileges`); + }); + + it('should delete a mail alias', async() => { + const ctx = {req: {accessToken: {userId: 9}}}; + + const result = await models.Account.deleteMailAlias(ctx, 1); + + expect(result).toBeDefined(); + }); +});