From d5865f5e261a5bcdd3cc462a36ada271ba15bee2 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 9 Nov 2023 12:08:11 +0100 Subject: [PATCH] test(cy): use child commands for seeding circle Signed-off-by: Max --- cypress/support/commands.js | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index aa08d835b..bdaaeb529 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -355,33 +355,30 @@ Cypress.Commands.add('seedCircleMember', (name, userId, type = 1, level) => { cy.dispatch(GET_CIRCLES) cy.store('state.circles.circles') .findBy({ sanitizedName: name }) - .its('id') - .then(circleId => { - cy.circleAddMember(circleId, { userId, type }) - }) - .then(({ circleId, memberId }) => { - if (level) { - cy.circleSetMemberLevel(circleId, memberId, level) - } - }) + .circleAddMember({ userId, type }) + .circleSetMemberLevel(level) }) -Cypress.Commands.add('circleSetMemberLevel', (circleId, memberId, level) => { +Cypress.Commands.add('circleAddMember', + { prevSubject: true }, + async ({ id }, { userId, type }) => { Cypress.log() - const url = `${Cypress.env('baseUrl')}/ocs/v2.php/apps/circles/circles/${circleId}/members` - return axios.put(`${url}/${memberId}/level`, - { level }, + const url = `${Cypress.env('baseUrl')}/ocs/v2.php/apps/circles/circles/${id}/members` + const response = await axios.post(url, + { userId, type }, ) + const memberId = response.data.ocs.data.id + return { circleId: id, userId, memberId } }) -Cypress.Commands.add('circleAddMember', async (circleId, { userId, type }) => { +Cypress.Commands.add('circleSetMemberLevel', + { prevSubject: true }, + ({ circleId, memberId }, level) => { Cypress.log() const url = `${Cypress.env('baseUrl')}/ocs/v2.php/apps/circles/circles/${circleId}/members` - const response = await axios.post(url, - { userId, type }, + return axios.put(`${url}/${memberId}/level`, + { level }, ) - const memberId = response.data.ocs.data.id - return { circleId, userId, memberId } }) /**