Skip to content

Commit

Permalink
Merge branch 'main' into fix/no_live_openai
Browse files Browse the repository at this point in the history
  • Loading branch information
JBR90 committed Jan 7, 2025
2 parents bf9c98c + 41b68eb commit 0f60bbe
Show file tree
Hide file tree
Showing 18 changed files with 788 additions and 694 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const chatContext: Partial<ChatContextProps> = {
keyStage: "Key Stage 2",
subject: "Science",
topic: "Amphibians",
basedOn: { title: "Frogs in Modern Britain" },
basedOn: { title: "Frogs in Modern Britain", id: "123" },
learningOutcome:
"To understand the importance of frogs in British society and culture",
},
Expand Down
10 changes: 8 additions & 2 deletions apps/nextjs/src/middlewares/auth.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,9 @@ const isPreloadableRoute = createRouteMatcher([

const isOnboardingRoute = createRouteMatcher([
"/onboarding",
"/sign-in",
// NOTE: Be careful that this request doesn't batch as it will change the path
"/api/trpc/main/auth.setDemoStatus",
"/api/trpc/main/auth.acceptTerms",
"/api/trpc/main",
]);

const isHomepage = createRouteMatcher(["/"]);
Expand Down Expand Up @@ -120,6 +118,14 @@ function conditionallyProtectRoute(
return NextResponse.redirect(new URL("/onboarding", req.url));
}
}
if (
userId &&
isOnboardingRoute(req) &&
!needsToCompleteOnboarding(sessionClaims)
) {
log("Already onboarded: REDIRECT");
return NextResponse.redirect(new URL("/", req.url));
}

if (isPublicRoute(req)) {
log("Public route: ALLOW");
Expand Down
4 changes: 3 additions & 1 deletion apps/nextjs/tests-e2e/helpers/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export async function prepareUser(
| "nearly-banned"
| "modify-lesson-plan"
| "nearly-rate-limited"
| "sharing-chat",
| "sharing-chat"
| "needs-onboarding"
| "needs-demo-status",
) {
return await test.step("Prepare user", async () => {
const [login] = await Promise.all([
Expand Down
64 changes: 64 additions & 0 deletions apps/nextjs/tests-e2e/tests/onboarding.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { test, expect } from "@playwright/test";

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

test("Landing on the site when not onboarded", async ({ page }) => {
await test.step("Setup", async () => {
await bypassVercelProtection(page);
await prepareUser(page, "needs-onboarding");
await page.goto(`${TEST_BASE_URL}/aila`);

await page.waitForURL(`${TEST_BASE_URL}/onboarding`);
await expect(
page.getByText("This product is experimental and uses AI"),
).toBeVisible();
});

await test.step("Toggle terms", async () => {
const termsHeading = page.getByRole("heading", {
name: "Terms and Conditions",
exact: true,
});
await expect(termsHeading).not.toBeVisible();

await page.getByText("See terms").click();
await expect(termsHeading).toBeVisible();
await page.getByText("See terms").click();
await expect(termsHeading).not.toBeVisible();
});

await test.step("Submit", async () => {
await page.getByText("I understand").click();

await page.waitForURL(`${TEST_BASE_URL}/?reason=onboarded`);
});
});

test("Onboarded without a demo status", async ({ page }) => {
await test.step("Setup", async () => {
await bypassVercelProtection(page);
await prepareUser(page, "needs-demo-status");
await page.goto(`${TEST_BASE_URL}/aila`);

await page.waitForURL(`${TEST_BASE_URL}/onboarding`);
await expect(page.getByText("Preparing your account")).toBeVisible();
});

await test.step("Redirect", async () => {
await page.waitForURL(`${TEST_BASE_URL}/?reason=metadata-upgraded`);
});
});

test("Loading onboarding when already onboarded", async ({ page }) => {
await test.step("Setup", async () => {
await bypassVercelProtection(page);
await prepareUser(page, "typical");
await page.goto(`${TEST_BASE_URL}/onboarding`);
});

await test.step("Redirect", async () => {
await page.waitForURL(`${TEST_BASE_URL}/`);
});
});
2 changes: 2 additions & 0 deletions packages/aila/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"ai": "^3.3.26",
"american-british-english-translator": "^0.2.1",
"cloudinary": "^1.41.1",
"dedent": "^1.5.3",
"dotenv-cli": "^6.0.0",
"jsonrepair": "^3.8.0",
"openai": "^4.58.1",
Expand All @@ -51,6 +52,7 @@
"@pollyjs/adapter-node-http": "^6.0.6",
"@pollyjs/core": "^6.0.6",
"@pollyjs/persister-fs": "^6.0.6",
"@types/dedent": "^0.7.2",
"@types/jest": "^29.5.14",
"jest": "^29.7.0",
"setup-polly-jest": "^0.11.0",
Expand Down
20 changes: 2 additions & 18 deletions packages/aila/src/protocol/jsonPatchProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ export type MessagePartType =
| "id";

export const MessagePartDocumentSchemaByType: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[K in MessagePartType]: z.ZodSchema<any>;
} = {
moderation: ModerationDocumentSchema,
Expand All @@ -533,7 +533,7 @@ export const MessagePartDocumentSchemaByType: {
id: MessageIdDocumentSchema,
};

const MessagePartSchema = z.object({
export const MessagePartSchema = z.object({
type: z.literal("message-part"),
id: z.string(),
isPartial: z.boolean(),
Expand Down Expand Up @@ -843,21 +843,5 @@ export function applyLessonPlanPatch(
});
}

// #TODO This is slightly ridiculous! Remove this once we are live
if (updatedLessonPlan.misconceptions) {
const working = updatedLessonPlan.misconceptions;
for (const misconception of working) {
misconception.description =
misconception.description ?? misconception.definition;
}
updatedLessonPlan.misconceptions = working;
}
if (updatedLessonPlan.keywords) {
const working = updatedLessonPlan.keywords;
for (const keyword of working) {
keyword.definition = keyword.definition ?? keyword.description;
}
updatedLessonPlan.keywords = working;
}
return updatedLessonPlan;
}
Loading

0 comments on commit 0f60bbe

Please sign in to comment.