Files
psmyrdek 9bdc69bfa9 test(e2e): query module 0 in list detail test
The shared e2e auth account is only enrolled in module 0 (prework), so
module 1 is locked and now returns lessons: [] after the locked-module
mask. Point the list-detail test at module 0 to match what the account
can actually see.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 16:44:49 +02:00

121 lines
3.0 KiB
TypeScript

import { describe, it, expect, beforeAll, afterAll } from "bun:test";
import { binaryExists, runCli, cleanupTempDirs } from "./support/cli";
import { hasAuthSecrets } from "./support/env";
import { ensureSharedAuth, AuthRateLimitedError } from "./support/auth-setup";
describe("e2e: list", () => {
let configDir: string;
let authSkipped = false;
beforeAll(async () => {
if (!binaryExists()) {
throw new Error(
"Binary not found. Run `bun run build:binary` before e2e tests.",
);
}
if (!hasAuthSecrets()) return;
try {
configDir = await ensureSharedAuth();
} catch (err) {
if (err instanceof AuthRateLimitedError) {
authSkipped = true;
return;
}
throw err;
}
}, 60_000);
afterAll(() => cleanupTempDirs());
it(
"list --json returns modules array",
() => {
if (!hasAuthSecrets() || authSkipped) {
console.log("Skipping: E2E auth not available");
return;
}
const result = runCli(["list", "--json"], {
env: { XDG_CONFIG_HOME: configDir, APPDATA: configDir },
});
expect(result.exitCode).toBe(0);
const json = result.json<{
status: string;
data: {
course: string;
modules: Array<{
module: number;
title: string;
state: string;
lessonCount: number;
}>;
};
}>();
expect(json.status).toBe("ok");
expect(json.data.modules.length).toBeGreaterThan(0);
expect(json.data.modules[0]!.module).toBe(0);
expect(json.data.modules[0]!.title).toBeTruthy();
},
{ timeout: 30_000 },
);
it(
"list 0 --json returns lessons for module 0",
() => {
if (!hasAuthSecrets() || authSkipped) {
console.log("Skipping: E2E auth not available");
return;
}
const result = runCli(["list", "0", "--json"], {
env: { XDG_CONFIG_HOME: configDir, APPDATA: configDir },
});
expect(result.exitCode).toBe(0);
const json = result.json<{
status: string;
data: {
module: number;
title: string;
lessons: Array<{ lessonId: string; title: string }>;
};
}>();
expect(json.status).toBe("ok");
expect(json.data.module).toBe(0);
expect(json.data.lessons.length).toBeGreaterThan(0);
},
{ timeout: 30_000 },
);
it(
"list 99 --json exits with USAGE (out of range)",
() => {
if (!hasAuthSecrets() || authSkipped) {
console.log("Skipping: E2E auth not available");
return;
}
const result = runCli(["list", "99", "--json"], {
env: { XDG_CONFIG_HOME: configDir, APPDATA: configDir },
});
expect(result.exitCode).toBe(2);
const json = result.json<{
status: string;
error: { code: string };
}>();
expect(json.status).toBe("error");
expect(json.error.code).toBe("invalid_module");
},
{ timeout: 30_000 },
);
});