Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from cy.route to cy.intercept for 7.x release #676

Merged
merged 56 commits into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
bbe7bb9
wip - convert cy.route to cy.http; remove cy.server; adjust to use JS…
Nov 18, 2020
40b82df
fix delete bankaccounts route
amirrustam Nov 19, 2020
2df6ef7
fix empty list test using cy.http
Nov 19, 2020
a36d581
wip - experiments
Nov 19, 2020
bde9fb5
uncomment wait
Nov 19, 2020
9fa7b56
reproduction and notes around cy.http issue with public transactions …
Nov 20, 2020
718ddd2
set run mode to not retry
Nov 20, 2020
7f130c4
remove only
Nov 20, 2020
8204520
rename cy.http to cy.intercept
Nov 23, 2020
2603578
remove JSON.parse per https://github.com/cypress-io/cypress-example-k…
Nov 23, 2020
0c59962
Merge branch 'develop' into kevin/cy-route-to-cy-http
Nov 24, 2020
79441bc
Merge branch 'develop' into kevin/cy-route-to-cy-intercept
Nov 25, 2020
69a2f6c
update to get user id if not 401 response
Nov 25, 2020
504652c
add glob-match to usersSearch for cy.intercept
Nov 25, 2020
01890a2
wip - iterate
Dec 1, 2020
6dc9646
Merge branch 'develop' into kevin/cy-route-to-cy-intercept
Dec 1, 2020
c3bc623
install nocache
Dec 1, 2020
2091375
configure routes not to cache (temporarily)
Dec 1, 2020
1b54220
note about failing cy.intercept for POST /logout
Dec 1, 2020
e27f96b
adjust cy.intercepts; notes on open Cypress issues
Dec 1, 2020
67895f2
update matching for stubbed public transactions
Dec 2, 2020
d18ef3e
restore to substring match for mocked response
Dec 2, 2020
fae229f
uninstall and remove nocache for routes since resolved in https://git…
Dec 2, 2020
da1d2d4
adjust to use response.statusCode for fix in https://github.com/cypre…
Dec 2, 2020
c4768ba
update syntax and expectation
Dec 3, 2020
d598c7c
Merge branch 'develop' into kevin/cy-route-to-cy-intercept
Feb 16, 2021
25b8694
Merge branch 'develop' into kevin/cy-route-to-cy-intercept
Mar 11, 2021
40741e9
delete if-none-match request header to prevent cached results for cy.…
Mar 11, 2021
6130eca
update to use regex for cy.intercept url matchers; delete if-none-mat…
Mar 11, 2021
ec65ac5
update /notifications to delete if-none-match request header to preve…
Mar 12, 2021
a14e014
cleanup and remove if-none-match for all feed routes, but continues t…
Mar 12, 2021
f197712
refactor to delete if-none-match for all routes in a global beforeEach
Mar 12, 2021
635a190
restore limit to 10
Mar 12, 2021
bf6c54d
update route matching to be exact
Mar 15, 2021
61e74a6
update to get url from response object
Mar 15, 2021
5ffd52a
update to use response.statusCode
Mar 15, 2021
0b9da87
update transaction view spec to use response.statusCode
Mar 15, 2021
155951f
update intercepts to use minimatch
Mar 19, 2021
28ed4c1
cleanup
Mar 23, 2021
22d557a
cleanup
Mar 24, 2021
04ad29f
example of res.send fixture not returning fixture
Mar 24, 2021
30851b5
add delay middleware for all mobile viewport tests
Mar 25, 2021
1122009
cleanup
Mar 25, 2021
7017840
cleanup
Mar 25, 2021
aa4fb9b
update mobile cy.intercept to throttle all routes
Mar 29, 2021
74d0692
fix syntax error
Mar 29, 2021
841ec4f
update from throttle -> setThrottle
Mar 29, 2021
13ae6ea
Merge branch 'develop' into kevin/cy-route-to-cy-intercept
Apr 6, 2021
5f6399a
update matching for global intercepts
Apr 6, 2021
40683bc
update path matching
Apr 6, 2021
32fa386
update matching for global intercepts
Apr 6, 2021
6fa9738
update intercept matching
Apr 6, 2021
444019e
temporary disable throttling for mobile
Apr 6, 2021
05e6a92
fix patch matching
Apr 6, 2021
17741f7
update matching for cy.intercept
Apr 6, 2021
bb5d576
wait for public transactions
Apr 6, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ Cypress.Commands.add("login", (username, password, rememberUser = false) => {
autoEnd: false,
});

