veza/tests/e2e/fixtures/factories.ts
senke 172581ff02 chore(cleanup): remove orphan code + archive disabled workflows + .playwright-mcp
Triple cleanup, landed together because they share the same cleanup
branch intent and touch non-overlapping trees.

1. 38× tracked .playwright-mcp/*.yml stage-deleted
   MCP session recordings that had been inadvertently committed.
   .gitignore already covers .playwright-mcp/ (post-audit J2 block
   added in d12b901de). Working tree copies removed separately.

2. 19× disabled CI workflows moved to docs/archive/workflows/
   Legacy .yml.disabled files in .github/workflows/ were 1676 LOC of
   dead config (backend-ci, cd, staging-validation, accessibility,
   chromatic, visual-regression, storybook-audit, contract-testing,
   zap-dast, container-scan, semgrep, sast, mutation-testing,
   rust-mutation, load-test-nightly, flaky-report, openapi-lint,
   commitlint, performance). Preserved in docs/archive/workflows/
   for historical reference; `.github/workflows/` now only lists the
   5 actually-running pipelines.

3. Orphan code removed (0 consumers confirmed via grep)
   - veza-backend-api/internal/repository/user_repository.go
     In-memory UserRepository mock, never imported anywhere.
   - proto/chat/chat.proto
     Chat server Rust deleted 2026-02-22 (commit 279a10d31); proto
     file was orphan spec. Chat lives 100% in Go backend now.
   - veza-common/src/types/chat.rs (Conversation, Message, MessageType,
     Attachment, Reaction)
   - veza-common/src/types/websocket.rs (WebSocketMessage,
     PresenceStatus, CallType — depended on chat::MessageType)
   - veza-common/src/types/mod.rs updated: removed `pub mod chat;`,
     `pub mod websocket;`, and their re-exports.
   Only `veza_common::logging` is consumed by veza-stream-server
   (verified with `grep -r "veza_common::"`). `cargo check` on
   veza-common passes post-removal.

Refs: AUDIT_REPORT.md §8.2 "Code mort / orphelin" + §9.1.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-20 20:33:40 +02:00

82 lines
2.4 KiB
TypeScript

import type { Page } from '@playwright/test';
import { CONFIG } from '../helpers';
/**
* API-driven test data factories.
* Create data via backend API instead of UI interactions.
* Use these to set up test preconditions deterministically.
*/
let counter = 0;
function uniqueId(prefix = 'e2e') {
counter++;
return `${prefix}-${Date.now()}-${counter}`;
}
/**
* Create a test user via registration API.
*/
export async function createUser(
page: Page,
overrides: { email?: string; password?: string; username?: string } = {},
) {
const base = CONFIG.baseURL;
const data = {
email: overrides.email ?? `${uniqueId('test')}@veza.test`,
password: overrides.password ?? 'TestPass123!',
username: overrides.username ?? uniqueId('user'),
display_name: overrides.username ?? 'E2E Test User',
};
const response = await page.request.post(`${base}/api/v1/auth/register`, { data });
if (!response.ok()) {
const body = await response.text();
throw new Error(`createUser failed: ${response.status()}${body}`);
}
return { ...data, response: await response.json() };
}
/**
* Create a playlist via API (requires authenticated page).
*/
export async function createPlaylist(
page: Page,
overrides: { name?: string; description?: string; visibility?: string } = {},
) {
const base = CONFIG.baseURL;
const data = {
name: overrides.name ?? `E2E Playlist ${uniqueId()}`,
description: overrides.description ?? 'Created by E2E factory',
visibility: overrides.visibility ?? 'private',
};
const response = await page.request.post(`${base}/api/v1/playlists`, { data });
if (!response.ok()) {
const body = await response.text();
throw new Error(`createPlaylist failed: ${response.status()}${body}`);
}
return { ...data, response: await response.json() };
}
/**
* Delete a resource via API.
*/
export async function deleteResource(page: Page, endpoint: string) {
const base = CONFIG.baseURL;
const response = await page.request.delete(`${base}${endpoint}`);
return response;
}
/**
* Seed: Ensure at least one track exists for the creator user.
* Returns true if tracks are available.
*/
export async function ensureTracksExist(page: Page): Promise<boolean> {
const base = CONFIG.baseURL;
const response = await page.request.get(`${base}/api/v1/tracks?limit=1`);
if (!response.ok()) return false;
const body = await response.json();
return (body.data?.length ?? 0) > 0;
}