Skip to content

Commit

Permalink
=
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed Sep 15, 2024
1 parent f41533d commit 37174bb
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 194 deletions.
13 changes: 13 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ export default defineConfig({
}
})

// This allows to store global data (e.g. the name of a snapshot)
// because Cypress.env() and other options are local to the current spec file.
const data = {}
on('task', {
setVariable({ key, value }) {
data[key] = value
return null
},
getVariable({ key }) {
return data[key] ?? null
},
})

// Before the browser launches
// starting Nextcloud testing container
const ip = await startNextcloud(process.env.BRANCH)
Expand Down
51 changes: 50 additions & 1 deletion cypress/e2e/files_versions/filesVersionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,56 @@
*/
/* eslint-disable jsdoc/require-jsdoc */
import type { User } from '@nextcloud/cypress'
import path from 'path'
import { addUserToGroup, createGroup, createGroupFolder, PERMISSION_DELETE, PERMISSION_READ, PERMISSION_WRITE } from '../groupfoldersUtils'
import { navigateToFolder } from '../files/filesUtils'

type SetupInfo = {
dataSnapshot: string
dbSnapshot: string
groupName: string
groupFolderName: string
fileName: string
filePath: string
user: User
}

export function setupFilesVersions(): Cypress.Chainable<SetupInfo> {
return cy.task('getVariable', { key: 'files-versions-data' })
.then((_setupInfo) => {
const setupInfo = _setupInfo as SetupInfo || {}

if (setupInfo.dataSnapshot && setupInfo.dbSnapshot) {
cy.restoreDB(setupInfo.dbSnapshot)
cy.restoreData(setupInfo.dataSnapshot)
} else {
setupInfo.groupName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
setupInfo.groupFolderName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
setupInfo.fileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
setupInfo.filePath = `${setupInfo.groupFolderName}/${setupInfo.fileName}`

cy.createRandomUser().then(_user => { setupInfo.user = _user })
createGroup(setupInfo.groupName)

cy.then(() => {
addUserToGroup(setupInfo.groupName, setupInfo.user.userId)
createGroupFolder(setupInfo.groupFolderName, setupInfo.groupName, [PERMISSION_READ, PERMISSION_WRITE, PERMISSION_DELETE])

uploadThreeVersions(setupInfo.user, setupInfo.filePath)
})
.then(() => cy.backupDB().then((value) => { setupInfo.dbSnapshot = value }))
.then(() => cy.backupData([setupInfo.user.userId]).then((value) => { setupInfo.dataSnapshot = value }))
.then(() => cy.task('setVariable', { key: 'files-versions-data', value: setupInfo }))
}

return cy.then(() => {
cy.login(setupInfo.user)
cy.visit('/apps/files')
navigateToFolder(setupInfo.groupFolderName)
openVersionsPanel(setupInfo.filePath)
return cy.wrap(setupInfo)
})
})
}

