forked from cypress-io/cypress-realworld-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.spec.ts
158 lines (125 loc) · 5.75 KB
/
auth.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import { User } from "../../../src/models";
import { isMobile } from "../../support/utils";
describe("User Sign-up and Login", function () {
beforeEach(function () {
cy.task("db:seed");
cy.server();
cy.route("POST", "/users").as("signup");
cy.route("POST", "/bankAccounts").as("createBankAccount");
});
it("should redirect unauthenticated user to signin page", function () {
cy.visit("/personal");
cy.location("pathname").should("equal", "/signin");
cy.visualSnapshot("Redirect to SignIn");
});
it("should remember a user for 30 days after login", function () {
cy.database("find", "users").then((user: User) => {
cy.login(user.username, "s3cret", true);
});
// Verify Session Cookie
cy.getCookie("connect.sid").should("have.property", "expiry");
// Logout User
if (isMobile()) {
cy.getBySel("sidenav-toggle").click();
}
cy.getBySel("sidenav-signout").click();
cy.location("pathname").should("eq", "/signin");
cy.visualSnapshot("Redirect to SignIn");
});
it("should allow a visitor to sign-up, login, and logout", function () {
const userInfo = {
firstName: "Bob",
lastName: "Ross",
username: "PainterJoy90",
password: "s3cret",
};
// Sign-up User
cy.visit("/");
cy.getBySel("signup").click();
cy.getBySel("signup-title").should("be.visible").and("contain", "Sign Up");
cy.visualSnapshot("Sign Up Title");
cy.getBySel("signup-first-name").type(userInfo.firstName);
cy.getBySel("signup-last-name").type(userInfo.lastName);
cy.getBySel("signup-username").type(userInfo.username);
cy.getBySel("signup-password").type(userInfo.password);
cy.getBySel("signup-confirmPassword").type(userInfo.password);
cy.visualSnapshot("About to Sign Up");
cy.getBySel("signup-submit").click();
cy.wait("@signup");
// Login User
cy.login(userInfo.username, userInfo.password);
// Onboarding
cy.getBySel("user-onboarding-dialog").should("be.visible");
cy.getBySel("list-skeleton").should("not.exist");
cy.getBySel("nav-top-notifications-count").should("exist");
cy.visualSnapshot("User Onboarding Dialog");
cy.getBySel("user-onboarding-next").click();
cy.getBySel("user-onboarding-dialog-title").should("contain", "Create Bank Account");
cy.getBySelLike("bankName-input").type("The Best Bank");
cy.getBySelLike("accountNumber-input").type("123456789");
cy.getBySelLike("routingNumber-input").type("987654321");
cy.visualSnapshot("About to complete User Onboarding");
cy.getBySelLike("submit").click();
cy.wait("@createBankAccount");
cy.getBySel("user-onboarding-dialog-title").should("contain", "Finished");
cy.getBySel("user-onboarding-dialog-content").should("contain", "You're all set!");
cy.visualSnapshot("Finished User Onboarding");
cy.getBySel("user-onboarding-next").click();
cy.getBySel("transaction-list").should("be.visible");
cy.visualSnapshot("Transaction List is visible after User Onboarding");
// Logout User
if (isMobile()) {
cy.getBySel("sidenav-toggle").click();
}
cy.getBySel("sidenav-signout").click();
cy.location("pathname").should("eq", "/signin");
cy.visualSnapshot("Redirect to SignIn");
});
it("should display login errors", function () {
cy.visit("/");
cy.getBySel("signin-username").type("User").find("input").clear().blur();
cy.get("#username-helper-text").should("be.visible").and("contain", "Username is required");
cy.visualSnapshot("Display Username is Required Error");
cy.getBySel("signin-password").type("abc").find("input").blur();
cy.get("#password-helper-text")
.should("be.visible")
.and("contain", "Password must contain at least 4 characters");
cy.visualSnapshot("Display Password Error");
cy.getBySel("signin-submit").should("be.disabled");
cy.visualSnapshot("Sign In Submit Disabled");
});
it("should display signup errors", function () {
cy.visit("/signup");
cy.getBySel("signup-first-name").type("First").find("input").clear().blur();
cy.get("#firstName-helper-text").should("be.visible").and("contain", "First Name is required");
cy.getBySel("signup-last-name").type("Last").find("input").clear().blur();
cy.get("#lastName-helper-text").should("be.visible").and("contain", "Last Name is required");
cy.getBySel("signup-username").type("User").find("input").clear().blur();
cy.get("#username-helper-text").should("be.visible").and("contain", "Username is required");
cy.getBySel("signup-password").type("password").find("input").clear().blur();
cy.get("#password-helper-text").should("be.visible").and("contain", "Enter your password");
cy.getBySel("signup-confirmPassword").type("DIFFERENT PASSWORD").find("input").blur();
cy.get("#confirmPassword-helper-text")
.should("be.visible")
.and("contain", "Password does not match");
cy.visualSnapshot("Display Sign Up Required Errors");
cy.getBySel("signup-submit").should("be.disabled");
cy.visualSnapshot("Sign Up Submit Disabled");
});
it("should error for an invalid user", function () {
cy.login("invalidUserName", "invalidPa$$word");
cy.getBySel("signin-error")
.should("be.visible")
.and("have.text", "Username or password is invalid");
cy.visualSnapshot("Sign In, Invalid Username and Password, Username or Password is Invalid");
});
it("should error for an invalid password for existing user", function () {
cy.database("find", "users").then((user: User) => {
cy.login(user.username, "INVALID");
});
cy.getBySel("signin-error")
.should("be.visible")
.and("have.text", "Username or password is invalid");
cy.visualSnapshot("Sign In, Invalid Username, Username or Password is Invalid");
});
});