diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index 2b2078fc2..e4d6c4bd1 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -128,9 +128,6 @@ jobs: export OC_PASS=1234561 php occ user:add --password-from-env user1 php occ user:add --password-from-env user2 - ./occ group:add shareTestGroup - ./occ group:adduser shareTestGroup user1 - ./occ group:adduser shareTestGroup user2 curl -v http://127.0.0.1:8081/index.php/login cat data/nextcloud.log diff --git a/cypress/e2e/tables-unified-search.cy.js b/cypress/e2e/tables-unified-search.cy.js index d701b94bb..4b8f5d692 100644 --- a/cypress/e2e/tables-unified-search.cy.js +++ b/cypress/e2e/tables-unified-search.cy.js @@ -1,14 +1,20 @@ let localUser let localUser2 +const groupId = (Math.random() + 1).toString(36).substring(7) describe('The Home Page', () => { before(function() { + cy.createGroup(groupId) cy.createRandomUser().then(user => { localUser = user + }).then(user => { + cy.addUserToGroup(user.userId, groupId) }) cy.createRandomUser().then(user => { localUser2 = user + }).then(user => { + cy.addUserToGroup(user.userId, groupId) }) }) @@ -75,7 +81,7 @@ describe('The Home Page', () => { }) it('Search for shared table via group share', () => { - cy.login({ userId: 'user1', password: '1234561' }) + cy.login(localUser) cy.visit('apps/tables') // create table to share @@ -86,19 +92,19 @@ describe('The Home Page', () => { cy.clickOnTableThreeDotMenu('Share') cy.intercept({ method: 'GET', url: '**/ocs/v2.php/apps/files_sharing/api/v1/sharees*' }).as('searchShareUsers') - cy.get('.sharing input').type('shareTestGroup') + cy.get('.sharing input').type(groupId) cy.wait('@searchShareUsers') cy.get('.sharing input').type('{enter}') - cy.get('h3').contains('Shares').parent().find('ul').contains('shareTestGroup').should('exist') + cy.get('h3').contains('Shares').parent().find('ul').contains(groupId).should('exist') - cy.login({ userId: 'user2', password: '1234561' }) + cy.login(localUser2) cy.visit('apps/tables') cy.unifiedSearch('Share for group') }) it('Search for shared view via group share', () => { - cy.login({ userId: 'user1', password: '1234561' }) + cy.login(localUser) cy.visit('apps/tables') // create table to share @@ -110,13 +116,13 @@ describe('The Home Page', () => { cy.clickOnTableThreeDotMenu('Share') cy.intercept({ method: 'GET', url: '**/ocs/v2.php/apps/files_sharing/api/v1/sharees*' }).as('searchShareUsers') - cy.get('.sharing input').type('shareTestGroup') + cy.get('.sharing input').type(groupId) cy.wait('@searchShareUsers') cy.get('.sharing input').type('{enter}') - cy.get('h3').contains('Shares').parent().find('ul').contains('shareTestGroup').should('exist') + cy.get('h3').contains('Shares').parent().find('ul').contains(groupId).should('exist') - cy.login({ userId: 'user2', password: '1234561' }) + cy.login(localUser2) cy.visit('apps/tables') cy.unifiedSearch('ShareView2') }) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 3b4af9e59..365af6e81 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -26,6 +26,7 @@ import { addCommands } from '@nextcloud/cypress' const url = Cypress.config('baseUrl').replace(/\/index.php\/?$/g, '') +Cypress.env('baseUrl', url) addCommands() @@ -156,3 +157,40 @@ Cypress.Commands.add('uploadFile', (fileName, mimeType, target) => { }) }) }) + +Cypress.Commands.add('ocsRequest', (user, options) => { + const auth = { user: user.userId, password: user.password } + return cy.request({ + form: true, + auth, + headers: { + 'OCS-ApiRequest': 'true', + 'Content-Type': 'application/x-www-form-urlencoded', + }, + ...options, + }) +}) +Cypress.Commands.add('createGroup', (groupName) => { + cy.ocsRequest({ userId: 'admin', password: 'admin' }, { + method: 'POST', + url: `${url}/ocs/v2.php/cloud/groups`, + body: { + groupid: groupName, + displayname: groupName, + }, + }).then(response => { + cy.log(`Group ${groupName} created.`, response.status) + }) +}) + +Cypress.Commands.add('addUserToGroup', (userId, groupId) => { + cy.ocsRequest({ userId: 'admin', password: 'admin' }, { + method: 'POST', + url: `${url}/ocs/v2.php/cloud/users/${userId}/groups`, + body: { + groupid: groupId, + }, + }).then(response => { + cy.log(`User ${userId} added to group ${groupId}.`, response.status) + }) +})