fix(auth): use UUID id generation for BetterAuth DB models
Some checks failed
ci/woodpecker/push/api Pipeline failed
Some checks failed
ci/woodpecker/push/api Pipeline failed
This commit is contained in:
@@ -50,6 +50,8 @@ describe("TelemetryInterceptor", () => {
|
||||
getResponse: vi.fn().mockReturnValue({
|
||||
statusCode: 200,
|
||||
setHeader: vi.fn(),
|
||||
headersSent: false,
|
||||
writableEnded: false,
|
||||
}),
|
||||
}),
|
||||
getClass: vi.fn().mockReturnValue({ name: "TestController" }),
|
||||
@@ -101,6 +103,35 @@ describe("TelemetryInterceptor", () => {
|
||||
expect(mockResponse.setHeader).toHaveBeenCalledWith("x-trace-id", "test-trace-id");
|
||||
});
|
||||
|
||||
it("should not set trace header when response is already committed", async () => {
|
||||
const committedResponseContext = {
|
||||
...mockContext,
|
||||
switchToHttp: vi.fn().mockReturnValue({
|
||||
getRequest: vi.fn().mockReturnValue({
|
||||
method: "GET",
|
||||
url: "/api/test",
|
||||
path: "/api/test",
|
||||
}),
|
||||
getResponse: vi.fn().mockReturnValue({
|
||||
statusCode: 200,
|
||||
setHeader: vi.fn(),
|
||||
headersSent: true,
|
||||
writableEnded: true,
|
||||
}),
|
||||
}),
|
||||
} as unknown as ExecutionContext;
|
||||
|
||||
mockHandler = {
|
||||
handle: vi.fn().mockReturnValue(of({ data: "test" })),
|
||||
} as unknown as CallHandler;
|
||||
|
||||
const committedResponse = committedResponseContext.switchToHttp().getResponse();
|
||||
|
||||
await lastValueFrom(interceptor.intercept(committedResponseContext, mockHandler));
|
||||
|
||||
expect(committedResponse.setHeader).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should record exception on error", async () => {
|
||||
const error = new Error("Test error");
|
||||
mockHandler = {
|
||||
|
||||
@@ -88,7 +88,7 @@ export class TelemetryInterceptor implements NestInterceptor {
|
||||
|
||||
// Add trace context to response headers for distributed tracing
|
||||
const spanContext = span.spanContext();
|
||||
if (spanContext.traceId) {
|
||||
if (spanContext.traceId && !response.headersSent && !response.writableEnded) {
|
||||
response.setHeader("x-trace-id", spanContext.traceId);
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user