cy.server();
cy.route("POST", "/login").as("loginUser");
cy.route("GET", "checkAuth").as("getUserProfile");
cy.intercept("POST", "/login").as("loginUser");
cy.intercept("GET", "checkAuth").as("getUserProfile");

cy.location("pathname", { log: false }).then((currentPath) => {
if (currentPath !== signinPath) {
Expand All @@ -77,7 +76,7 @@ Cypress.Commands.add("login", (username, password, rememberUser = false) => {
username,
password,
rememberUser,
userId: loginUser.response.body.user?.id,
userId: loginUser.response.statusCode !== 401 && loginUser.response.body.user.id,
};
},
});
Expand Down Expand Up @@ -137,9 +136,8 @@ Cypress.Commands.add("loginByXstate", (username, password = Cypress.env("default
autoEnd: false,
});

cy.server();
cy.route("POST", "/login").as("loginUser");
cy.route("GET", "/checkAuth").as("getUserProfile");
cy.intercept("POST", "/login").as("loginUser");
cy.intercept("GET", "/checkAuth").as("getUserProfile");
cy.visit("/signin", { log: false }).then(() => {
log.snapshot("before");
});
Expand All @@ -164,8 +162,7 @@ Cypress.Commands.add("loginByXstate", (username, password = Cypress.env("default
});

Cypress.Commands.add("logoutByXstate", () => {
cy.server();
cy.route("POST", "/logout").as("logoutUser");
cy.intercept("POST", "/logout").as("logoutUser");

const log = Cypress.log({
name: "logoutByXstate",
Expand Down
20 changes: 20 additions & 0 deletions cypress/support/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
// @ts-check
import "@cypress/code-coverage/support";
import "./commands";
import { isMobile } from "./utils";

beforeEach(() => {
// cy.intercept middleware to remove 'if-none-match' headers from all requests
// to prevent the server from returning cached responses of API requests
cy.intercept(
{ url: "http://localhost:3001/**", middleware: true },
(req) => delete req.headers["if-none-match"]
);

// Throttle API responses for mobile testing to simulate real world condition
if (isMobile()) {
cy.intercept({ url: "http://localhost:3001/**", middleware: true }, (req) => {
req.on("response", (res) => {
// Throttle the response to 1 Mbps to simulate a mobile 3G connection
res.setThrottle(1000);
});
});
}
});
7 changes: 4 additions & 3 deletions cypress/tests/ui/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ 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");
cy.intercept("POST", "/users").as("signup");
cy.intercept("POST", "/bankAccounts").as("createBankAccount");
});

it("should redirect unauthenticated user to signin page", function () {
Expand Down Expand Up @@ -112,6 +111,8 @@ describe("User Sign-up and Login", function () {
});

it("should display signup errors", function () {
cy.intercept("GET", "/signup");

cy.visit("/signup");

cy.getBySel("signup-first-name").type("First").find("input").clear().blur();
Expand Down
11 changes: 6 additions & 5 deletions cypress/tests/ui/bankaccounts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ describe("Bank Accounts", function () {
beforeEach(function () {
cy.task("db:seed");

cy.server();
cy.route("POST", "/bankAccounts").as("createBankAccount");
cy.route("DELETE", "/bankAccounts/*").as("deleteBankAccount");
cy.route("GET", "/notifications").as("getNotifications");
cy.intercept("POST", "/bankAccounts").as("createBankAccount");
cy.intercept("DELETE", "**/bankAccounts/*").as("deleteBankAccount");
cy.intercept("GET", "/notifications").as("getNotifications");

cy.database("find", "users").then((user: User) => {
ctx.user = user;
Expand Down Expand Up @@ -124,7 +123,9 @@ describe("Bank Accounts", function () {

// TODO: [enhancement] the onboarding modal assertion can be removed after adding "onboarded" flag to user profile
it("renders an empty bank account list state with onboarding modal", function () {
cy.route("GET", "/bankAccounts", []).as("getBankAccounts");
cy.intercept("GET", "/bankAccounts", {
body: { results: [] },
}).as("getBankAccounts");

cy.visit("/bankaccounts");
cy.wait("@getBankAccounts");
Expand Down
24 changes: 13 additions & 11 deletions cypress/tests/ui/new-transaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ describe("New Transaction", function () {
beforeEach(function () {
cy.task("db:seed");

cy.server();
cy.route("POST", "/transactions").as("createTransaction");
cy.intercept("GET", "/users*").as("allUsers");

cy.route("GET", "/users").as("allUsers");
cy.route("GET", "/notifications").as("notifications");
cy.route("GET", "/transactions/public").as("publicTransactions");
cy.route("GET", "/transactions").as("personalTransactions");
cy.route("GET", "/users/search*").as("usersSearch");
cy.route("PATCH", "/transactions/*").as("updateTransaction");
cy.intercept("GET", "/users/search*").as("usersSearch");

cy.intercept("POST", "/transactions").as("createTransaction");

cy.intercept("GET", "/notifications").as("notifications");
cy.intercept("GET", "/transactions/public").as("publicTransactions");
cy.intercept("GET", "/transactions").as("personalTransactions");
cy.intercept("PATCH", "/transactions/*").as("updateTransaction");

cy.database("filter", "users").then((users: User[]) => {
ctx.allUsers = users;
Expand Down Expand Up @@ -219,7 +220,7 @@ describe("New Transaction", function () {
cy.visualSnapshot("Navigate to Transaction Item");

cy.getBySelLike("accept-request").click();
cy.wait("@updateTransaction").its("status").should("equal", 204);
cy.wait("@updateTransaction").its("response.statusCode").should("eq", 204);
cy.getBySelLike("transaction-detail-header").should("be.visible");
cy.getBySelLike("transaction-amount").should("be.visible");
cy.getBySelLike("sender-avatar").should("be.visible");
Expand Down Expand Up @@ -263,8 +264,9 @@ describe("New Transaction", function () {
cy.getBySel("user-list-search-input").type(targetUser[attr] as string, { force: true });
cy.wait("@usersSearch")
// make sure the backend returns some results
.its("responseBody.results.length")
.should("be.gt", 0)
.its("response.body.results")
.should("have.length.gt", 0)
.its("length")
.then((resultsN) => {
cy.getBySelLike("user-list-item")
// make sure the list of results is fully updated
Expand Down
11 changes: 5 additions & 6 deletions cypress/tests/ui/notifications.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ describe("Notifications", function () {
beforeEach(function () {
cy.task("db:seed");

cy.server();
cy.route("GET", "/notifications").as("getNotifications");
cy.route("POST", "/transactions").as("createTransaction");
cy.route("PATCH", "/notifications/*").as("updateNotification");
cy.route("POST", "/comments/*").as("postComment");
cy.intercept("GET", "/notifications*").as("getNotifications");
cy.intercept("POST", "/transactions").as("createTransaction");
cy.intercept("PATCH", "/notifications/*").as("updateNotification");
cy.intercept("POST", "/comments/*").as("postComment");

cy.database("filter", "users").then((users: User[]) => {
ctx.userA = users[0];
Expand Down Expand Up @@ -250,7 +249,7 @@ describe("Notifications", function () {
});

it("renders an empty notifications state", function () {
cy.route("GET", "/notifications", []).as("notifications");
cy.intercept("GET", "/notifications", []).as("notifications");

cy.loginByXstate(ctx.userA.username);

Expand Down
24 changes: 15 additions & 9 deletions cypress/tests/ui/transaction-feeds.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ describe("Transaction Feed", function () {
beforeEach(function () {
cy.task("db:seed");

cy.server();
cy.route("GET", "/notifications").as("notifications");
cy.route("/transactions*").as(feedViews.personal.routeAlias);
cy.route("/transactions/public*").as(feedViews.public.routeAlias);
cy.route("/transactions/contacts*").as(feedViews.contacts.routeAlias);
cy.intercept("GET", "/notifications").as("notifications");
cy.intercept("GET", "/transactions*").as(feedViews.personal.routeAlias);
cy.intercept("GET", "/transactions/public*").as(feedViews.public.routeAlias);
cy.intercept("GET", "/transactions/contacts*").as(feedViews.contacts.routeAlias);

cy.database("filter", "users").then((users: User[]) => {
ctx.user = users[0];
Expand All @@ -62,6 +61,7 @@ describe("Transaction Feed", function () {
describe("app layout and responsiveness", function () {
it("toggles the navigation drawer", function () {
cy.wait("@notifications");
cy.wait("@publicTransactions");
if (isMobile()) {
cy.getBySel("sidenav-home").should("not.exist");
cy.visualSnapshot("Mobile Initial Side Navigation Not Visible");
Expand All @@ -87,9 +87,15 @@ describe("Transaction Feed", function () {

describe("renders and paginates all transaction feeds", function () {
it("renders transactions item variations in feed", function () {
cy.route("/transactions/public*", "fixture:public-transactions").as(
"mockedPublicTransactions"
);
cy.intercept("GET", "/transactions/public*", {
headers: {
"X-Powered-By": "Express",
Date: new Date().toString(),
},
fixture: "public-transactions.json",
}).as("mockedPublicTransactions");

// Visit page again to trigger call to /transactions/public
cy.visit("/");

cy.wait("@notifications");
Expand Down Expand Up @@ -309,7 +315,7 @@ describe("Transaction Feed", function () {
);

// @ts-ignore
cy.wait(`@${feed.routeAlias}`).then(({ response: { body }, url }) => {
cy.wait(`@${feed.routeAlias}`).then(({ response: { body, url } }) => {
const transactions = body.results as TransactionResponseItem[];
const urlParams = new URLSearchParams(_.last(url.split("?")));

Expand Down
19 changes: 9 additions & 10 deletions cypress/tests/ui/transaction-view.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ describe("Transaction View", function () {
beforeEach(function () {
cy.task("db:seed");

cy.server();
cy.route("GET", "/transactions").as("personalTransactions");
cy.route("GET", "/transactions/public").as("publicTransactions");
cy.route("GET", "/transactions/*").as("getTransaction");
cy.route("PATCH", "/transactions/*").as("updateTransaction");
cy.intercept("GET", "/transactions*").as("personalTransactions");
cy.intercept("GET", "/transactions/public*").as("publicTransactions");
cy.intercept("GET", "/transactions/*").as("getTransaction");
cy.intercept("PATCH", "/transactions/*").as("updateTransaction");

cy.route("GET", "/checkAuth").as("userProfile");
cy.route("GET", "/notifications").as("getNotifications");
cy.route("GET", "/bankAccounts").as("getBankAccounts");
cy.intercept("GET", "/checkAuth").as("userProfile");
cy.intercept("GET", "/notifications").as("getNotifications");
cy.intercept("GET", "/bankAccounts").as("getBankAccounts");

cy.database("find", "users").then((user: User) => {
ctx.authenticatedUser = user;
Expand Down Expand Up @@ -78,7 +77,7 @@ describe("Transaction View", function () {
cy.wait("@getTransaction");

cy.getBySelLike("accept-request").click();
cy.wait("@updateTransaction").should("have.property", "status", 204);
cy.wait("@updateTransaction").its("response.statusCode").should("equal", 204);
cy.getBySelLike("accept-request").should("not.exist");
cy.getBySel("transaction-detail-header").should("be.visible");
cy.visualSnapshot("Transaction Accepted");
Expand All @@ -89,7 +88,7 @@ describe("Transaction View", function () {
cy.wait("@getTransaction");

cy.getBySelLike("reject-request").click();
cy.wait("@updateTransaction").should("have.property", "status", 204);
cy.wait("@updateTransaction").its("response.statusCode").should("equal", 204);
cy.getBySelLike("reject-request").should("not.exist");
cy.getBySel("transaction-detail-header").should("be.visible");
cy.visualSnapshot("Transaction Rejected");
Expand Down
7 changes: 3 additions & 4 deletions cypress/tests/ui/user-settings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ describe("User Settings", function () {
beforeEach(function () {
cy.task("db:seed");

cy.server();
cy.route("PATCH", "/users/*").as("updateUser");
cy.route("GET", "/notifications").as("getNotifications");
cy.intercept("PATCH", "/users/*").as("updateUser");
cy.intercept("GET", "/notifications*").as("getNotifications");

cy.database("find", "users").then((user: User) => {
cy.loginByXstate(user.username);
Expand Down Expand Up @@ -69,7 +68,7 @@ describe("User Settings", function () {
cy.getBySelLike("submit").should("not.be.disabled");
cy.getBySelLike("submit").click();

cy.wait("@updateUser").its("status").should("equal", 204);
cy.wait("@updateUser").its("response.statusCode").should("equal", 204);

if (isMobile()) {
cy.getBySel("sidenav-toggle").click();
Expand Down