diff --git a/cypress.json b/cypress.json
index 6ae01d9c2..6ae1ae602 100644
--- a/cypress.json
+++ b/cypress.json
@@ -1,5 +1,4 @@
{
"baseUrl": "http://localhost:3000",
- "fixturesFolder": false,
"pluginsFile": false
}
diff --git a/cypress/fixtures/user.nzap.json b/cypress/fixtures/user.nzap.json
new file mode 100644
index 000000000..9846c9b68
--- /dev/null
+++ b/cypress/fixtures/user.nzap.json
@@ -0,0 +1,9 @@
+{
+ "id": 12,
+ "username": "NZAP",
+ "discriminator": "6227",
+ "discordId": "455039198672453645",
+ "discordAvatar": "f809176af93132c3db5f0a5019e96339",
+ "iat": 1614241069,
+ "exp": 1616833069
+}
diff --git a/cypress/fixtures/user.sendou.json b/cypress/fixtures/user.sendou.json
new file mode 100644
index 000000000..8b75b2798
--- /dev/null
+++ b/cypress/fixtures/user.sendou.json
@@ -0,0 +1,9 @@
+{
+ "id": 11,
+ "username": "Sendou",
+ "discriminator": "4059",
+ "discordId": "79237403620945920",
+ "discordAvatar": "1e0968214a6ea74aebce4bbd699d6aae",
+ "iat": 1614241069,
+ "exp": 1616833069
+}
diff --git a/cypress/integration/plus.spec.ts b/cypress/integration/plus.spec.ts
index cb73ff073..39d44f4b9 100644
--- a/cypress/integration/plus.spec.ts
+++ b/cypress/integration/plus.spec.ts
@@ -1,10 +1,7 @@
///
+///
-context("Actions", () => {
- // beforeEach(() => {
- // cy.visit('/plus/history')
- // })
-
+context("Plus Voting History", () => {
it("show 404 if invalid route ([[...slug]])", () => {
cy.visit("/plus/history/asd", { failOnStatusCode: false });
cy.contains("Not Found");
@@ -13,7 +10,14 @@ context("Actions", () => {
cy.contains("Not Found");
});
- it("correctly calculates voting percentage", () => {
- getPercentageFromCounts;
- });
+ it("correctly calculates voting percentage", () => {});
+});
+
+context("Plus Home Page", () => {
+ beforeEach(() => {
+ cy.login("sendou");
+ cy.visit("/plus");
+ });
+
+ it.only("correctly calculates voting percentage", () => {});
});
diff --git a/cypress/support/commands.js b/cypress/support/commands.js
deleted file mode 100644
index ca4d256f3..000000000
--- a/cypress/support/commands.js
+++ /dev/null
@@ -1,25 +0,0 @@
-// ***********************************************
-// This example commands.js shows you how to
-// create various custom commands and overwrite
-// existing commands.
-//
-// For more comprehensive examples of custom
-// commands please read more here:
-// https://on.cypress.io/custom-commands
-// ***********************************************
-//
-//
-// -- This is a parent command --
-// Cypress.Commands.add("login", (email, password) => { ... })
-//
-//
-// -- This is a child command --
-// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
-//
-//
-// -- This is a dual command --
-// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
-//
-//
-// -- This will overwrite an existing command --
-// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
diff --git a/cypress/support/index.d.ts b/cypress/support/index.d.ts
new file mode 100644
index 000000000..ed795c9c7
--- /dev/null
+++ b/cypress/support/index.d.ts
@@ -0,0 +1,18 @@
+// in cypress/support/index.d.ts
+// load type definitions that come with Cypress module
+///
+
+declare namespace Cypress {
+ interface Chainable {
+ /**
+ * Custom command to select DOM element by data-cy attribute.
+ * @example cy.dataCy('greeting')
+ */
+ dataCy(value: string): Chainable;
+ /**
+ * Mock login
+ * @example cy.login('sendou')
+ */
+ login(user: "sendou" | "nzap"): Chainable;
+ }
+}
diff --git a/cypress/support/index.js b/cypress/support/index.js
deleted file mode 100644
index d68db96df..000000000
--- a/cypress/support/index.js
+++ /dev/null
@@ -1,20 +0,0 @@
-// ***********************************************************
-// This example support/index.js is processed and
-// loaded automatically before your test files.
-//
-// This is a great place to put global configuration and
-// behavior that modifies Cypress.
-//
-// You can change the location of this file or turn off
-// automatically serving support files with the
-// 'supportFile' configuration option.
-//
-// You can read more here:
-// https://on.cypress.io/configuration
-// ***********************************************************
-
-// Import commands.js using ES2015 syntax:
-import './commands'
-
-// Alternatively you can use CommonJS syntax:
-// require('./commands')
diff --git a/cypress/support/index.ts b/cypress/support/index.ts
new file mode 100644
index 000000000..bfddf8f78
--- /dev/null
+++ b/cypress/support/index.ts
@@ -0,0 +1,13 @@
+Cypress.Commands.add("dataCy", (value: string) => {
+ return cy.get(`[data-cy=${value}]`);
+});
+
+Cypress.Commands.add("login", (user: "sendou" | "nzap") => {
+ return cy.fixture(`user.${user}`).then((u) => {
+ const d = new Date();
+ u.iat = Math.floor(d.setHours(-168) / 1000);
+ u.exp = Math.floor(d.setHours(336) / 1000);
+ cy.setCookie("mockUser", JSON.stringify(u));
+ cy.intercept("/api/auth/session", u);
+ });
+});
diff --git a/lib/api.ts b/lib/api.ts
index 11f925503..acb5c20fc 100644
--- a/lib/api.ts
+++ b/lib/api.ts
@@ -2,6 +2,14 @@ import { User } from "@prisma/client";
import { NextApiRequest } from "next";
import { getSession } from "next-auth/client";
-export const getMySession = (req: NextApiRequest): Promise =>
+export const getMySession = (req: NextApiRequest): Promise => {
+ if (
+ process.env.NODE_ENV === "development" &&
+ req.headers.cookie?.includes("mockUser=")
+ ) {
+ return JSON.parse(req.headers.cookie.replace("mockUser=", ""));
+ }
+
// @ts-expect-error
- getSession({ req });
+ return getSession({ req });
+};
diff --git a/package.json b/package.json
index 32e28c9a7..e7d644b7e 100644
--- a/package.json
+++ b/package.json
@@ -16,7 +16,9 @@
"compile": "lingui compile",
"restore": "pg_restore -d 'postgresql://sendou@localhost:5432/postgres' --jobs 4 dumped.sql --clean",
"seed": "prisma db seed --preview-feature",
- "cy:open": "cypress open"
+ "cy:open": "cypress open",
+ "cy:clearcache": "cypress cache clear",
+ "cy:install": "cypress install"
},
"dependencies": {
"@chakra-ui/icons": "^1.0.5",
diff --git a/prisma/mocks/plus.ts b/prisma/mocks/plus.ts
index 1b52134b2..b53bc460d 100644
--- a/prisma/mocks/plus.ts
+++ b/prisma/mocks/plus.ts
@@ -53,6 +53,16 @@ export const getPlusStatusesData = (): Prisma.PlusStatusCreateManyInput[] => {
userId: 10,
region: "NA",
},
+ {
+ userId: 11,
+ region: "EU",
+ membershipTier: 1,
+ },
+ {
+ userId: 12,
+ region: "EU",
+ membershipTier: 2,
+ },
];
};
@@ -62,7 +72,7 @@ export const getPlusSuggestionsData = (): Prisma.PlusSuggestionCreateManyInput[]
description: "yooo so cracked",
region: "NA",
tier: 2,
- suggestedId: 10,
+ suggestedId: 11,
suggesterId: 1,
},
];
diff --git a/prisma/mocks/user.ts b/prisma/mocks/user.ts
index 0ee35515e..e333a139f 100644
--- a/prisma/mocks/user.ts
+++ b/prisma/mocks/user.ts
@@ -2,20 +2,27 @@ import { Prisma } from "@prisma/client";
export const getUsersData = (): Prisma.UserCreateManyInput[] => {
return [
+ ...new Array(10).fill(null).map((_, i) => ({
+ id: i + 1,
+ discordId: padWithZero(i, 17),
+ discriminator: padWithZero(i, 4),
+ username: `User${i + 1}`,
+ })),
{
- id: 1,
+ id: 11,
discordId: "79237403620945920",
username: "Sendou",
discriminator: "4059",
patreonTier: 1,
discordAvatar: "1e0968214a6ea74aebce4bbd699d6aae",
},
- ...new Array(9).fill(null).map((_, i) => ({
- id: i + 2,
- discordId: padWithZero(i, 17),
- discriminator: padWithZero(i, 4),
- username: `User${i + 2}`,
- })),
+ {
+ id: 12,
+ discordId: "455039198672453645",
+ username: "NZAP",
+ discriminator: "6227",
+ discordAvatar: "f809176af93132c3db5f0a5019e96339",
+ },
];
};