diff --git a/.eslintignore b/.eslintignore index 2cb7d2a..80cbd90 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ **/*.js +docs diff --git a/cypress/e2e/smoke.cy.ts b/cypress/e2e/smoke.cy.ts index adb60f6..0f5a10b 100644 --- a/cypress/e2e/smoke.cy.ts +++ b/cypress/e2e/smoke.cy.ts @@ -1,48 +1,5 @@ -import { faker } from "@faker-js/faker"; - describe("smoke tests", () => { afterEach(() => { cy.cleanupUser(); }); - - it("should allow you to register and login", () => { - const loginForm = { - email: `${faker.internet.userName()}@example.com`, - password: faker.internet.password(), - }; - cy.then(() => ({ email: loginForm.email })).as("user"); - - cy.visitAndCheck("/"); - cy.findByRole("link", { name: /sign up/i }).click(); - - cy.findByRole("textbox", { name: /email/i }).type(loginForm.email); - cy.findByLabelText(/password/i).type(loginForm.password); - cy.findByRole("button", { name: /create account/i }).click(); - - cy.findByRole("link", { name: /notes/i }).click(); - cy.findByRole("button", { name: /logout/i }).click(); - cy.findByRole("link", { name: /log in/i }); - }); - - it("should allow you to make a note", () => { - const testNote = { - title: faker.lorem.words(1), - body: faker.lorem.sentences(1), - }; - cy.login(); - cy.visitAndCheck("/"); - - cy.findByRole("link", { name: /notes/i }).click(); - cy.findByText("No notes yet"); - - cy.findByRole("link", { name: /\+ new note/i }).click(); - - cy.findByRole("textbox", { name: /title/i }).type(testNote.title); - cy.findByRole("textbox", { name: /body/i }).type(testNote.body); - cy.findByRole("button", { name: /save/i }).click(); - - cy.findByRole("button", { name: /delete/i }).click(); - - cy.findByText("No notes yet"); - }); }); diff --git a/cypress/support/create-user.ts b/cypress/support/create-user.ts deleted file mode 100644 index a466ea2..0000000 --- a/cypress/support/create-user.ts +++ /dev/null @@ -1,48 +0,0 @@ -// Use this to create a new user and login with that user -// Simply call this with: -// npx ts-node --require tsconfig-paths/register ./cypress/support/create-user.ts username@example.com -// and it will log out the cookie value you can use to interact with the server -// as that new user. - -import { installGlobals } from "@remix-run/node"; -import { parse } from "cookie"; - -import { createUser } from "~/models/user.server"; -import { createUserSession } from "~/session.server"; - -installGlobals(); - -async function createAndLogin(email: string) { - if (!email) { - throw new Error("email required for login"); - } - if (!email.endsWith("@example.com")) { - throw new Error("All test emails must end in @example.com"); - } - - const user = await createUser(email, "myreallystrongpassword"); - - const response = await createUserSession({ - request: new Request("test://test"), - userId: user.id, - remember: false, - redirectTo: "/", - }); - - const cookieValue = response.headers.get("Set-Cookie"); - if (!cookieValue) { - throw new Error("Cookie missing from createUserSession response"); - } - const parsedCookie = parse(cookieValue); - // we log it like this so our cypress command can parse it out and set it as - // the cookie value. - console.log( - ` - - ${parsedCookie.__session} - - `.trim(), - ); -} - -createAndLogin(process.argv[2]); diff --git a/cypress/support/delete-user.ts b/cypress/support/delete-user.ts deleted file mode 100644 index 2b45754..0000000 --- a/cypress/support/delete-user.ts +++ /dev/null @@ -1,37 +0,0 @@ -// Use this to delete a user by their email -// Simply call this with: -// npx ts-node --require tsconfig-paths/register ./cypress/support/delete-user.ts username@example.com -// and that user will get deleted - -import { PrismaClientKnownRequestError } from "@prisma/client/runtime"; -import { installGlobals } from "@remix-run/node"; - -import { prisma } from "~/db.server"; - -installGlobals(); - -async function deleteUser(email: string) { - if (!email) { - throw new Error("email required for login"); - } - if (!email.endsWith("@example.com")) { - throw new Error("All test emails must end in @example.com"); - } - - try { - await prisma.user.delete({ where: { email } }); - } catch (error) { - if ( - error instanceof PrismaClientKnownRequestError && - error.code === "P2025" - ) { - console.log("User not found, so no need to delete"); - } else { - throw error; - } - } finally { - await prisma.$disconnect(); - } -} - -deleteUser(process.argv[2]); diff --git a/tsconfig.json b/tsconfig.json index 9bacef8..9d0e85d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,5 @@ { - "exclude": ["./cypress", "./cypress.config.ts"], + "exclude": ["./cypress", "./cypress.config.ts", "./docs"], "include": ["remix.env.d.ts", "**/*.ts", "**/*.tsx"], "compilerOptions": { "lib": ["DOM", "DOM.Iterable", "ES2019"],