Skip to content

Commit

Permalink
test: seed a completed lesson plan
Browse files Browse the repository at this point in the history
  • Loading branch information
codeincontext committed Sep 25, 2024
1 parent 57990a6 commit cec78d6
Show file tree
Hide file tree
Showing 5 changed files with 437 additions and 20 deletions.
52 changes: 52 additions & 0 deletions apps/nextjs/tests-e2e/tests/aila-chat/downloads.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { clerkSetup, setupClerkTestingToken } from "@clerk/testing/playwright";

Check failure on line 1 in apps/nextjs/tests-e2e/tests/aila-chat/downloads.test.ts

View workflow job for this annotation

GitHub Actions / test-e2e

[public] › tests/aila-chat/downloads.test.ts:9:5 › Downloading a completed lesson plan

1) [public] › tests/aila-chat/downloads.test.ts:9:5 › Downloading a completed lesson plan › Setup Test timeout of ***0000ms exceeded.
import { test, expect } from "@playwright/test";

import { TEST_BASE_URL } from "../../config/config";
import { prepareUser } from "../../helpers/auth";
import { bypassVercelProtection } from "../../helpers/vercel";
import { isFinished } from "./helpers";

test("Downloading a completed lesson plan", async ({ page }) => {
await test.step("Setup", async () => {
await clerkSetup();
await bypassVercelProtection(page);
await setupClerkTestingToken({ page });

await prepareUser(page, "typical");

await page.goto(`${TEST_BASE_URL}/aila/e2e-seed-typical-chat`);
await isFinished(page);
});

await test.step("Go to downloads page", async () => {
// Open 'download resources' menu
const downloadResources = page.getByTestId("chat-download-resources");
await downloadResources.click();
page.waitForURL(/\aila\/.*\/download/);
page.getByRole("heading", { name: "Download resources" });

// Click to download lesson plan
const downloadLessonPlan = page.getByTestId("chat-download-lesson-plan");
await downloadLessonPlan.click();

// Skip feedback form
if (await page.getByLabel("Skip").isVisible()) {
await page.getByLabel("Skip").click();
} else {
console.log("Feedback form not found");
}

// Generating
await expect(downloadLessonPlan).toContainText(
"Generating Lesson plan for export",
);

// Generated
await expect(downloadLessonPlan).toContainText(
"Download lesson plan (.docx)",
);
await expect(downloadLessonPlan).toContainText(
"Download Lesson plan (.pdf)",
);
});
});
20 changes: 0 additions & 20 deletions apps/nextjs/tests-e2e/tests/aila-chat/full-romans.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,25 +99,5 @@ test.describe("Authenticated", { tag: "@authenticated" }, () => {

await isFinished(page);
});

await test.step("Go to downloads page", async () => {
// Open 'download resources' menu
const downloadResources = page.getByTestId("chat-download-resources");
await downloadResources.click();
page.waitForURL(/\aila\/.*\/download/);

// Click to download lesson plan
const downloadLessonPlan = page.getByTestId("chat-download-lesson-plan");
await downloadLessonPlan.click();

// Skip feedback form
if (await page.getByLabel("Skip").isVisible()) {
await page.getByLabel("Skip").click();
} else {
console.log("Feedback form not found");
}

page.getByRole("heading", { name: "Download resources" });
});
});
});
10 changes: 10 additions & 0 deletions packages/api/src/router/testSupport/prepareUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ import os from "os";
import { z } from "zod";

import { publicProcedure } from "../../trpc";
import { seedChat } from "./seedChat";

const branch = process.env.VERCEL_GIT_COMMIT_REF ?? os.hostname();

const variants = {
// A user with no issues and a completed lesson plan
typical: {
isDemoUser: false,
region: "GB",
seedChat: true,
},
// A user from a demo region
demo: {
isDemoUser: true,
region: "US",
seedChat: false,
},
} as const;

Expand Down Expand Up @@ -79,6 +84,11 @@ export const prepareUser = publicProcedure
const email = calculateEmailAddress(input.variant);
const user = await findOrCreateUser(email, input.variant);

const shouldSeedChat = variants[input.variant].seedChat;
if (shouldSeedChat) {
await seedChat(user.id);
}

return {
email,
signInToken: await getSignInToken(user.id),
Expand Down
21 changes: 21 additions & 0 deletions packages/api/src/router/testSupport/seedChat/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { prisma } from "@oakai/db";

import { typicalChat } from "./typical";

export const seedChat = async (userId: string) => {
const id = `e2e-typical-user${userId}`;
await prisma.appSession.upsert({
where: {
id,
},
create: {
id,
appId: "lesson-planner",
userId: userId,
output: typicalChat,
},
update: {
output: typicalChat,
},
});
};
Loading

0 comments on commit cec78d6

Please sign in to comment.