mirror of
https://github.com/bitbaum/evig.git
synced 2026-12-04 04:46:59 +01:00
* chore: add a formatter, matching the style this repo already writes singleQuote=true was chosen by counting this repo's own imports, not by fleet decree. The fleet is genuinely split and the two repos that already had a .prettierrc disagreed with each other, so there was no standard to restore. Quote style does not cross repo boundaries; having a gate does. Markdown is ignored for now — prettier rewraps prose, which would bury the real diff. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * style: format with prettier, and close a comment that was never closed The formatter refused this repo outright, which turned out to be a real defect rather than a tooling complaint. kivitendo-intake.css opens a header comment, and line 17 contains an inner /* ⚠ PRÜFEN */ — CSS comments do not nest, so that inner terminator CLOSES the header. Everything after it is parsed as CSS until the stray */ on line 20. A browser mis-parses it the same way. The file exists in two places (public/presentations/ and deliverables/), both carrying the same defect; fixing one still failed the gate, which is how the duplicate surfaced at all. Mechanical otherwise. This SHA is listed in .git-blame-ignore-revs. * chore: teach git blame to skip the reformat * fix: undo a 3-way merge duplication in AdminSidebar.tsx Merging main with -X theirs duplicated a 30-line block: main's currency-sweep commit and this branch's prettier reformat both touched overlapping lines in the single-destination-group render path, and the -X theirs strategy inserted rather than replaced, leaving two near-identical copies and a dangling closing brace — SyntaxError: ',' expected at line 298. The branch has no legitimate change to this file's logic, only formatting, so main's content is correct outright. Took it wholesale rather than hand-editing the merge result. * fix(lint): reattach 5 directives the reformat detached Four eslint-disable-next-line sites for react-hooks/set-state-in-effect and one @ts-expect-error, all the same defect: the directive sat above useEffect( (or above a JSX element), while the statement that actually errors is 1-2 lines further down inside the block. eslint/tsc report at the real statement; the directive, still bound to its original line number, protects nothing there. TimecardReviewDrawer.tsx (x2), DataEntryTabs.tsx, AppointmentBookingForm.tsx, CreatePoolModal.tsx. Same root cause documented for hirnli, fleetcrown and ivy-portal earlier today — a positional directive is a hidden dependency on formatting, and this is the fourth distinct shape it's taken. * fix(i18n): restore a same-line audit-exemption marker Fifth shape of today's positional-directive defect, this time the repo's own i18n-hardcoded-audit convention rather than eslint or tsc: a // i18n-ok comment exempts a hardcoded string only when it trails the SAME line. prettier wrapped this one if-statement's long condition onto its own line, leaving the marker on the return statement below — the exact sibling one line down ('fortgeschrittene bis experten') stayed on one line because it was short enough not to wrap, and it alone kept passing. Restored the one-line form and added // prettier-ignore so a future reformat cannot re-split it. Verified against the real audit script locally: 0 new violations. --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
447 lines
11 KiB
TypeScript
447 lines
11 KiB
TypeScript
import { Client } from 'pg';
|
|
import bcrypt from 'bcryptjs';
|
|
|
|
type DbConfig =
|
|
| { connectionString: string }
|
|
| {
|
|
host: string;
|
|
port: number;
|
|
database: string;
|
|
user: string;
|
|
password: string;
|
|
ssl: false | { rejectUnauthorized: boolean };
|
|
};
|
|
|
|
const ADMIN_EMAIL = process.env.AUTH_TEST_ADMIN_EMAIL || 'e2e-admin@revampit.test';
|
|
const ADMIN_PASSWORD = process.env.AUTH_TEST_ADMIN_PASSWORD || 'E2EAdmin123!';
|
|
// Second staff account — the intake journey needs it because the
|
|
// Vier-Augen-Prinzip forbids the sole worker from signing off final QA.
|
|
const SECOND_ADMIN_EMAIL = process.env.AUTH_TEST_SECOND_ADMIN_EMAIL || 'e2e-admin2@revampit.test';
|
|
const SECOND_ADMIN_PASSWORD = process.env.AUTH_TEST_SECOND_ADMIN_PASSWORD || 'E2EAdmin123!';
|
|
const USER_EMAIL = process.env.AUTH_TEST_USER_EMAIL || 'e2e-user@revampit.test';
|
|
const USER_PASSWORD = process.env.AUTH_TEST_USER_PASSWORD || 'E2EUser123!';
|
|
|
|
function getDbConfig(): DbConfig {
|
|
if (process.env.DATABASE_URL) {
|
|
return { connectionString: process.env.DATABASE_URL };
|
|
}
|
|
return {
|
|
host: process.env.DB_HOST || process.env.PGHOST || 'localhost',
|
|
port: Number(process.env.DB_PORT || process.env.PGPORT || 5433),
|
|
database: process.env.DB_NAME || process.env.PGDATABASE || 'revampit_cms',
|
|
user: process.env.DB_USER || process.env.PGUSER || 'postgres',
|
|
password: process.env.DB_PASSWORD || process.env.PGPASSWORD || 'postgres',
|
|
ssl: process.env.DB_SSL === 'true' ? { rejectUnauthorized: false } : false,
|
|
};
|
|
}
|
|
|
|
async function upsertUser(
|
|
client: Client,
|
|
input: {
|
|
email: string;
|
|
password: string;
|
|
name: string;
|
|
isStaff: boolean;
|
|
isSuperAdmin: boolean;
|
|
permissions: string[];
|
|
},
|
|
): Promise<string> {
|
|
const passwordHash = await bcrypt.hash(input.password, 12);
|
|
const result = await client.query<{ id: string }>(
|
|
`
|
|
INSERT INTO users (
|
|
email,
|
|
name,
|
|
password_hash,
|
|
role,
|
|
"emailVerified",
|
|
is_staff,
|
|
staff_permissions,
|
|
is_super_admin,
|
|
dashboard_mode,
|
|
"createdAt",
|
|
"updatedAt"
|
|
)
|
|
VALUES ($1, $2, $3, $4, NOW(), $5, $6::text[], $7, $8, NOW(), NOW())
|
|
ON CONFLICT (email) DO UPDATE SET
|
|
name = EXCLUDED.name,
|
|
password_hash = EXCLUDED.password_hash,
|
|
role = EXCLUDED.role,
|
|
"emailVerified" = COALESCE(users."emailVerified", NOW()),
|
|
is_staff = EXCLUDED.is_staff,
|
|
staff_permissions = EXCLUDED.staff_permissions,
|
|
is_super_admin = EXCLUDED.is_super_admin,
|
|
dashboard_mode = EXCLUDED.dashboard_mode,
|
|
"updatedAt" = NOW()
|
|
RETURNING id
|
|
`,
|
|
[
|
|
input.email,
|
|
input.name,
|
|
passwordHash,
|
|
input.isStaff ? 'revampit_admin' : 'user',
|
|
input.isStaff,
|
|
input.permissions,
|
|
input.isSuperAdmin,
|
|
input.isStaff ? 'lead' : 'volunteer',
|
|
],
|
|
);
|
|
|
|
const userId = result.rows[0].id;
|
|
await client.query(
|
|
`
|
|
INSERT INTO user_profiles (user_id, display_name, preferred_language, created_at, updated_at)
|
|
VALUES ($1, $2, 'de', NOW(), NOW())
|
|
ON CONFLICT (user_id) DO UPDATE SET
|
|
display_name = EXCLUDED.display_name,
|
|
preferred_language = COALESCE(user_profiles.preferred_language, 'de'),
|
|
updated_at = NOW()
|
|
`,
|
|
[userId, input.name],
|
|
);
|
|
|
|
return userId;
|
|
}
|
|
|
|
async function seed() {
|
|
const client = new Client(getDbConfig());
|
|
await client.connect();
|
|
|
|
try {
|
|
await client.query('BEGIN');
|
|
|
|
const adminId = await upsertUser(client, {
|
|
email: ADMIN_EMAIL,
|
|
password: ADMIN_PASSWORD,
|
|
name: 'E2E Admin',
|
|
isStaff: true,
|
|
isSuperAdmin: true,
|
|
permissions: ['*'],
|
|
});
|
|
|
|
await upsertUser(client, {
|
|
email: SECOND_ADMIN_EMAIL,
|
|
password: SECOND_ADMIN_PASSWORD,
|
|
name: 'E2E Admin Zwei',
|
|
isStaff: true,
|
|
isSuperAdmin: false,
|
|
permissions: ['*'],
|
|
});
|
|
|
|
const userId = await upsertUser(client, {
|
|
email: USER_EMAIL,
|
|
password: USER_PASSWORD,
|
|
name: 'E2E User',
|
|
isStaff: false,
|
|
isSuperAdmin: false,
|
|
permissions: [],
|
|
});
|
|
|
|
await client.query(`DELETE FROM locations WHERE name = 'E2E Workshop Room'`);
|
|
await client.query(
|
|
`
|
|
INSERT INTO technician_profiles (
|
|
user_id,
|
|
business_name,
|
|
business_type,
|
|
description,
|
|
phone,
|
|
address,
|
|
city,
|
|
postal_code,
|
|
canton,
|
|
services_offered,
|
|
specializations,
|
|
is_active,
|
|
status,
|
|
accepts_gratis,
|
|
accepts_kulturlegi,
|
|
max_travel_km,
|
|
service_delivery_types,
|
|
profile_tier,
|
|
updated_at
|
|
)
|
|
VALUES (
|
|
$1,
|
|
'E2E Technik',
|
|
'individual',
|
|
'Deterministic Playwright technician profile.',
|
|
'+41440000000',
|
|
'Birmensdorferstrasse 379',
|
|
'Zurich',
|
|
'8055',
|
|
'ZH',
|
|
ARRAY['hardware_diagnosis', 'computer_repair']::text[],
|
|
ARRAY['laptop']::text[],
|
|
true,
|
|
'active',
|
|
true,
|
|
true,
|
|
25,
|
|
ARRAY['remote', 'onsite', 'flexible']::text[],
|
|
'community',
|
|
NOW()
|
|
)
|
|
ON CONFLICT (user_id) DO UPDATE SET
|
|
description = EXCLUDED.description,
|
|
services_offered = EXCLUDED.services_offered,
|
|
specializations = EXCLUDED.specializations,
|
|
is_active = true,
|
|
status = 'active',
|
|
accepts_gratis = true,
|
|
accepts_kulturlegi = true,
|
|
service_delivery_types = EXCLUDED.service_delivery_types,
|
|
profile_tier = 'community',
|
|
updated_at = NOW()
|
|
`,
|
|
[userId],
|
|
);
|
|
|
|
// Verification lives on user_profiles (identity SSOT since migration 121/122).
|
|
await client.query(
|
|
`
|
|
UPDATE user_profiles
|
|
SET is_verified = true,
|
|
verification_date = COALESCE(verification_date, NOW()),
|
|
updated_at = NOW()
|
|
WHERE user_id = $1
|
|
`,
|
|
[userId],
|
|
);
|
|
|
|
await client.query(`DELETE FROM user_skills WHERE user_id = $1`, [userId]);
|
|
await client.query(
|
|
`
|
|
INSERT INTO user_skills (user_id, skill_id, category_id, verified, verified_at, verified_by, updated_at)
|
|
VALUES
|
|
($1, 'hardware_diagnosis', 'laptop', true, NOW(), $2, NOW()),
|
|
($1, 'linux_support', 'software', true, NOW(), $2, NOW())
|
|
`,
|
|
[userId, adminId],
|
|
);
|
|
|
|
await client.query(`DELETE FROM listings WHERE seller_id = $1 AND title = 'E2E Seed Listing'`, [
|
|
userId,
|
|
]);
|
|
await client.query(
|
|
`
|
|
INSERT INTO service_types (
|
|
slug,
|
|
name,
|
|
description,
|
|
duration_minutes,
|
|
price_cents,
|
|
requires_approval,
|
|
is_active,
|
|
category,
|
|
is_bookable,
|
|
is_featured,
|
|
display_order,
|
|
updated_at
|
|
)
|
|
VALUES (
|
|
'computer-repair-upgrades',
|
|
'Computer repair and upgrades',
|
|
'Seeded E2E service type.',
|
|
60,
|
|
0,
|
|
false,
|
|
true,
|
|
'repair',
|
|
true,
|
|
true,
|
|
1,
|
|
NOW()
|
|
)
|
|
ON CONFLICT (slug) DO UPDATE SET
|
|
name = EXCLUDED.name,
|
|
description = EXCLUDED.description,
|
|
is_active = true,
|
|
is_bookable = true,
|
|
updated_at = NOW()
|
|
`,
|
|
);
|
|
|
|
await client.query(
|
|
`
|
|
INSERT INTO locations (
|
|
name,
|
|
type,
|
|
description,
|
|
address_line1,
|
|
postal_code,
|
|
city,
|
|
canton,
|
|
country,
|
|
max_capacity,
|
|
facilities,
|
|
is_active,
|
|
is_approved,
|
|
approval_status,
|
|
created_by,
|
|
approved_by,
|
|
approved_at,
|
|
updated_at
|
|
)
|
|
VALUES (
|
|
'E2E Workshop Room',
|
|
'venue',
|
|
'Seeded Playwright venue.',
|
|
'Birmensdorferstrasse 379',
|
|
'8055',
|
|
'Zurich',
|
|
'ZH',
|
|
'Switzerland',
|
|
20,
|
|
ARRAY['projector', 'wifi']::text[],
|
|
true,
|
|
true,
|
|
'approved',
|
|
$1,
|
|
$1,
|
|
NOW(),
|
|
NOW()
|
|
)
|
|
ON CONFLICT DO NOTHING
|
|
`,
|
|
[adminId],
|
|
);
|
|
|
|
const workshop = await client.query<{ id: string }>(
|
|
`
|
|
INSERT INTO workshops (
|
|
slug,
|
|
title,
|
|
description,
|
|
short_description,
|
|
category,
|
|
duration,
|
|
duration_minutes,
|
|
level,
|
|
min_participants,
|
|
max_participants,
|
|
price_cents,
|
|
is_active,
|
|
created_by,
|
|
updated_by,
|
|
updated_at
|
|
)
|
|
VALUES (
|
|
'e2e-free-workshop',
|
|
'E2E Free Workshop',
|
|
'Deterministic workshop for Playwright registration journeys.',
|
|
'E2E registration fixture',
|
|
'Hardware',
|
|
'2 hours',
|
|
120,
|
|
'beginner',
|
|
1,
|
|
12,
|
|
0,
|
|
true,
|
|
$1,
|
|
$1,
|
|
NOW()
|
|
)
|
|
ON CONFLICT (slug) DO UPDATE SET
|
|
title = EXCLUDED.title,
|
|
description = EXCLUDED.description,
|
|
is_active = true,
|
|
price_cents = 0,
|
|
max_participants = 12,
|
|
updated_by = EXCLUDED.updated_by,
|
|
updated_at = NOW()
|
|
RETURNING id
|
|
`,
|
|
[adminId],
|
|
);
|
|
|
|
await client.query(
|
|
`DELETE FROM workshop_instances WHERE workshop_id = $1 AND notes = 'Seeded Playwright workshop instance.'`,
|
|
[workshop.rows[0].id],
|
|
);
|
|
await client.query(
|
|
`
|
|
INSERT INTO workshop_instances (
|
|
workshop_id,
|
|
start_date,
|
|
end_date,
|
|
location,
|
|
instructor,
|
|
max_participants,
|
|
notes,
|
|
status,
|
|
instructor_id,
|
|
updated_at
|
|
)
|
|
VALUES (
|
|
$1,
|
|
NOW() + INTERVAL '14 days',
|
|
NOW() + INTERVAL '14 days 2 hours',
|
|
'E2E Workshop Room',
|
|
'E2E Admin',
|
|
12,
|
|
'Seeded Playwright workshop instance.',
|
|
'scheduled',
|
|
$2,
|
|
NOW()
|
|
)
|
|
ON CONFLICT DO NOTHING
|
|
`,
|
|
[workshop.rows[0].id, adminId],
|
|
);
|
|
|
|
await client.query(
|
|
`
|
|
INSERT INTO listings (
|
|
seller_id,
|
|
title,
|
|
description,
|
|
price_chf,
|
|
category,
|
|
condition,
|
|
delivery_options,
|
|
pickup_location,
|
|
payment_mode,
|
|
status,
|
|
is_revampit,
|
|
updated_at
|
|
)
|
|
VALUES (
|
|
$1,
|
|
'E2E Seed Listing',
|
|
'Deterministic listing for local Playwright smoke coverage.',
|
|
1,
|
|
'99',
|
|
'good',
|
|
'pickup',
|
|
'Zurich',
|
|
'secure',
|
|
'active',
|
|
false,
|
|
NOW()
|
|
)
|
|
ON CONFLICT DO NOTHING
|
|
`,
|
|
[userId],
|
|
);
|
|
|
|
await client.query('COMMIT');
|
|
|
|
console.log('E2E seed ready.');
|
|
console.log(`Admin: ${ADMIN_EMAIL}`);
|
|
console.log(`Second admin: ${SECOND_ADMIN_EMAIL}`);
|
|
console.log(`User: ${USER_EMAIL}`);
|
|
} catch (error) {
|
|
await client.query('ROLLBACK');
|
|
throw error;
|
|
} finally {
|
|
await client.end();
|
|
}
|
|
}
|
|
|
|
seed().catch((error) => {
|
|
console.error('Failed to seed E2E data:', error);
|
|
process.exit(1);
|
|
});
|