diff options
author | skjnldsv <skjnldsv@protonmail.com> | 2024-08-21 19:28:55 +0200 |
---|---|---|
committer | John Molakvoæ <skjnldsv@users.noreply.github.com> | 2024-08-22 13:32:59 +0200 |
commit | b6bc28833ca7292aa6144fab9710868cf252925f (patch) | |
tree | 3245d54c2eb748df4ba1c25b312534a8d282365d /cypress | |
parent | 49fa2e508d286f10c5f80b3b5dc5ca28e323ce99 (diff) | |
download | nextcloud-server-b6bc28833ca7292aa6144fab9710868cf252925f.tar.gz nextcloud-server-b6bc28833ca7292aa6144fab9710868cf252925f.zip |
chore(cypress): allow db snapshot and restore fo faster tests
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
Diffstat (limited to 'cypress')
-rw-r--r-- | cypress/e2e/settings/personal-info.cy.ts | 27 | ||||
-rw-r--r-- | cypress/support/commands.ts | 23 |
2 files changed, 43 insertions, 7 deletions
diff --git a/cypress/e2e/settings/personal-info.cy.ts b/cypress/e2e/settings/personal-info.cy.ts index 491d8206b5e..746717b5fb4 100644 --- a/cypress/e2e/settings/personal-info.cy.ts +++ b/cypress/e2e/settings/personal-info.cy.ts @@ -102,11 +102,23 @@ const genericProperties = ['Location', 'X (formerly Twitter)', 'Fediverse'] const nonfederatedProperties = ['Organisation', 'Role', 'Headline', 'About'] describe('Settings: Change personal information', { testIsolation: true }, () => { + let snapshot: string = '' before(() => { // ensure we can set locale and language cy.runOccCommand('config:system:delete force_language') cy.runOccCommand('config:system:delete force_locale') + cy.createRandomUser().then(($user) => { + user = $user + cy.modifyUser(user, 'language', 'en') + cy.modifyUser(user, 'locale', 'en_US') + }) + + cy.wait(500) + + cy.backupDB().then(($snapshot) => { + snapshot = $snapshot + }) }) after(() => { @@ -115,16 +127,15 @@ describe('Settings: Change personal information', { testIsolation: true }, () => }) beforeEach(() => { - cy.createRandomUser().then(($user) => { - user = $user - cy.modifyUser(user, 'language', 'en') - cy.modifyUser(user, 'locale', 'en_US') - cy.login($user) - cy.visit('/settings/user') - }) + cy.login(user) + cy.visit('/settings/user') cy.intercept('PUT', /ocs\/v2.php\/cloud\/users\//).as('submitSetting') }) + afterEach(() => { + cy.restoreDB(snapshot) + }) + it('Can dis- and enable the profile', () => { cy.visit(`/u/${user.userId}`) cy.contains('h2', user.userId).should('be.visible') @@ -132,6 +143,7 @@ describe('Settings: Change personal information', { testIsolation: true }, () => cy.visit('/settings/user') cy.contains('Enable profile').click() handlePasswordConfirmation(user.password) + cy.wait('@submitSetting') cy.visit(`/u/${user.userId}`, { failOnStatusCode: false }) cy.contains('h2', 'Profile not found').should('be.visible') @@ -139,6 +151,7 @@ describe('Settings: Change personal information', { testIsolation: true }, () => cy.visit('/settings/user') cy.contains('Enable profile').click() handlePasswordConfirmation(user.password) + cy.wait('@submitSetting') cy.visit(`/u/${user.userId}`, { failOnStatusCode: false }) cy.contains('h2', user.userId).should('be.visible') diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 6ca0388a0a0..e5aa11df775 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -65,6 +65,17 @@ declare global { * Run an occ command in the docker container. */ runOccCommand(command: string, options?: Partial<Cypress.ExecOptions>): Cypress.Chainable<Cypress.Exec>, + + /** + * Create a snapshot of the current database + */ + backupDB(): Cypress.Chainable<string>, + + /** + * Restore a snapshot of the database + * Default is the post-setup state + */ + restoreDB(snapshot?: string): Cypress.Chainable, } } } @@ -276,3 +287,15 @@ Cypress.Commands.add('runOccCommand', (command: string, options?: Partial<Cypres const env = Object.entries(options?.env ?? {}).map(([name, value]) => `-e '${name}=${value}'`).join(' ') return cy.exec(`docker exec --user www-data ${env} nextcloud-cypress-tests-server php ./occ ${command}`, options) }) + +Cypress.Commands.add('backupDB', (): Cypress.Chainable<string> => { + const randomString = Math.random().toString(36).substring(7) + cy.exec(`docker exec nextcloud-cypress-tests-server cp /var/www/html/data/owncloud.db /var/www/html/data/owncloud.db-${randomString}`) + cy.log(`Created snapshot ${randomString}`) + return cy.wrap(randomString) +}) + +Cypress.Commands.add('restoreDB', (snapshot: string = 'init') => { + cy.exec(`docker exec nextcloud-cypress-tests-server cp /var/www/html/data/owncloud.db-${snapshot} /var/www/html/data/owncloud.db`) + cy.log(`Restored snapshot ${snapshot}`) +}) |