All Tests Work! Password reset implemented. Users list sorted.
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
|
||||
import { test as base, expect } from '@playwright/test';
|
||||
import { request } from '@playwright/test';
|
||||
import { exec as cp_exec } from 'child_process';
|
||||
import { promisify } from 'util';
|
||||
|
||||
const exec = promisify(cp_exec);
|
||||
|
||||
// Define the type for our custom fixtures
|
||||
type MyFixtures = {
|
||||
createUniqueUser: () => Promise<{ email: string, password: string, id: string, token: string }>;
|
||||
createAdminUser: () => Promise<{ email: string, password: string, id: string, token: string }>;
|
||||
};
|
||||
|
||||
// Extend the base test with our custom fixture
|
||||
@@ -50,6 +55,34 @@ export const test = base.extend<MyFixtures>({
|
||||
// Given the requirements "delete own account" exists (5.6), we could theoretically login and delete.
|
||||
// For now we skip auto-cleanup to keep it simple, assuming test DB is reset periodically.
|
||||
},
|
||||
|
||||
createAdminUser: async ({ createUniqueUser }, use) => {
|
||||
// Setup: Helper function to create an admin user (create regular -> promote)
|
||||
const createAdmin = async () => {
|
||||
const user = await createUniqueUser(); // Create a regular user first
|
||||
|
||||
console.log(`Promoting user ${user.email} to ADMIN...`);
|
||||
try {
|
||||
const { stdout, stderr } = await exec(`npx ts-node promote_admin.ts ${user.email}`, {
|
||||
cwd: 'server',
|
||||
env: { ...process.env, APP_MODE: 'test', DATABASE_URL: 'file:./prisma/test.db', DATABASE_URL_TEST: 'file:./prisma/test.db' }
|
||||
});
|
||||
if (stderr) {
|
||||
console.error(`Promote Admin Stderr: ${stderr}`);
|
||||
}
|
||||
console.log(`Promote Admin Stdout: ${stdout}`);
|
||||
if (!stdout.includes(`User ${user.email} promoted to ADMIN`)) {
|
||||
throw new Error('Admin promotion failed or unexpected output.');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error promoting user ${user.email} to ADMIN:`, error);
|
||||
throw error;
|
||||
}
|
||||
return user;
|
||||
};
|
||||
|
||||
await use(createAdmin);
|
||||
},
|
||||
});
|
||||
|
||||
export { expect };
|
||||
|
||||
Reference in New Issue
Block a user