diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index b1922382..90250dc2 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -44,12 +44,6 @@ jobs: GITHUB_ID: ${{ secrets.E2E_GITHUB_ID }} GITHUB_SECRET: ${{ secrets.E2E_GITHUB_SECRET }} NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }} - E2E_USER_ONE_EMAIL: e2e-user-one@codu.co - E2E_USER_ONE_ID: 8e3179ce-f32b-4d0a-ba3b-234d66b836ad - E2E_USER_ONE_SESSION_ID: df8a11f2-f20a-43d6-80a0-a213f1efedc1 - E2E_USER_TWO_EMAIL: e2e-user-two@codu.co - E2E_USER_TWO_ID: a15a104a-0e34-4101-8800-ed25c9231345 - E2E_USER_TWO_SESSION_ID: 10134766-bc6c-4b52-83d7-46ec0a4cb95d steps: - name: Checkout repository diff --git a/E2E Overview.md b/E2E Overview.md index 54197f59..4493d66a 100644 --- a/E2E Overview.md +++ b/E2E Overview.md @@ -2,15 +2,6 @@ To run the end-to-end tests using Playwright, you need to configure your environment and follow these steps: -### Environment Variables - -Ensure you have the following variables set in your `.env` file: - -- `E2E_USER_ID`: The ID of the E2E user for testing. -- `E2E_USER_EMAIL`: The email of the E2E user for testing. -- `E2E_USER_ONE_SESSION_ID`: The session ID that the user will use to authenticate. - -Note: The sample `.env` file is fine to use. ### Session and User Setup @@ -38,11 +29,9 @@ For UI mode: npx playwright test --ui ``` -### Additional E2E Environment Variables +### Additional E2E constants - **E2E_USER_ONE_SESSION_ID**: This is the session token UUID for one E2E user. - **E2E_USER_TWO_SESSION_ID**: This is the session token UUID for another E2E user. - **E2E_USER_ONE_ID**: The user ID of one of the E2E users. - **E2E_USER_TWO_ID**: The user ID of another E2E user. - -These values are currently hardcoded and should be unique for each user. diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index fad72169..096edb97 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -1,27 +1,27 @@ ## Context -Please provide any relevant information about your setup + ## Expected Behavior -Please describe the behavior you are expecting + ## Current Behavior -What is the current behavior? + ## Screenshots -Drag and drop screenshots here to better describe your issue + ## Steps to reproduce -Please provide detailed steps for reproducing the issue - + ## Additional info -Provide any additional information here + diff --git a/app/(app)/courses/[slug]/[id]/_client.tsx b/app/(app)/courses/[slug]/[id]/_client.tsx new file mode 100644 index 00000000..7359bc40 --- /dev/null +++ b/app/(app)/courses/[slug]/[id]/_client.tsx @@ -0,0 +1,131 @@ +"use client"; +import { FEATURE_FLAGS, isFlagEnabled } from "@/utils/flags"; +import { CircleCheck, SquarePlay } from "lucide-react"; +import { type Session } from "next-auth"; +import { notFound } from "next/navigation"; +import { mockContentList } from "../../mock"; + +interface ContentProps { + session: Session | null; +} + +const Content = ({ session }: ContentProps) => { + const flagEnabled = isFlagEnabled(FEATURE_FLAGS.COURSE_VIDEO); + + if (!flagEnabled) { + notFound(); + } + + return ( +
+
+ + +
+
+ +
+
+ ); +}; + +const VideoPlayer = () => ( +
+
+ +
+
+); + +interface SidebarProps { + contentList: typeof mockContentList; +} + +const Sidebar = ({ contentList }: SidebarProps) => ( +
+ +
+); + +interface SidebarItemProps { + item: (typeof mockContentList)[0]; +} + +const SidebarItem = ({ item }: SidebarItemProps) => ( +
  • +
    +
    +
  • +); + +interface ContentListProps { + contentList: typeof mockContentList; +} + +const ContentList = ({ contentList }: ContentListProps) => { + return ( + <> + {contentList.map( + ({ + id, + title, + longDescription, + description, + publishedDate, + author, + imageLink, + }) => ( +
    +

    + {title} +

    +
  • +
    + +
    +

    + {author} +

    +

    + {publishedDate} +

    +
    +
    +
  • +
    {description}
    +
    {longDescription}
    +
    + ), + )} + + ); +}; + +export default Content; diff --git a/app/(app)/courses/[slug]/[id]/page.tsx b/app/(app)/courses/[slug]/[id]/page.tsx new file mode 100644 index 00000000..a592c480 --- /dev/null +++ b/app/(app)/courses/[slug]/[id]/page.tsx @@ -0,0 +1,13 @@ +import { getServerAuthSession } from "@/server/auth"; +import Content from "./_client"; + +export const metadata = { + title: "Video Course", +}; + +export default async function Page() { + // Example of grabbing session in case it is needed + const session = await getServerAuthSession(); + + return ; +} diff --git a/app/(app)/courses/mock.ts b/app/(app)/courses/mock.ts new file mode 100644 index 00000000..0634867c --- /dev/null +++ b/app/(app)/courses/mock.ts @@ -0,0 +1,130 @@ +// Mock video source (this would typically be a path to a video file) +const mockVideoSrc = "https://youtu.be/Ln4KSN0rchI?t=12"; + +// Mock content list +const mockContentList = [ + { + id: 1, + title: "Introduction to React", + longDescription: + "In this video, we will explore the fundamentals of React, including its component-based architecture, virtual DOM, and how to get started with your first React application. This tutorial guides you through the installation and configuration of essential tools like Node.js, npm, and create-react-app to set up your React development environment.", + description: "Learn the basics of React and its core concepts", + watched: false, + publishedDate: "2023-01-15", + author: "John Doe", + imageLink: "https://example.com/images/react-introduction.jpg", + }, + { + id: 2, + title: "Setting Up Your Development Environment", + longDescription: + "This tutorial guides you through the installation and configuration of essential tools like Node.js, npm, and create-react-app to set up your React development environment.", + description: + "Install and configure the necessary tools for React development", + watched: true, + publishedDate: "2023-01-22", + author: "Jane Smith", + }, + { + id: 3, + title: "Components and Props", + longDescription: + "Dive deep into React's core concepts of components and props. Learn how to create reusable components and pass data between them using props.", + description: "Understand the building blocks of React applications", + watched: true, + publishedDate: "2023-01-29", + author: "John Doe", + }, + { + id: 4, + title: "State and Lifecycle", + longDescription: + "Explore how to manage component state and lifecycle methods to build dynamic and interactive applications with React.", + description: "Manage component state and lifecycle methods", + watched: true, + publishedDate: "2023-02-05", + author: "Jane Smith", + }, + { + id: 5, + title: "Handling Events", + longDescription: + "Learn how to handle user interactions in React, including events like clicks, form submissions, and more.", + description: "Learn how to handle user interactions in React", + watched: true, + publishedDate: "2023-02-12", + author: "John Doe", + }, + { + id: 6, + title: "Conditional Rendering", + longDescription: + "Discover how to display different UI elements based on specific conditions in your React applications.", + description: "Display different UI based on conditions", + watched: false, + publishedDate: "2023-02-19", + author: "Jane Smith", + }, + { + id: 7, + title: "Lists and Keys", + longDescription: + "Learn the best practices for rendering lists of components in React and how to efficiently manage them with unique keys.", + description: "Render multiple components efficiently", + watched: false, + publishedDate: "2023-02-26", + author: "John Doe", + }, + { + id: 8, + title: "Forms in React", + longDescription: + "This video covers how to create and manage forms in React applications, including controlled and uncontrolled components.", + description: "Create and handle form inputs in React applications", + watched: false, + publishedDate: "2023-03-05", + author: "Jane Smith", + }, + { + id: 9, + title: "Hooks: useState and useEffect", + longDescription: + "An introduction to React Hooks, focusing on useState and useEffect to manage state and side effects in functional components.", + description: "Understand and use basic React Hooks", + watched: false, + publishedDate: "2023-03-12", + author: "John Doe", + }, + { + id: 10, + title: "Custom Hooks", + longDescription: + "Learn how to create custom hooks in React to encapsulate and reuse logic across components.", + description: "Create reusable logic with custom Hooks", + watched: false, + publishedDate: "2023-03-19", + author: "Jane Smith", + }, + { + id: 11, + title: "Context API", + longDescription: + "Explore the Context API to manage global state in your React applications without the need for prop drilling.", + description: "Manage global state in your React application", + watched: false, + publishedDate: "2023-03-26", + author: "John Doe", + }, + { + id: 12, + title: "React Router", + longDescription: + "Learn how to implement navigation in your single-page applications using React Router, including dynamic routing and nested routes.", + description: "Implement navigation in your single-page application", + watched: false, + publishedDate: "2023-04-02", + author: "Jane Smith", + }, +]; + +export { mockVideoSrc, mockContentList }; diff --git a/components/editor/editor/components/bubble-menu.tsx b/components/editor/editor/components/bubble-menu.tsx index a1dcf67f..a4d2c892 100644 --- a/components/editor/editor/components/bubble-menu.tsx +++ b/components/editor/editor/components/bubble-menu.tsx @@ -5,7 +5,6 @@ import { useState } from "react"; import { BoldIcon, ItalicIcon, - CodeIcon, } from "lucide-react"; import { NodeSelector } from "./node-selector"; @@ -25,22 +24,16 @@ export const EditorBubbleMenu: FC = (props) => { const items: BubbleMenuItem[] = [ { name: "bold", - isActive: () => props.editor.isActive("bold"), - command: () => props.editor.chain().focus().toggleBold().run(), + isActive: () => props.editor?.isActive("bold") ?? false, + command: () => props.editor?.chain().focus().toggleBold().run(), icon: BoldIcon, }, { name: "italic", - isActive: () => props.editor.isActive("italic"), - command: () => props.editor.chain().focus().toggleItalic().run(), + isActive: () => props.editor?.isActive("italic") ?? false, + command: () => props.editor?.chain().focus().toggleItalic().run(), icon: ItalicIcon, }, - { - name: "code", - isActive: () => props.editor.isActive("code"), - command: () => props.editor.chain().focus().toggleCode().run(), - icon: CodeIcon, - }, ]; const bubbleMenuProps: EditorBubbleMenuProps = { @@ -79,22 +72,16 @@ export const EditorBubbleMenu: FC = (props) => { {...bubbleMenuProps} className="flex w-fit divide-x divide-stone-200 rounded border border-stone-200 bg-white shadow-xl" > - { - setIsNodeSelectorOpen(!isNodeSelectorOpen); - setIsLinkSelectorOpen(false); - }} - /> - { - setIsLinkSelectorOpen(!isLinkSelectorOpen); - setIsNodeSelectorOpen(false); - }} - /> + {props.editor && ( + { + setIsNodeSelectorOpen(!isNodeSelectorOpen); + setIsLinkSelectorOpen(false); + }} + /> + )}
    {items.map((item, index) => ( ))} + {props.editor && ( + { + setIsLinkSelectorOpen(!isLinkSelectorOpen); + }} + /> + )}
    ); diff --git a/components/editor/editor/components/link-selector.tsx b/components/editor/editor/components/link-selector.tsx index 81b0502d..0bedc84f 100644 --- a/components/editor/editor/components/link-selector.tsx +++ b/components/editor/editor/components/link-selector.tsx @@ -1,6 +1,6 @@ import { cn, getUrlFromString } from "@/utils/utils"; import type { Editor } from "@tiptap/core"; -import { Check, Trash } from "lucide-react"; +import { Link } from "lucide-react"; import type { Dispatch, FC, SetStateAction } from "react"; import { useEffect, useRef, useCallback } from "react"; @@ -60,14 +60,11 @@ export const LinkSelector: FC = ({ className="flex h-full items-center space-x-2 px-3 py-1.5 text-sm font-medium text-stone-600 hover:bg-stone-100 active:bg-stone-200" onClick={setLink} > -

    -

    - Link -

    + /> {/* {isOpen && (
    = ({ setIsOpen, }) => { const items: BubbleMenuItem[] = [ - { - name: "Text", - icon: TextIcon, - command: () => - editor.chain().focus().toggleNode("paragraph", "paragraph").run(), - // I feel like there has to be a more efficient way to do this – feel free to PR if you know how! - isActive: () => - editor.isActive("paragraph") && - !editor.isActive("bulletList") && - !editor.isActive("orderedList"), - }, { name: "Heading", icon: Heading, @@ -51,6 +34,13 @@ export const NodeSelector: FC = ({ command: () => editor.chain().focus().toggleHeading({ level: 3 }).run(), isActive: () => editor.isActive("heading", { level: 3 }), }, + { + name: "Text", + icon: TextIcon, + command: () => + editor.chain().focus().toggleNode("paragraph", "paragraph").run(), + isActive: () => editor.isActive("paragraph"), + }, { name: "Quote", icon: TextQuote, @@ -63,24 +53,6 @@ export const NodeSelector: FC = ({ .run(), isActive: () => editor.isActive("blockquote"), }, - { - name: "Code", - icon: Code, - command: () => editor.chain().focus().toggleCodeBlock().run(), - isActive: () => editor.isActive("codeBlock"), - }, - { - name: "Bullet List", - icon: ListOrdered, - command: () => editor.chain().focus().toggleBulletList().run(), - isActive: () => editor.isActive("bulletList"), - }, - { - name: "Numbered List", - icon: ListOrdered, - command: () => editor.chain().focus().toggleOrderedList().run(), - isActive: () => editor.isActive("orderedList"), - }, ]; const activeItem = items.filter((item) => item.isActive()).pop() ?? { @@ -93,6 +65,7 @@ export const NodeSelector: FC = ({ type="button" className="flex h-full items-center gap-1 whitespace-nowrap p-2 text-sm font-medium text-stone-600 hover:bg-stone-100 active:bg-stone-200" onClick={() => setIsOpen(!isOpen)} + aria-expanded={isOpen} > {activeItem?.name} diff --git a/drizzle/seed.ts b/drizzle/seed.ts index ce795e56..256941d7 100644 --- a/drizzle/seed.ts +++ b/drizzle/seed.ts @@ -9,20 +9,6 @@ import { drizzle, type PostgresJsDatabase } from "drizzle-orm/postgres-js"; import postgres from "postgres"; const DATABASE_URL = process.env.DATABASE_URL || ""; -// These can be removed in a follow on PR. Until this hits main we cant add E2E_USER_* stuff to the env. -const E2E_USER_ONE_SESSION_ID = - process.env.E2E_USER_ONE_SESSION_ID || "df8a11f2-f20a-43d6-80a0-a213f1efedc1"; -const E2E_USER_ONE_ID = - process.env.E2E_USER_ONE_ID || "8e3179ce-f32b-4d0a-ba3b-234d66b836ad"; -const E2E_USER_ONE_EMAIL = - process.env.E2E_USER_ONE_EMAIL || "e2e-user-one@codu.co"; - -const E2E_USER_TWO_SESSION_ID = - process.env.E2E_USER_TWO_SESSION_ID || "10134766-bc6c-4b52-83d7-46ec0a4cb95d"; -const E2E_USER_TWO_ID = - process.env.E2E_USER_TWO_ID || "a15a104a-0e34-4101-8800-ed25c9231345"; -const E2E_USER_TWO_EMAIL = - process.env.E2E_USER_TWO_EMAIL || "e2e-user-two@codu.co"; if (!DATABASE_URL) { throw new Error("DATABASE_URL is not set"); @@ -124,62 +110,6 @@ ${chance.paragraph()} return users; }; - const seedE2EUser = async (email: string, id: string, name: string) => { - const [existingE2EUser] = await db - .selectDistinct() - .from(user) - .where(eq(user.id, id)); - - if (existingE2EUser) { - console.log("E2E Test user already exists. Skipping creation"); - return existingE2EUser; - } - - const userData = { - id: id, - username: `${name.split(" ").join("-").toLowerCase()}-${chance.integer({ - min: 0, - max: 999, - })}`, - name, - email, - image: `https://robohash.org/${encodeURIComponent(name)}?bgset=bg1`, - location: chance.country({ full: true }), - bio: chance.sentence({ words: 10 }), - websiteUrl: chance.url(), - }; - const [createdUser] = await db.insert(user).values(userData).returning(); - return createdUser; - }; - - const seedE2EUserSession = async (userId: string, sessionToken: string) => { - const [existingE2EUserSession] = await db - .selectDistinct() - .from(session) - .where(eq(session.sessionToken, sessionToken)); - - if (existingE2EUserSession) { - console.log("E2E Test session already exists. Skipping creation"); - return existingE2EUserSession; - } - - try { - const currentDate = new Date(); - - return await db - .insert(session) - .values({ - userId, - sessionToken, - // Set session to expire in 6 months. - expires: new Date(currentDate.setMonth(currentDate.getMonth() + 6)), - }) - .returning(); - } catch (err) { - console.log(err); - } - }; - const userData = generateUserData(); const addUserData = async () => { @@ -255,19 +185,6 @@ ${chance.paragraph()} try { await addUserData(); - const userOne = await seedE2EUser( - E2E_USER_ONE_EMAIL, - E2E_USER_ONE_ID, - "E2E Test User One", - ); - const userTwo = await seedE2EUser( - E2E_USER_TWO_EMAIL, - E2E_USER_TWO_ID, - "E2E Test User Two", - ); - - await seedE2EUserSession(userOne.id, E2E_USER_ONE_SESSION_ID); - await seedE2EUserSession(userTwo.id, E2E_USER_TWO_SESSION_ID); } catch (error) { console.log("Error:", error); } diff --git a/e2e/constants/constants.ts b/e2e/constants/constants.ts new file mode 100644 index 00000000..c5d853ac --- /dev/null +++ b/e2e/constants/constants.ts @@ -0,0 +1,12 @@ +export const articleContent = + "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas vitae ipsum id metus vestibulum rutrum eget a diam. Integer eget vulputate risus, ac convallis nulla. Mauris sed augue nunc. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam congue posuere tempor. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Ut ac augue non libero ullamcorper ornare. Ut commodo ligula vitae malesuada maximus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Etiam sagittis justo non justo placerat, a dapibus sapien volutpat. Nullam ullamcorper sodales justo sed."; + +export const articleExcerpt = "Lorem ipsum dolor sit amet"; + +export const E2E_USER_ONE_EMAIL = "e2e@codu.co"; +export const E2E_USER_ONE_ID = "8e3179ce-f32b-4d0a-ba3b-234d66b836ad"; +export const E2E_USER_ONE_SESSION_ID = "df8a11f2-f20a-43d6-80a0-a213f1efedc1"; + +export const E2E_USER_TWO_EMAIL = "e2e-user-two@codu.co"; +export const E2E_USER_TWO_ID = "a15a104a-0e34-4101-8800-ed25c9231345"; +export const E2E_USER_TWO_SESSION_ID = "10134766-bc6c-4b52-83d7-46ec0a4cb95d"; diff --git a/e2e/constants/index.ts b/e2e/constants/index.ts new file mode 100644 index 00000000..b04bfcf7 --- /dev/null +++ b/e2e/constants/index.ts @@ -0,0 +1 @@ +export * from "./constants"; diff --git a/e2e/setup.ts b/e2e/setup.ts index 1eb86d9f..f18f308d 100644 --- a/e2e/setup.ts +++ b/e2e/setup.ts @@ -1,24 +1,23 @@ -import dotenv from "dotenv"; import postgres from "postgres"; import { drizzle } from "drizzle-orm/postgres-js"; -import { post, comment } from "@/server/db/schema"; -import { articleContent, articleExcerpt } from "./utils"; - -dotenv.config(); // Load .env file contents into process.env +import { post, comment, session, user } from "@/server/db/schema"; +import { + articleContent, + articleExcerpt, + E2E_USER_ONE_EMAIL, + E2E_USER_ONE_ID, + E2E_USER_ONE_SESSION_ID, + E2E_USER_TWO_EMAIL, + E2E_USER_TWO_ID, + E2E_USER_TWO_SESSION_ID, +} from "./constants"; +import { eq } from "drizzle-orm"; +import { nanoid } from "nanoid"; export const setup = async () => { - // Dynamically import nanoid - const { nanoid } = await import("nanoid"); - - if ( - !process.env.DATABASE_URL || - !process.env.E2E_USER_ONE_ID || - !process.env.E2E_USER_TWO_ID - ) { - throw new Error("Missing env variables for DB clean up script"); - } - - const db = drizzle(postgres(process.env.DATABASE_URL as string)); + const db = drizzle( + postgres("postgresql://postgres:secret@127.0.0.1:5432/postgres"), + ); const addE2EArticleAndComment = async ( authorId: string, @@ -96,13 +95,90 @@ export const setup = async () => { .returning(); }; + const seedE2EUser = async ( + email: string, + id: string, + name: string, + username: string, + ) => { + const [existingE2EUser] = await db + .selectDistinct() + .from(user) + .where(eq(user.id, id)); + + if (existingE2EUser) { + console.log("E2E Test user already exists. Skipping creation"); + return existingE2EUser; + } + + const userData = { + id: id, + username, + name, + email, + image: `https://robohash.org/${encodeURIComponent(name)}?bgset=bg1`, + location: "Ireland", + bio: "Hi I am an robot", + websiteUrl: "codu.co", + }; + const [createdUser] = await db.insert(user).values(userData).returning(); + return createdUser; + }; + + const seedE2EUserSession = async (userId: string, sessionToken: string) => { + const [existingE2EUserSession] = await db + .selectDistinct() + .from(session) + .where(eq(session.sessionToken, sessionToken)); + + if (existingE2EUserSession) { + console.log("E2E Test session already exists. Skipping creation"); + return existingE2EUserSession; + } + + try { + const currentDate = new Date(); + + return await db + .insert(session) + .values({ + userId, + sessionToken, + // Set session to expire in 6 months. + expires: new Date(currentDate.setMonth(currentDate.getMonth() + 6)), + }) + .returning(); + } catch (err) { + console.log(err); + } + }; + try { - console.log("creating articles"); + console.log("Creating users"); + const [userOne, userTwo] = await Promise.all([ + seedE2EUser( + E2E_USER_ONE_EMAIL, + E2E_USER_ONE_ID, + "E2E Test User One", + "e2e-test-user-one-111", + ), + seedE2EUser( + E2E_USER_TWO_EMAIL, + E2E_USER_TWO_ID, + "E2E Test User Two", + "e2e-test-user-two-222", + ), + ]); + + console.log("Creating sessions"); + await Promise.all([ + seedE2EUserSession(userOne.id, E2E_USER_ONE_SESSION_ID), + seedE2EUserSession(userTwo.id, E2E_USER_TWO_SESSION_ID), + ]); + + console.log("Creating articles"); + await addE2EArticleAndComment(E2E_USER_ONE_ID, E2E_USER_TWO_ID); - await addE2EArticleAndComment( - process.env.E2E_USER_ONE_ID as string, - process.env.E2E_USER_TWO_ID as string, - ); console.log("DB setup successful"); } catch (err) { console.log("Error while setting up DB before E2E test run", err); diff --git a/e2e/teardown.ts b/e2e/teardown.ts index d5b1a416..bb06e6a0 100644 --- a/e2e/teardown.ts +++ b/e2e/teardown.ts @@ -1,33 +1,22 @@ -import dotenv from "dotenv"; import postgres from "postgres"; - -dotenv.config(); // Load .env file contents into process.env +import { E2E_USER_ONE_ID, E2E_USER_TWO_ID } from "./constants"; export const teardown = async () => { try { - if ( - !process.env.DATABASE_URL || - !process.env.E2E_USER_ONE_ID || - !process.env.E2E_USER_TWO_ID - ) - throw new Error("Missing env variables for DB clean up script"); - const db = postgres(process.env.DATABASE_URL as string); - - // the test suit adds posts created by the E2E users. We want to remove them between test runs - await db` - DELETE FROM "Post" WHERE "userId" = ${process.env.E2E_USER_ONE_ID as string} - `; - await db` - DELETE FROM "Post" WHERE "userId" = ${process.env.E2E_USER_TWO_ID as string} - `; - // the test suit adds comments created by the E2E user. We want to remove them between test runs - await db` - DELETE FROM "Comment" WHERE "userId" = ${process.env.E2E_USER_ONE_ID as string} - `; - await db` - DELETE FROM "Comment" WHERE "userId" = ${process.env.E2E_USER_TWO_ID as string} - `; + const db = postgres("postgresql://postgres:secret@127.0.0.1:5432/postgres"); + await Promise.all([ + // the test suit adds posts created by the E2E users. We want to remove them between test runs + db` + DELETE FROM "Post" WHERE "userId" IN(${E2E_USER_ONE_ID}, ${E2E_USER_TWO_ID}) + `, + // the test suite adds comments created by the E2E user. We want to remove them between test runs + db` + DELETE FROM "Comment" WHERE "userId" IN(${E2E_USER_ONE_ID}, ${E2E_USER_TWO_ID}) + `, + db` + DELETE FROM "user" WHERE "id" IN(${E2E_USER_ONE_ID}, ${E2E_USER_TWO_ID})`, + ]); console.log("DB clean up successful"); } catch (err) { console.log("Error while cleaning up DB after E2E test run", err); diff --git a/e2e/utils/utils.ts b/e2e/utils/utils.ts index 1d918d92..408f16e6 100644 --- a/e2e/utils/utils.ts +++ b/e2e/utils/utils.ts @@ -1,13 +1,12 @@ import { expect, Page } from "@playwright/test"; +import { E2E_USER_ONE_SESSION_ID, E2E_USER_TWO_SESSION_ID } from "../constants"; export const loggedInAsUserOne = async (page: Page) => { try { - expect(process.env.E2E_USER_ONE_SESSION_ID).toBeDefined(); - await page.context().addCookies([ { name: "next-auth.session-token", - value: process.env.E2E_USER_ONE_SESSION_ID as string, + value: E2E_USER_ONE_SESSION_ID, domain: "localhost", path: "/", sameSite: "Lax", @@ -26,14 +25,12 @@ export const loggedInAsUserOne = async (page: Page) => { export const loggedInAsUserTwo = async (page: Page) => { try { - expect(process.env.E2E_USER_TWO_SESSION_ID).toBeDefined(); - await page.context().clearCookies(); await page.context().addCookies([ { name: "next-auth.session-token", - value: process.env.E2E_USER_TWO_SESSION_ID as string, + value: E2E_USER_TWO_SESSION_ID, domain: "localhost", path: "/", sameSite: "Lax", diff --git a/sample.env b/sample.env index c3602d3a..b3601bc9 100644 --- a/sample.env +++ b/sample.env @@ -4,9 +4,3 @@ GITLAB_ID= ### Replace with GitLab OAuth ID (https://gitlab.com/-/user_settings GITLAB_SECRET= ### Replace with GitLab OAuth Secret (https://gitlab.com/-/user_settings/applications) NEXTAUTH_URL=http://localhost:3000/api/auth DATABASE_URL=postgresql://postgres:secret@127.0.0.1:5432/postgres - -E2E_USER_EMAIL=e2e@codu.co -E2E_USER_ONE_ID=8e3179ce-f32b-4d0a-ba3b-234d66b836ad -E2E_USER_TWO_ID=a15a104a-0e34-4101-8800-ed25c9231345 -E2E_USER_ONE_SESSION_ID=df8a11f2-f20a-43d6-80a0-a213f1efedc1 -E2E_USER_TWO_SESSION_ID=10134766-bc6c-4b52-83d7-46ec0a4cb95d diff --git a/utils/flags.ts b/utils/flags.ts index 005587d3..a6f9cc51 100644 --- a/utils/flags.ts +++ b/utils/flags.ts @@ -2,6 +2,7 @@ import { posthog } from "posthog-js"; export const FEATURE_FLAGS = { FEATURE_FLAG_TEST: "feature-flag-test", + COURSE_VIDEO: "course-video", JOBS: "jobs", // Add more feature flags as needed } as const;