Skip to content

Commit

Permalink
test(cy): use child commands for seeding circle
Browse files Browse the repository at this point in the history
Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud committed Nov 9, 2023
1 parent b463947 commit 4c8f582
Showing 1 changed file with 25 additions and 26 deletions.
51 changes: 25 additions & 26 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ Cypress.Commands.add('seedPageContent', (pagePath, content) => {
const contentForLog = content.length > 200
? content.substring(0, 200) + '...'
: content
Cypress.log({ message: `${pagePath}, ${contentForLog}`})
Cypress.log({ message: `${pagePath}, ${contentForLog}` })
cy.uploadContent(`Collectives/${pagePath}`, content)
})

Expand Down Expand Up @@ -355,34 +355,33 @@ 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.log()
const url = `${Cypress.env('baseUrl')}/ocs/v2.php/apps/circles/circles/${circleId}/members`
return axios.put(`${url}/${memberId}/level`,
{ level },
)
})
Cypress.Commands.add('circleAddMember',
{ prevSubject: true },
async ({ id }, { userId, type }) => {
Cypress.log()
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.log()
const url = `${Cypress.env('baseUrl')}/ocs/v2.php/apps/circles/circles/${circleId}/members`
const response = await axios.post(url,
{ userId, type },
)
const memberId = response.data.ocs.data.id
return { circleId, userId, memberId }
})
Cypress.Commands.add('circleSetMemberLevel',
{ prevSubject: true },
({ circleId, memberId }, level) => {
Cypress.log()
const url = `${Cypress.env('baseUrl')}/ocs/v2.php/apps/circles/circles/${circleId}/members`
return axios.put(`${url}/${memberId}/level`,
{ level },
)
},
)

/**
* Fail the test on the initial run to check if retries work
Expand Down

0 comments on commit 4c8f582

Please sign in to comment.