export const uploadThreeVersions = (user: User, fileName: string) => {
// A new version will not be created if the changes occur
Expand Down
34 changes: 3 additions & 31 deletions cypress/e2e/files_versions/version_creation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,11 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { User } from '@nextcloud/cypress'

import { PERMISSION_DELETE, PERMISSION_READ, PERMISSION_WRITE, addUserToGroup, createGroup, createGroupFolder } from '../groupfoldersUtils'
import { openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils'
import { navigateToFolder } from '../files/filesUtils'
import { setupFilesVersions } from './filesVersionsUtils'

describe('Versions creation', () => {
let randomGroupName: string
let randomGroupFolderName: string
let randomFileName: string
let randomFilePath: string
let user1: User

before(() => {
randomGroupName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
randomGroupFolderName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
randomFilePath = `${randomGroupFolderName}/${randomFileName}`

cy.createRandomUser().then(_user => { user1 = _user })
createGroup(randomGroupName)

cy.then(() => {
addUserToGroup(randomGroupName, user1.userId)
createGroupFolder(randomGroupFolderName, randomGroupName, [PERMISSION_READ, PERMISSION_WRITE, PERMISSION_DELETE])

uploadThreeVersions(user1, randomFilePath)
cy.login(user1)
})

cy.visit('/apps/files')
navigateToFolder(randomGroupFolderName)
openVersionsPanel(randomFilePath)
beforeEach(() => {
setupFilesVersions()
})

it('Opens the versions panel and sees the versions', () => {
Expand Down
34 changes: 3 additions & 31 deletions cypress/e2e/files_versions/version_deletion.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,11 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { User } from '@nextcloud/cypress'

import { openVersionsPanel, uploadThreeVersions, deleteVersion } from './filesVersionsUtils'
import { navigateToFolder } from '../files/filesUtils'
import { PERMISSION_DELETE, PERMISSION_READ, PERMISSION_WRITE, addUserToGroup, createGroup, createGroupFolder } from '../groupfoldersUtils'
import { deleteVersion, setupFilesVersions } from './filesVersionsUtils'

describe('Versions restoration', () => {
let randomGroupName: string
let randomGroupFolderName: string
let randomFileName: string
let randomFilePath: string
let user1: User

before(() => {
randomGroupName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
randomGroupFolderName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
randomFilePath = `${randomGroupFolderName}/${randomFileName}`

cy.createRandomUser().then(_user => { user1 = _user })
createGroup(randomGroupName)

cy.then(() => {
addUserToGroup(randomGroupName, user1.userId)
createGroupFolder(randomGroupFolderName, randomGroupName, [PERMISSION_READ, PERMISSION_WRITE, PERMISSION_DELETE])

uploadThreeVersions(user1, randomFilePath)
cy.login(user1)
})

cy.visit('/apps/files')
navigateToFolder(randomGroupFolderName)
openVersionsPanel(randomFilePath)
beforeEach(() => {
setupFilesVersions()
})

it('Delete initial version', () => {
Expand Down
34 changes: 3 additions & 31 deletions cypress/e2e/files_versions/version_download.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,11 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { User } from '@nextcloud/cypress'

import { assertVersionContent, openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils'
import { PERMISSION_DELETE, PERMISSION_READ, PERMISSION_WRITE, addUserToGroup, createGroup, createGroupFolder } from '../groupfoldersUtils'
import { navigateToFolder } from '../files/filesUtils'
import { assertVersionContent, setupFilesVersions } from './filesVersionsUtils'

describe('Versions download', () => {
let randomGroupName: string
let randomGroupFolderName: string
let randomFileName: string
let randomFilePath: string
let user1: User

before(() => {
randomGroupName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
randomGroupFolderName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
randomFilePath = `${randomGroupFolderName}/${randomFileName}`

cy.createRandomUser().then(_user => { user1 = _user })
createGroup(randomGroupName)

cy.then(() => {
addUserToGroup(randomGroupName, user1.userId)
createGroupFolder(randomGroupFolderName, randomGroupName, [PERMISSION_READ, PERMISSION_WRITE, PERMISSION_DELETE])

uploadThreeVersions(user1, randomFilePath)
cy.login(user1)
})

cy.visit('/apps/files')
navigateToFolder(randomGroupFolderName)
openVersionsPanel(randomFilePath)
beforeEach(() => {
setupFilesVersions()
})

it('Download versions and assert their content', () => {
Expand Down
47 changes: 12 additions & 35 deletions cypress/e2e/files_versions/version_expiration.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,25 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { User } from '@nextcloud/cypress'

import { assertVersionContent, nameVersion, openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils'
import { addUserToGroup, createGroup, createGroupFolder, PERMISSION_DELETE, PERMISSION_READ, PERMISSION_WRITE } from '../groupfoldersUtils'
import { navigateToFolder } from '../files/filesUtils'
import { closeSidebar } from '../files/filesUtils'
import { assertVersionContent, nameVersion, openVersionsPanel, setupFilesVersions } from './filesVersionsUtils'

describe('Versions expiration', () => {
let randomGroupName: string
let randomGroupFolderName: string
let randomFileName: string
let randomFilePath: string
let user1: User

beforeEach(() => {
randomGroupName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
randomGroupFolderName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
randomFilePath = `${randomGroupFolderName}/${randomFileName}`

cy.createRandomUser().then(_user => { user1 = _user })
createGroup(randomGroupName)

cy.then(() => {
addUserToGroup(randomGroupName, user1.userId)
createGroupFolder(randomGroupFolderName, randomGroupName, [PERMISSION_READ, PERMISSION_WRITE, PERMISSION_DELETE])

uploadThreeVersions(user1, randomFilePath)
cy.login(user1)
})

cy.visit('/apps/files')
navigateToFolder(randomGroupFolderName)
openVersionsPanel(randomFilePath)

setupFilesVersions()
.then(({ filePath }) => {
randomFilePath = filePath
})
})

it('Expire all versions', () => {
cy.runOccCommand('config:system:set versions_retention_obligation --value "0, 0"')
cy.runOccCommand('versions:expire')
cy.runOccCommand('groupfolders:expire')
cy.runOccCommand('config:system:set versions_retention_obligation --value auto')
cy.visit('/apps/files')
openVersionsPanel(randomFileName)
closeSidebar()
openVersionsPanel(randomFilePath)

cy.get('#tab-version_vue').within(() => {
cy.get('[data-files-versions-version]').should('have.length', 1)
Expand All @@ -58,10 +35,10 @@ describe('Versions expiration', () => {
nameVersion(2, 'v1')

cy.runOccCommand('config:system:set versions_retention_obligation --value "0, 0"')
cy.runOccCommand('versions:expire')
cy.runOccCommand('groupfolders:expire')
cy.runOccCommand('config:system:set versions_retention_obligation --value auto')
cy.visit('/apps/files')
openVersionsPanel(randomFileName)
closeSidebar()
openVersionsPanel(randomFilePath)

cy.get('#tab-version_vue').within(() => {
cy.get('[data-files-versions-version]').should('have.length', 2)
Expand Down
34 changes: 3 additions & 31 deletions cypress/e2e/files_versions/version_naming.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,11 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { User } from '@nextcloud/cypress'

import { nameVersion, openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils'
import { PERMISSION_DELETE, PERMISSION_READ, PERMISSION_WRITE, addUserToGroup, createGroup, createGroupFolder } from '../groupfoldersUtils'
import { navigateToFolder } from '../files/filesUtils'
import { nameVersion, setupFilesVersions } from './filesVersionsUtils'

describe('Versions naming', () => {
let randomGroupName: string
let randomGroupFolderName: string
let randomFileName: string
let randomFilePath: string
let user1: User

before(() => {
randomGroupName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
randomGroupFolderName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
randomFilePath = `${randomGroupFolderName}/${randomFileName}`

cy.createRandomUser().then(_user => { user1 = _user })
createGroup(randomGroupName)

cy.then(() => {
addUserToGroup(randomGroupName, user1.userId)
createGroupFolder(randomGroupFolderName, randomGroupName, [PERMISSION_READ, PERMISSION_WRITE, PERMISSION_DELETE])

uploadThreeVersions(user1, randomFilePath)
cy.login(user1)
})

cy.visit('/apps/files')
navigateToFolder(randomGroupFolderName)
openVersionsPanel(randomFilePath)
beforeEach(() => {
setupFilesVersions()
})

it('Names the versions', () => {
Expand Down
34 changes: 3 additions & 31 deletions cypress/e2e/files_versions/version_restoration.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,11 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { User } from '@nextcloud/cypress'

import { assertVersionContent, doesNotHaveAction, openVersionsPanel, restoreVersion, uploadThreeVersions } from './filesVersionsUtils'
import { PERMISSION_DELETE, PERMISSION_READ, PERMISSION_WRITE, addUserToGroup, createGroup, createGroupFolder } from '../groupfoldersUtils'
import { navigateToFolder } from '../files/filesUtils'
import { assertVersionContent, doesNotHaveAction, restoreVersion, setupFilesVersions } from './filesVersionsUtils'

describe('Versions restoration', () => {
let randomGroupName: string
let randomGroupFolderName: string
let randomFileName: string
let randomFilePath: string
let user1: User

before(() => {
randomGroupName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
randomGroupFolderName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
randomFilePath = `${randomGroupFolderName}/${randomFileName}`

cy.createRandomUser().then(_user => { user1 = _user })
createGroup(randomGroupName)

cy.then(() => {
addUserToGroup(randomGroupName, user1.userId)
createGroupFolder(randomGroupFolderName, randomGroupName, [PERMISSION_READ, PERMISSION_WRITE, PERMISSION_DELETE])

uploadThreeVersions(user1, randomFilePath)
cy.login(user1)
})

cy.visit('/apps/files')
navigateToFolder(randomGroupFolderName)
openVersionsPanel(randomFilePath)
setupFilesVersions()
})

it('Current version does not have restore action', () => {
Expand All @@ -52,7 +24,7 @@ describe('Versions restoration', () => {
})
})

it('Downloads versions and assert there content', () => {
it('Downloads versions and assert their content', () => {
assertVersionContent(0, 'v1')
assertVersionContent(1, 'v3')
assertVersionContent(2, 'v2')
Expand Down
Loading

0 comments on commit 37174bb

Please sign in to comment.