Created
April 14, 2023 06:02
-
-
Save tochman/1f7a8a5a97e37db98f1b5e86df035066 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe("Authentication:", () => { | |
beforeEach(() => { | |
cy.visit("/"); | |
cy.intercept("POST", "https://hooks.slack.com/services/**", { | |
body: { message: "ok" }, | |
statusCode: 200, | |
}).as("slackHook"); | |
}); | |
}); | |
describe("by navigating to SIGN-UP, ", () => { | |
beforeEach("- ACTIONS intercept calls, navigate --", () => { | |
cy.getCy("sign-up-button").click(); | |
}); | |
context("and submitting an VALID registration form", () => { | |
beforeEach("- ACTIONS fill in form --", () => { | |
cy.intercept("POST", "**/auth", { | |
fixture: "authenticatedUser.json", | |
}).as("signUp"); | |
cy.intercept("POST", "**/auth/sign_in", { | |
fixture: "authenticatedUser.json", | |
}).as("signIn"); | |
cy.intercept("GET", "**/auth/validate_token", { | |
fixture: "authenticatedUser.json", | |
headers: { uid: "random.guy@mail.com" }, | |
}); | |
cy.getCy("create-account-form").within(() => { | |
cy.getCy("name").type("Random Guy"); | |
cy.getCy("email").type("random.guy@email.com"); | |
cy.getCy("password").type("password"); | |
cy.getCy("password-conf").type("password"); | |
cy.get("[data-cy=submit]").click(); | |
}); | |
}); | |
it("is expected to make a network call on submit", () => { | |
cy.wait("@signUp").its("request.method").should("eql", "POST"); | |
}); | |
it("is expected to make a network call on submit", () => { | |
cy.wait("@slackHook").its("request.method").should("eql", "POST"); | |
}); | |
it("is expected to include message in request params", () => { | |
cy.wait("@slackHook").then(({ request }) => { | |
const expectedBody = '{"icon_emoji":":pencil2:","username":"Pranzo.se","blocks":[{"type":"section","text":{"type":"mrkdwn","text":"Kalle Andersson just registered with Pranzo.se"}}]}' | |
expect(request.body).to.eql(expectedBody) | |
}); | |
}); | |
it("is expected to include form data as params", () => { | |
cy.wait("@signUp").then(({ request }) => { | |
expect(request.body.name).to.eql("Random Guy"); | |
expect(request.body.email).to.eql("random.guy@email.com"); | |
expect(request.body.password).to.eql("password"); | |
expect(request.body.passwordConf).to.eql("password"); | |
}); | |
}); | |
it("is expected to store currentUser in application state", () => { | |
cy.wait("@signUp"); | |
cy.window() | |
.pipe((window) => window.store.getState().user.currentUser) | |
.should("not.be", "undefined") | |
.and("be.an", "object"); | |
}); | |
it("is expected to redirect user to /dashboard view", () => { | |
cy.location("pathname").should("eq", "/dashboard"); | |
}); | |
it("is expected to hide SignUp button in AppBar", () => { | |
cy.getCy("sign-up-button").should("exist"); | |
}); | |
it("is expected to hide SignIn button in AppBar", () => { | |
cy.getCy("sign-in-button").should("nit.exist"); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment