Skip to content

Commit

Permalink
fix(ci): use independent users for cypress tests (#550)
Browse files Browse the repository at this point in the history
* make use of dev setup default user
- this allows to run the tests locally and in CI with the same setup

Signed-off-by: Florian Steffens <florian.steffens@nextcloud.com>

* add a script to setup local requirements

Signed-off-by: Florian Steffens <florian.steffens@nextcloud.com>

* refactor(test): use independent users for testing

Signed-off-by: Florian Steffens <florian.steffens@nextcloud.com>

* cypress setup fix

Signed-off-by: Florian Steffens <florian.steffens@nextcloud.com>

* Update cypress/e2e/tables-unified-search.cy.js

Okay, did not know that cypress waits for promises...

Co-authored-by: max-nextcloud <max@nextcloud.com>
Signed-off-by: Florian <florian.steffens@nextcloud.com>

---------

Signed-off-by: Florian Steffens <florian.steffens@nextcloud.com>
Signed-off-by: Florian <florian.steffens@nextcloud.com>
Co-authored-by: max-nextcloud <max@nextcloud.com>
  • Loading branch information
Florian and max-nextcloud authored Sep 13, 2023
1 parent 6a98231 commit e0aa764
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 11 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 14 additions & 8 deletions cypress/e2e/tables-unified-search.cy.js
Original file line number Diff line number Diff line change
@@ -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)
})
})

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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')
})
Expand Down
38 changes: 38 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import { addCommands } from '@nextcloud/cypress'

const url = Cypress.config('baseUrl').replace(/\/index.php\/?$/g, '')
Cypress.env('baseUrl', url)

addCommands()

Expand Down Expand Up @@ -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)
})
})

0 comments on commit e0aa764

Please sign in to comment.