Files
support_backend/tests/integration/known-issues.test.ts
T
saqib mirandClaude Sonnet 5 40687f68fa feat(010-identity-auth): real staff login, session verification, and role gating
Replaces the no-op fastify.authenticate stub and the never-implemented
identity/auth login with real bcrypt password verification, JWT session
issuance/verification (reusing the existing JWT_SECRET), and a Redis-backed
revocation denylist for logout. Adds requireRole('ADMIN') to admin-only
configuration writes across 002-009 that previously relied on a decorator
that never actually checked anything. Adds self-identity (GET /auth/me,
re-validated against live account state) and admin-provisioned accounts
(POST /admin/users).

Making the auth check genuinely reject invalid/missing tokens exposed that
~18 pre-existing integration test files called already-gated routes with no
Authorization header (safe against the old no-op stub, broken against a real
one) — fixed via a shared tests/helpers/auth.ts (loginAs/authHeader) and a
file-by-file pass, plus two related SLA-run cleanup races exposed once admin
setup calls in those files' own beforeAll blocks started actually succeeding.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-07 12:45:37 +05:30

67 lines
2.6 KiB
TypeScript

import { describe, it, expect, beforeAll, afterAll } from 'vitest';
import { buildApp } from '@/app';
import { prismaClient } from '@/infrastructure/database';
import { FastifyInstance } from 'fastify';
import { loginAs, authHeader } from '../helpers/auth';
/** Covers specs/004-product-knowledge/quickstart.md Scenario 4 against a real Postgres. */
describe('Error codes and known issues', () => {
let app: FastifyInstance;
let token: string;
const externalProductId = `TEST_KNOWNISSUE_PROD_${Date.now()}`;
const errorCode = 'LAYOUT_PARSE_042';
beforeAll(async () => {
app = await buildApp();
token = await loginAs(app, 'ADMIN');
await prismaClient.product.create({
data: { externalProductId, name: 'Known Issue Test Product', status: 'active' },
});
});
afterAll(async () => {
await prismaClient.knownIssue.deleteMany({ where: { product: { externalProductId } } });
await prismaClient.errorCode.deleteMany({ where: { product: { externalProductId } } });
await prismaClient.product.deleteMany({ where: { externalProductId } });
await app.close();
});
it('Scenario 4: a known issue resolves by its error code in a single lookup', async () => {
const errorCodeResponse = await app.inject({
method: 'POST',
url: `/admin/products/${externalProductId}/error-codes`,
headers: authHeader(token),
payload: { code: errorCode, description: 'Layout parser failure' },
});
expect(errorCodeResponse.statusCode).toBe(201);
const { id: errorCodeId } = errorCodeResponse.json().data;
const knownIssueResponse = await app.inject({
method: 'POST',
url: `/admin/products/${externalProductId}/known-issues`,
headers: authHeader(token),
payload: { errorCodeId, description: 'Conversion fails for complex layouts' },
});
expect(knownIssueResponse.statusCode).toBe(201);
const lookupResponse = await app.inject({
method: 'GET',
url: `/admin/products/${externalProductId}/known-issues/by-error-code/${errorCode}`,
headers: authHeader(token),
});
expect(lookupResponse.statusCode).toBe(200);
const knownIssues = lookupResponse.json().data;
expect(knownIssues).toHaveLength(1);
expect(knownIssues[0].description).toBe('Conversion fails for complex layouts');
});
it('a lookup for a nonexistent error code returns 404', async () => {
const response = await app.inject({
method: 'GET',
url: `/admin/products/${externalProductId}/known-issues/by-error-code/NEVER_REGISTERED`,
headers: authHeader(token),
});
expect(response.statusCode).toBe(404);
});
});