diff --git a/cypress/e2e/albums.cy.js b/cypress/e2e/albums.cy.js index 79fb61dce..5226adc61 100644 --- a/cypress/e2e/albums.cy.js +++ b/cypress/e2e/albums.cy.js @@ -30,6 +30,7 @@ import { import { deleteSelection, favoriteSelection, + mkdir, selectMedia, unfavoriteSelection, unselectMedia, @@ -47,10 +48,11 @@ Cypress.on('uncaught:exception', (err) => { describe('Manage albums', { testIsolation: true }, () => { let user = null - beforeEach(function() { + beforeEach(function () { cy.createRandomUser() .then(_user => { user = _user + mkdir(user, '/Photos') uploadTestMedia(user) cy.login(user) }) diff --git a/cypress/e2e/photosUtils.ts b/cypress/e2e/photosUtils.ts index 1d8a066bd..af7d1e792 100644 --- a/cypress/e2e/photosUtils.ts +++ b/cypress/e2e/photosUtils.ts @@ -19,12 +19,13 @@ */ import type { User } from '@nextcloud/cypress' +import axios from 'axios' -export function uploadTestMedia(user: User) { +export function uploadTestMedia(user: User, destination = '/Photos') { cy.exec('ls cypress/fixtures/media') .then((result) => { for (const fileName of result.stdout.split('\n')) { - cy.uploadFile(user, `media/${fileName}`, 'image/png', `/${fileName}`) + cy.uploadFile(user, `media/${fileName}`, 'image/png', `/${destination}/${fileName}`) } }) } @@ -72,3 +73,26 @@ export function deleteSelection() { .click() .wait('@deleteRequests') } + +export function mkdir(user: User, target: string) { + // eslint-disable-next-line cypress/unsafe-to-chain-command + cy.clearCookies() + .then({ timeout: 8000 }, async () => { + try { + const rootPath = `${Cypress.env('baseUrl')}/remote.php/dav/files/${encodeURIComponent(user.userId)}` + const filePath = target.split('/').map(encodeURIComponent).join('/') + const response = await axios({ + url: `${rootPath}${filePath}`, + method: 'MKCOL', + auth: { + username: user.userId, + password: user.password, + }, + }) + cy.log(`Created directory ${target}`, response) + } catch (error) { + cy.log('error', error) + throw new Error('Unable to process fixture') + } + }) +} diff --git a/cypress/e2e/places.cy.js b/cypress/e2e/places.cy.js index ea34aa0b1..645cff279 100644 --- a/cypress/e2e/places.cy.js +++ b/cypress/e2e/places.cy.js @@ -19,7 +19,7 @@ * along with this program. If not, see . * */ -import { uploadTestMedia } from './photosUtils' +import { mkdir, uploadTestMedia } from './photosUtils' import { navigateToPlace, runOccCommand } from './placesUtils' const resizeObserverLoopErrRe = /^[^(ResizeObserver loop limit exceeded)]/ @@ -31,9 +31,10 @@ Cypress.on('uncaught:exception', (err) => { }) describe('Manage places', () => { - before(function() { + before(function () { cy.createRandomUser() .then((user) => { + mkdir(user, '/Photos') uploadTestMedia(user) runOccCommand('files:scan --all --generate-metadata') cy.login(user) diff --git a/cypress/e2e/shared_albums.cy.ts b/cypress/e2e/shared_albums.cy.ts index 0396bbe6d..b651f2f47 100644 --- a/cypress/e2e/shared_albums.cy.ts +++ b/cypress/e2e/shared_albums.cy.ts @@ -34,6 +34,7 @@ import { deleteSelection, downloadAllFiles, downloadSelection, + mkdir, selectMedia, uploadTestMedia, } from './photosUtils' @@ -64,6 +65,9 @@ describe('Manage shared albums', () => { cy.createUser(alice) cy.createUser(bob) cy.createUser(charlie) + mkdir(alice, '/Photos') + mkdir(bob, '/Photos') + mkdir(charlie, '/Photos') uploadTestMedia(alice) uploadTestMedia(bob) uploadTestMedia(charlie) @@ -302,6 +306,7 @@ describe('Manage shared albums', () => { cy.visit('apps/photos/sharedalbums') cy.get('body').should('not.contain', `shared_album_test7 (${alice.userId})`) cy.createUser(alice) + mkdir(alice, '/Photos') uploadTestMedia(alice) }) }) diff --git a/cypress/e2e/timelines.cy.js b/cypress/e2e/timelines.cy.js index 8e9cce5fd..566640dc8 100644 --- a/cypress/e2e/timelines.cy.js +++ b/cypress/e2e/timelines.cy.js @@ -33,6 +33,7 @@ import { deleteSelection, downloadSelection, favoriteSelection, + mkdir, selectMedia, unfavoriteSelection, unselectMedia, @@ -59,9 +60,11 @@ const bob = new User(`bob_${randHash()}`) describe('View list of photos in the main timeline', () => { before(() => { cy.createUser(alice).then(() => { + mkdir(alice, '/Photos') uploadTestMedia(alice) }) cy.createUser(bob).then(() => { + mkdir(bob, '/Photos') uploadTestMedia(bob) }) cy.login(alice)