Skip to content

Commit

Permalink
Test/review requests (#1379)
Browse files Browse the repository at this point in the history
* feat: add utils for review request

* fix: allow remove collaborators to work with more than 2 additional collaborators

* feat: add addAdminCollaborator utils

* feat: add additional api utils

* Fix: sets removeOtherCollaborators to remove only the second collaborator

* feat: add review request tests

* fix: revert e2e_email_collab

* chore: remame e2e_email_collab_2

* chore: rename removeOtherCollaborators

* nit: modify comments

* feat: add check for automatic redirect

* refactor: move common interceptors into util method

* fix: remove unnecessary waits and change wait for dropdown

* feat: add additional test case for collaborators not approving

* fix: add removeOtherCollaborators

* chore: move cypress support method to utils

* fix: remove unused import
  • Loading branch information
alexanderleegs authored Aug 3, 2023
1 parent bf341f8 commit e7b34c5
Show file tree
Hide file tree
Showing 11 changed files with 745 additions and 79 deletions.
142 changes: 142 additions & 0 deletions cypress/api/pages.api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,71 @@
import { DirectoryData } from "types/directory"

import { UnlinkedPageDto } from "../../src/types/pages"
import { BACKEND_URL } from "../fixtures/constants"

export const listCollectionPages = (
site: string,
collectionName: string
): Cypress.Chainable<DirectoryData[]> => {
return cy
.request(
"GET",
`${BACKEND_URL}/sites/${site}/collections/${collectionName}`
)
.then(({ body }) => body)
}

export const listUnlinkedPages = (
site: string
): Cypress.Chainable<DirectoryData[]> => {
return cy
.request("GET", `${BACKEND_URL}/sites/${site}/pages`)
.then(({ body }) => body)
}

export const addCollectionPage = (
pageName: string,
collectionName: string,
title: string,
permalink: string,
pageContent: string,
site: string
): void => {
cy.request(
"POST",
`${BACKEND_URL}/sites/${site}/collections/${collectionName}/pages`,
{
content: {
frontMatter: {
title,
permalink,
},
pageBody: pageContent,
},
newFileName: pageName,
}
)
}

export const addUnlinkedPage = (
pageName: string,
title: string,
permalink: string,
pageContent: string,
site: string
): void => {
cy.request("POST", `${BACKEND_URL}/sites/${site}/pages/pages`, {
content: {
frontMatter: {
title,
permalink,
},
pageBody: pageContent,
},
newFileName: pageName,
})
}

export const editUnlinkedPage = (
pageName: string,
pageContent: string,
Expand Down Expand Up @@ -29,3 +94,80 @@ export const readUnlinkedPage = (
.request("GET", `${BACKEND_URL}/sites/${site}/pages/pages/${pageName}`)
.then(({ body }) => body)
}

export const readCollectionPage = (
pageName: string,
collectionName: string,
site: string
): Cypress.Chainable<UnlinkedPageDto> => {
return cy
.request(
"GET",
`${BACKEND_URL}/sites/${site}/collections/${collectionName}/pages/${pageName}`
)
.then(({ body }) => body)
}

export const deleteUnlinkedPage = (pageName: string, site: string): void => {
readUnlinkedPage(pageName, site).then(({ sha }) => {
return cy.request(
"DELETE",
`${BACKEND_URL}/sites/${site}/pages/pages/${pageName}`,
{
sha,
}
)
})
}

export const deleteCollectionPage = (
pageName: string,
collectionName: string,
site: string
): void => {
readCollectionPage(pageName, collectionName, site).then(({ sha }) => {
return cy.request(
"DELETE",
`${BACKEND_URL}/sites/${site}/collections/${collectionName}/pages/${pageName}`,
{
sha,
}
)
})
}

export const renameUnlinkedPage = (
pageName: string,
newPageName: string,
site: string
): void => {
readUnlinkedPage(pageName, site).then(({ sha, content }) => {
return cy.request(
"POST",
`${BACKEND_URL}/sites/${site}/pages/pages/${pageName}`,
{
content,
sha,
newFileName: newPageName,
}
)
})
}

export const moveUnlinkedPage = (
pageName: string,
targetCollectionName: string,
site: string
): void => {
cy.request("POST", `${BACKEND_URL}/sites/${site}/pages/move`, {
target: {
collectionName: targetCollectionName,
},
items: [
{
name: pageName,
type: "file",
},
],
})
}
10 changes: 7 additions & 3 deletions cypress/api/reviewRequest.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@ export const createReviewRequest = (
.then(({ body }) => body.pullRequestNumber)
}

export const listReviewRequests = (): Cypress.Chainable<{ id: number }[]> => {
export const listReviewRequests = (): Cypress.Chainable<
{ id: number; author: string; status: string }[]
> => {
return cy
.request("GET", `${BASE_URL}/summary`)
.then(({ body }) => body.reviews)
}

export const closeReviewRequests = (): void => {
listReviewRequests().then((reviewRequests) => {
reviewRequests.forEach(({ id }) => {
closeReviewRequest(id)
reviewRequests.forEach(({ id, author }) => {
// Only the requestor can close their own review request
cy.actAsEmailUser(author, "Email admin")
cy.request("DELETE", `${BASE_URL}/${id}`)
})
})
}
Expand Down
6 changes: 3 additions & 3 deletions cypress/e2e/collaborators.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
addCollaborator,
getCollaboratorsModal,
inputCollaborators,
removeOtherCollaborators,
removeFirstCollaborator,
} from "../utils/collaborators"

const collaborator = E2E_EMAIL_COLLAB.email
Expand Down Expand Up @@ -62,7 +62,7 @@ describe("collaborators flow", () => {
})

describe("Admin adding a collaborator", () => {
after(() => removeOtherCollaborators())
after(() => removeFirstCollaborator())

it("should not be able to click the add collaborator button when the input is empty", () => {
// Act
Expand Down Expand Up @@ -137,7 +137,7 @@ describe("collaborators flow", () => {
it("should not be able to remove the last site member", () => {
// Act
// NOTE: Remove all collaborators except the initial admin
removeOtherCollaborators()
removeFirstCollaborator()

// Assert
cy.get(DELETE_COLLABORATOR_BUTTON_SELECTOR).should("be.disabled")
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/comments.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
ignoreNotFoundError,
openCommentsDrawer,
openReviewRequest,
removeOtherCollaborators,
removeFirstCollaborator,
setUserAsUnauthorised,
visitE2eEmailTestRepo,
getCommentInput,
Expand Down Expand Up @@ -201,7 +201,7 @@ describe("Comments", () => {
.then((id) => {
reviewId = id
})
removeOtherCollaborators()
removeFirstCollaborator()
})

// This is required so that subsequent tests do not fail
Expand Down
Loading

0 comments on commit e7b34c5

Please sign in to comment.