From 34bcdf1bd33b9c0fcedf64ed0976dc5844efc059 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 18 May 2022 14:01:30 +0200 Subject: [PATCH] test(account): acl, connections and accounts secctions --- back/methods/chat/sendCheckingPresence.js | 2 +- db/dump/fixtures.sql | 4 ++ e2e/helpers/selectors.js | 17 +++++-- e2e/paths/14-account/04_acl.spec.js | 56 +++++---------------- e2e/paths/14-account/05_connections.spec.js | 33 ++++++++++++ e2e/paths/14-account/06_accounts.spec.js | 49 ++++++++++++++++++ 6 files changed, 113 insertions(+), 48 deletions(-) create mode 100644 e2e/paths/14-account/05_connections.spec.js create mode 100644 e2e/paths/14-account/06_accounts.spec.js diff --git a/back/methods/chat/sendCheckingPresence.js b/back/methods/chat/sendCheckingPresence.js index 6560240c6..2217aaee2 100644 --- a/back/methods/chat/sendCheckingPresence.js +++ b/back/methods/chat/sendCheckingPresence.js @@ -46,7 +46,7 @@ module.exports = Self => { const {data} = await Self.getUserStatus(recipient.name); if (data) { - if (data.status === 'offline' || data.status === 'busy') { + if (data.status === 'offline' || data.status === 'busy') { // Send message to department room const workerDepartment = await models.WorkerDepartment.findById(recipientId, { include: { diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index c329e4c6e..0da3a7a31 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2544,3 +2544,7 @@ INSERT INTO `vn`.`supplierAgencyTerm` (`agencyFk`, `supplierFk`, `minimumPackage (3, 2, 0, 15.00, 0.00, NULL, 0, 0.00, 0), (4, 2, 0, 20.00, 0.00, NULL, 0, 0.00, 0), (5, 442, 0, 0.00, 3.05, NULL, 0, 0.00, 0); + +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES + ('UserAccount', '*', '*', 'ALLOW', 'ROLE', 'sysadmin'); diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 343a88f5c..44facb13b 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -103,9 +103,8 @@ export default { }, accountAcl: { addAcl: 'vn-acl-index button vn-icon[icon="add"]', - firstAcl: 'vn-acl-index vn-list:nth-child(1)', - firstAclName: 'vn-acl-index vn-list:nth-child(1) > vn-item-section > h6', - deleteFirstAcl: 'vn-acl-index vn-list:nth-child(1) vn-icon-button[icon="delete"]', + thirdAcl: 'vn-acl-index vn-list> a:nth-child(3)', + deleteThirdAcl: 'vn-acl-index vn-list > a:nth-child(3) > vn-item-section > vn-icon-button[icon="delete"]', role: 'vn-acl-create vn-autocomplete[ng-model="$ctrl.acl.principalId"]', model: 'vn-acl-create vn-autocomplete[ng-model="$ctrl.acl.model"]', property: 'vn-acl-create vn-autocomplete[ng-model="$ctrl.acl.property"]', @@ -113,6 +112,18 @@ export default { permission: 'vn-acl-create vn-autocomplete[ng-model="$ctrl.acl.permission"]', save: 'vn-acl-create vn-submit' }, + accountConnections: { + firstConnection: 'vn-connections vn-list > a:nth-child(1)', + deleteFirstConnection: 'vn-connections vn-list > a:nth-child(1) > vn-item-section > vn-icon-button[icon="exit_to_app"]' + }, + accountAccounts: { + syncRoles: 'vn-account-accounts vn-button[label="Synchronize roles"]', + syncUser: 'vn-account-accounts vn-button[label="Synchronize user"]', + syncAll: 'vn-account-accounts vn-button[label="Synchronize all"]', + syncUserName: 'vn-textfield[ng-model="$ctrl.syncUser"]', + syncUserPassword: 'vn-textfield[ng-model="$ctrl.syncPassword"]', + buttonAccept: 'button[response="accept"]' + }, clientsIndex: { createClientButton: `vn-float-button` }, diff --git a/e2e/paths/14-account/04_acl.spec.js b/e2e/paths/14-account/04_acl.spec.js index f745f8114..f86267d25 100644 --- a/e2e/paths/14-account/04_acl.spec.js +++ b/e2e/paths/14-account/04_acl.spec.js @@ -1,14 +1,14 @@ import selectors from '../../helpers/selectors.js'; import getBrowser from '../../helpers/puppeteer'; -fdescribe('Account ACL path', () => { +describe('Account ACL path', () => { let browser; let page; beforeAll(async() => { browser = await getBrowser(); page = browser.page; - await page.loginAndModule('sysadmin', 'account'); + await page.loginAndModule('developer', 'account'); await page.accessToSection('account.acl'); }); @@ -23,7 +23,7 @@ fdescribe('Account ACL path', () => { it('should create new acl', async() => { await page.autocompleteSearch(selectors.accountAcl.role, 'trainee'); - await page.autocompleteSearch(selectors.accountAcl.model, 'ACL'); + await page.autocompleteSearch(selectors.accountAcl.model, 'Campaign'); await page.autocompleteSearch(selectors.accountAcl.accessType, 'WRITE'); await page.autocompleteSearch(selectors.accountAcl.permission, 'DENY'); await page.waitToClick(selectors.accountAcl.save); @@ -34,11 +34,11 @@ fdescribe('Account ACL path', () => { it('should navigate to edit', async() => { await page.doSearch(); - await page.waitToClick(selectors.accountAcl.firstAcl); + await page.waitToClick(selectors.accountAcl.thirdAcl); await page.waitForState('account.acl.edit'); }); - it('should edit the acl', async() => { + it('should edit the third acl', async() => { await page.autocompleteSearch(selectors.accountAcl.model, 'AccessToken'); await page.autocompleteSearch(selectors.accountAcl.accessType, 'READ'); await page.waitToClick(selectors.accountAcl.save); @@ -47,46 +47,14 @@ fdescribe('Account ACL path', () => { expect(message.text).toContain('Data saved!'); }); - it('should delete the first result', async() => { - const firstResult = await page.waitToGetProperty(selectors.accountAcl.firstAclName, 'value'); - await page.waitToClick(selectors.accountAcl.deleteFirstAcl); - await page.reloadSection('account.acl'); - const newFirstResult = await page.waitToGetProperty(selectors.accountAcl.firstAclName, 'value'); + it('should delete the third result', async() => { + const firstResult = await page.waitToGetProperty(selectors.accountAcl.thirdAcl, 'innerText'); + await page.waitToClick(selectors.accountAcl.deleteThirdAcl); + await page.waitToClick(selectors.globalItems.acceptButton); + const message = await page.waitForSnackbar(); + const newFirstResult = await page.waitToGetProperty(selectors.accountAcl.thirdAcl, 'innerText'); + expect(message.text).toContain('ACL removed'); expect(firstResult).not.toEqual(newFirstResult); }); - /* - it('should check the role description was edited successfully', async() => { - const result = await page.waitToGetProperty(selectors.accountRoleBasicData.description, 'value'); - - expect(result).toContain('psykers'); - }); - - it('should navigate to the subroles section', async() => { - await page.accessToSection('account.role.card.subroles'); - }); - - it('should asign a subrole', async() => { - await page.waitToClick(selectors.accountSubroles.addSubrole); - await page.autocompleteSearch(selectors.accountSubroles.role, 'teamManager'); - await page.waitToClick(selectors.accountSubroles.save); - const message = await page.waitForSnackbar(); - - expect(message.text).toContain('Role added!'); - }); - - it('should reload the subroles section and check a role was added', async() => { - await page.reloadSection('account.role.card.subroles'); - const subrolesCount = await page.countElement(selectors.accountSubroles.anyResult); - - expect(subrolesCount).toEqual(1); - }); - - it('should access the employee roles inheritance then check the roles listed are the expected ones', async() => { - await page.accessToSearchResult('employee'); - await page.accessToSection('account.role.card.inherited'); - const rolesCount = await page.countElement(selectors.accountRoleInheritance.anyResult); - - expect(rolesCount).toEqual(6); - });*/ }); diff --git a/e2e/paths/14-account/05_connections.spec.js b/e2e/paths/14-account/05_connections.spec.js new file mode 100644 index 000000000..e0282639a --- /dev/null +++ b/e2e/paths/14-account/05_connections.spec.js @@ -0,0 +1,33 @@ +import selectors from '../../helpers/selectors.js'; +import getBrowser from '../../helpers/puppeteer'; + +describe('Account Connections path', () => { + let browser; + let page; + const account = 'sysadmin'; + + beforeAll(async() => { + browser = await getBrowser(); + page = browser.page; + await page.loginAndModule(account, 'account'); + await page.accessToSection('account.connections'); + }); + + afterAll(async() => { + await browser.close(); + }); + + it('should check this is the last connection', async() => { + const firstResult = await page.waitToGetProperty(selectors.accountConnections.firstConnection, 'innerText'); + + expect(firstResult).toContain(account); + }); + + it('should kill this connection', async() => { + await page.waitToClick(selectors.accountConnections.deleteFirstConnection); + await page.waitToClick(selectors.globalItems.acceptButton); + const message = await page.waitForSnackbar(); + + expect(message.text).toContain('Your session has expired, please login again'); + }); +}); diff --git a/e2e/paths/14-account/06_accounts.spec.js b/e2e/paths/14-account/06_accounts.spec.js new file mode 100644 index 000000000..eab32c81b --- /dev/null +++ b/e2e/paths/14-account/06_accounts.spec.js @@ -0,0 +1,49 @@ +import selectors from '../../helpers/selectors.js'; +import getBrowser from '../../helpers/puppeteer'; + +describe('Account Connections path', () => { + let browser; + let page; + + beforeAll(async() => { + browser = await getBrowser(); + page = browser.page; + await page.loginAndModule('sysadmin', 'account'); + await page.accessToSection('account.accounts'); + }); + + afterAll(async() => { + await browser.close(); + }); + + it('should sync roles', async() => { + await page.waitToClick(selectors.accountAccounts.syncRoles); + const message = await page.waitForSnackbar(); + + expect(message.text).toContain('Roles synchronized!'); + }); + + it('should sync user', async() => { + await page.waitToClick(selectors.accountAccounts.syncUser); + await page.write(selectors.accountAccounts.syncUserName, 'sysadmin'); + await page.write(selectors.accountAccounts.syncUserPassword, 'nightmare'); + + await page.waitToClick(selectors.accountAccounts.buttonAccept); + + const message = await page.waitForSnackbar(); + + expect(message.text).toContain('User synchronized!'); + }); + + it('should relogin', async() => { + await page.loginAndModule('sysadmin', 'account'); + await page.accessToSection('account.accounts'); + }); + + it('should sync all', async() => { + await page.waitToClick(selectors.accountAccounts.syncAll); + const message = await page.waitForSnackbar(); + + expect(message.text).toContain('Synchronizing in the background'); + }); +});