fix(test): repair integration suite after analytics column/endpoint removal (#340)

* fix(test): repair integration suite after analytics column/endpoint removal

#336 moved analytics to a build-time bake: migration 0005 dropped the
users.analytics_enabled and analytics_consent_* columns and removed the
PUT /api/v1/user/analytics endpoint. Two integration tests were left
referencing the old shape and went red on main (13 failures):

- migrate-from-sqlite.test.ts built 1.x SQLite fixtures whose users table
  declared the analytics columns. The generic SELECT *-based importer then
  tried to INSERT them into the 2.0 target, which no longer has those
  columns, failing with Postgres 42703 and rolling back the whole import
  (cascading to all 12 assertions). 1.x never had analytics columns, so the
  fixtures are corrected to drop them. Also removed the now-dead analytics
  entries from the importer's TS/BOOL conversion sets.

- analytics.test.ts asserted the removed PUT endpoint returns 404 but sent
  the request unauthenticated, so the global auth preHandler answered 401
  first. It now authenticates, reaching Fastify's not-found handler (404).

Also removed the stale /api/v1/user/analytics path from openapi.yaml.

Verified locally: full platform integration bucket 1029 passed / 0 failed;
monorepo typecheck clean.

* test(e2e): drop orphaned analytics-consent dismissal calls

#336 deleted the entire analytics consent system (consent page, consent
module, and PUT /api/v1/user/analytics), but six tests/e2e files still
PUT to that removed endpoint to 'dismiss analytics consent.' The calls
were silent no-ops (Playwright request.put / fetch don't throw on 4xx),
so they passed while hitting a dead route.

There is no consent prompt to dismiss anymore, so remove the calls:
- auth.setup.ts / qa-auth.setup.ts: keep the waitForFunction that syncs on
  login completion, drop the now-unused token capture, the dead PUT, and
  the stale 'consent guard' comments.
- rbac / rbac-full / gui-settings-rbac / gui-settings-expanded specs: the
  re-login blocks existed solely to obtain a token for the PUT (reLoginData
  was used nowhere else and the block was the tail of each helper), so
  remove the whole block. The meaningful create-user/login/change-password
  work is untouched.

Verified: no /api/v1/user/analytics refs remain in tests/e2e; biome clean
(no unused vars).
This commit is contained in:
SnapOtter
2026-06-24 13:30:18 +08:00
committed by GitHub
parent 5dac40d782
commit 6917a8b0c7
10 changed files with 28 additions and 172 deletions
+4 -12
View File
@@ -14,23 +14,15 @@ setup("authenticate", async ({ page }) => {
await page.getByLabel("Password").fill("admin");
await page.getByRole("button", { name: /login/i }).click();
// Wait for login to complete and grab the token in one step
const handle = await page.waitForFunction(() => localStorage.getItem("snapotter-token"), null, {
// Wait for login to complete (the token lands in localStorage)
await page.waitForFunction(() => localStorage.getItem("snapotter-token"), null, {
timeout: 15_000,
});
const token = await handle.jsonValue();
// Dismiss analytics consent via API so it won't block any test
const apiBase = process.env.API_URL || "http://localhost:13490";
await page.request.put(`${apiBase}/api/v1/user/analytics`, {
headers: { Authorization: `Bearer ${token}` },
data: { enabled: false },
});
// Now navigate to "/" - consent guard is satisfied
// Navigate to "/" and let any client-side redirect settle
// Use waitUntil: "domcontentloaded" to avoid racing with client-side redirects
await page.goto("/", { waitUntil: "domcontentloaded" });
// Wait for the URL to settle (app may redirect through consent/auth guards)
// Wait for the URL to settle (app may redirect through auth guards)
await page.waitForURL((url) => url.pathname === "/", { timeout: 30_000 }).catch(() => {});
await page.waitForLoadState("load");
-13
View File
@@ -107,19 +107,6 @@ async function createReadyUser(
headers: authJson(loginData.token),
body: JSON.stringify({ currentPassword: password, newPassword: password }),
});
// Re-login and dismiss analytics consent
const reLogin = await fetch(`${API}/api/auth/login`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ username, password }),
});
const reLoginData = await reLogin.json();
await fetch(`${API}/api/v1/user/analytics`, {
method: "PUT",
headers: authJson(reLoginData.token),
body: JSON.stringify({ enabled: false }),
});
}
/** Delete a user by username if it exists. */
-13
View File
@@ -62,19 +62,6 @@ async function createReadyUser(
headers: authJson(loginData.token),
body: JSON.stringify({ currentPassword: password, newPassword: password }),
});
// Re-login and dismiss analytics consent
const reLogin = await fetch(`${API}/api/auth/login`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ username, password }),
});
const reLoginData = await reLogin.json();
await fetch(`${API}/api/v1/user/analytics`, {
method: "PUT",
headers: authJson(reLoginData.token),
body: JSON.stringify({ enabled: false }),
});
}
/** Delete a user by username if it exists. */
+2 -10
View File
@@ -13,18 +13,10 @@ setup("authenticate for QA", async ({ page }) => {
await page.getByLabel("Password").fill("admin");
await page.getByRole("button", { name: /login/i }).click();
const handle = await page.waitForFunction(() => localStorage.getItem("snapotter-token"), null, {
// Wait for login to complete (the token lands in localStorage)
await page.waitForFunction(() => localStorage.getItem("snapotter-token"), null, {
timeout: 15_000,
});
const token = await handle.jsonValue();
// Dismiss analytics consent via API (use same baseURL)
await page.request
.put("/api/v1/user/analytics", {
headers: { Authorization: `Bearer ${token}` },
data: { enabled: false },
})
.catch(() => {});
await page.goto("/", { waitUntil: "domcontentloaded" });
await page.waitForURL((url) => url.pathname === "/", { timeout: 15_000 }).catch(() => {});
-13
View File
@@ -86,19 +86,6 @@ async function createUserWithRole(
if (!changeRes.ok) {
throw new Error(`Failed to clear mustChangePassword for ${username}: ${changeRes.status}`);
}
// Re-login (change-password invalidates sessions) and dismiss analytics consent
const reLogin = await fetch(`${API}/api/auth/login`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ username, password }),
});
const reLoginData = await reLogin.json();
await fetch(`${API}/api/v1/user/analytics`, {
method: "PUT",
headers: authJson(reLoginData.token),
body: JSON.stringify({ enabled: false }),
});
}
/** Delete a user by username if it exists. */
-26
View File
@@ -69,19 +69,6 @@ async function ensureTestUser(adminToken: string): Promise<void> {
if (!changeRes.ok) {
throw new Error(`Failed to clear mustChangePassword: ${changeRes.status}`);
}
// Re-login (change-password invalidates sessions) and dismiss analytics consent
const reLogin = await fetch(`${API}/api/auth/login`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ username: TEST_USER, password: TEST_PASSWORD }),
});
const reLoginData = await reLogin.json();
await fetch(`${API}/api/v1/user/analytics`, {
method: "PUT",
headers: authJson(reLoginData.token),
body: JSON.stringify({ enabled: false }),
});
}
/** Delete the test user if it exists. */
@@ -218,19 +205,6 @@ base.describe("RBAC - Editor sees collaborative tabs", () => {
newPassword: "EditorTest1",
}),
});
// Re-login and dismiss analytics consent
const reLogin = await fetch(`${API}/api/auth/login`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ username: "editortest", password: "EditorTest1" }),
});
const reLoginData = await reLogin.json();
await fetch(`${API}/api/v1/user/analytics`, {
method: "PUT",
headers: authJson(reLoginData.token),
body: JSON.stringify({ enabled: false }),
});
});
base.afterAll(async () => {