Skip to content

Commit

Permalink
Make intercepts in tests less version specific (#1658)
Browse files Browse the repository at this point in the history
  • Loading branch information
asnaith authored Oct 28, 2021
1 parent 02f3e17 commit ac0a204
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/files-ui/cypress/tests/file-preview-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe("File Preview", () => {
homePage.uploadFile("../fixtures/uploadedFiles/file.zip")

// setup an api intercepter for download requests
cy.intercept("POST", "https://stage.imploy.site/api/v1/bucket/*/download").as("downloadRequest").then(() => {
cy.intercept("POST", "**/bucket/*/download").as("downloadRequest").then(() => {
homePage.fileItemName().dblclick()
previewModal.unsupportedFileLabel().should("exist")
previewModal.downloadUnsupportedFileButton().should("be.visible")
Expand Down
28 changes: 15 additions & 13 deletions packages/files-ui/cypress/tests/survey-banner-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,52 @@ import { homePage } from "../support/page-objects/homePage"

describe("Survey Banner", () => {

const dismissedSurveyKey = "csf.dismissedSurveyBannerV3"

context("desktop", () => {

it("User can view and dismiss the survey banner", () => {
// intercept and stub the account creation date to be > 7 days
cy.intercept("GET", "https://stage.imploy.site/api/v1/user/profile", (req) => {
cy.intercept("GET", "**/user/profile", (req) => {
req.on("response", (res) => {
res.body.created_at = profileCreatedDate
res.body.created_at = profileCreatedDate
})
})

// intercept and stub the response to ensure the banner is displayed
cy.intercept("GET", "https://stage.imploy.site/api/v1/user/store", {
body: [{ "csf.dismissedSurveyBannerV3": "false" }]
cy.intercept("GET", "**/user/store", {
body: { [dismissedSurveyKey]: "false" }
})

cy.web3Login()
homePage.surveyBanner().should("be.visible")

// set up a spy for the POST response
cy.intercept("POST", "https://stage.imploy.site/api/v1/user/store").as("storePost").then(() => {
cy.intercept("POST", "**/user/store").as("storePost").then(() => {

// dismiss the survey banner
homePage.closeBannerButton().click()
homePage.surveyBanner().should("not.exist")

// intercept POST to ensure the key was updated after the banner is dismissed
cy.wait("@storePost").its("request.body").should("contain", {
"csf.dismissedSurveyBannerV3": "true"
[dismissedSurveyKey]: "true"
})
})
})

it("User should not see the survey banner if previously dismissed", () => {
cy.intercept("GET", "https://stage.imploy.site/api/v1/user/store", {
body: [{ "csf.dismissedSurveyBannerV3": "true" }]
cy.intercept("GET", "**/user/store", {
body: { [dismissedSurveyKey]: "true" }
})

cy.web3Login()
homePage.surveyBanner().should("not.exist")
})

it("User should see banner if account age is greater than 7 days and api response is empty", () => {
cy.intercept("GET", "https://stage.imploy.site/api/v1/user/store", {
body: [{}]
cy.intercept("GET", "**/user/store", {
body: {}
})

cy.web3Login()
Expand All @@ -55,14 +57,14 @@ describe("Survey Banner", () => {

it("User should not see banner if account age is less than 7 days and api response is empty", () => {
// intercept and stub the account creation date to make it less than 7 days
cy.intercept("GET", "https://stage.imploy.site/api/v1/user/profile", (req) => {
cy.intercept("GET", "**/user/profile", (req) => {
req.on("response", (res) => {
res.body.created_at = res.body.updated_at
})
})

cy.intercept("GET", "https://stage.imploy.site/api/v1/user/store", {
body: [{}]
cy.intercept("GET", "**/user/store", {
body: {}
})

cy.web3Login()
Expand Down

0 comments on commit ac0a204

Please sign in to comment.