MAI CALL - step 5
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* AC verification for Passo 5:
|
||||
* workstation.list and user.listOperators return seeds from Passo 2.
|
||||
*/
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { config as loadEnv } from 'dotenv';
|
||||
|
||||
const here = path.dirname(fileURLToPath(import.meta.url));
|
||||
loadEnv({ path: path.resolve(here, '../.env') });
|
||||
|
||||
import { prisma, tenantScoped } from '../packages/db/src/index.js';
|
||||
import { appRouter, createTRPCContext } from '../packages/api/src/index.js';
|
||||
import { createCallerFactory } from '../packages/api/src/trpc.js';
|
||||
|
||||
async function main() {
|
||||
// Resolve the demo tenant and admin user from the real DB
|
||||
const adminUser = await prisma.user.findFirst({ where: { email: 'admin@demo.local' } });
|
||||
if (!adminUser) throw new Error('Run pnpm db:seed first');
|
||||
|
||||
const ctx = await createTRPCContext({
|
||||
user: {
|
||||
id: adminUser.id,
|
||||
email: adminUser.email,
|
||||
role: adminUser.role as 'ADMIN',
|
||||
tenantId: adminUser.tenantId,
|
||||
},
|
||||
headers: new Headers(),
|
||||
});
|
||||
|
||||
const caller = createCallerFactory(appRouter)(ctx);
|
||||
|
||||
// workstation.list
|
||||
const workstations = await caller.workstation.list();
|
||||
const wsCodes = workstations.map((w) => w.code).sort();
|
||||
const expectedCodes = ['CTR04', 'MTG_01', 'QVN_RTL_2'];
|
||||
if (JSON.stringify(wsCodes) !== JSON.stringify(expectedCodes)) {
|
||||
throw new Error(`workstation.list mismatch: got ${JSON.stringify(wsCodes)}`);
|
||||
}
|
||||
console.log(`workstation.list → ${wsCodes.join(', ')} ✓`);
|
||||
|
||||
// user.listOperators
|
||||
const operators = await caller.user.listOperators();
|
||||
const opEmails = operators.map((u) => u.email).sort();
|
||||
const expectedEmails = ['op1@demo.local', 'op2@demo.local', 'op3@demo.local'];
|
||||
if (JSON.stringify(opEmails) !== JSON.stringify(expectedEmails)) {
|
||||
throw new Error(`user.listOperators mismatch: got ${JSON.stringify(opEmails)}`);
|
||||
}
|
||||
console.log(`user.listOperators → ${opEmails.join(', ')} ✓`);
|
||||
|
||||
await prisma.$disconnect();
|
||||
console.log('\nRouter AC PASSED');
|
||||
}
|
||||
|
||||
main().catch(async (err) => {
|
||||
console.error('Router AC FAILED:', err);
|
||||
await prisma.$disconnect();
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user