Skip to content

Commit 82d716d

Browse files
Fix next-auth mock configuration in API route tests (#56)
2 parents 5cb65f8 + 60eadf3 commit 82d716d

5 files changed

Lines changed: 146 additions & 90 deletions

File tree

src/app/api/orders/[id]/__tests__/route.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { OrderStatus, PaymentStatus, ShippingStatus } from '@prisma/client';
1313

1414
// Mock next-auth
1515
vi.mock('next-auth', () => ({
16+
default: vi.fn(),
1617
getServerSession: vi.fn(),
1718
}));
1819

@@ -333,7 +334,7 @@ describe('GET /api/orders/[id]', () => {
333334
const request = new NextRequest('http://localhost:3000/api/orders/order-1');
334335
await GET(request, { params: Promise.resolve({ id: 'order-1' }) });
335336

336-
expect(orderService.getOrderById).toHaveBeenCalledWith('order-1', null);
337+
expect(orderService.getOrderById).toHaveBeenCalledWith('order-1', undefined);
337338
});
338339

339340
it('should return 404 when order belongs to different store', async () => {

src/app/api/orders/[id]/invoice/__tests__/route.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { PaymentStatus } from '@prisma/client';
1313

1414
// Mock next-auth
1515
vi.mock('next-auth', () => ({
16+
default: vi.fn(),
1617
getServerSession: vi.fn(),
1718
}));
1819

src/app/api/orders/[id]/status/__tests__/route.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { OrderStatus } from '@prisma/client';
1313

1414
// Mock next-auth
1515
vi.mock('next-auth', () => ({
16+
default: vi.fn(),
1617
getServerSession: vi.fn(),
1718
} as any));
1819

@@ -512,7 +513,7 @@ describe('PUT /api/orders/[id]/status', () => {
512513
expect.objectContaining({
513514
orderId: 'order-1',
514515
newStatus: OrderStatus.PROCESSING,
515-
storeId: null,
516+
storeId: undefined,
516517
} as any)
517518
);
518519
});

src/app/api/orders/__tests__/route.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { OrderStatus } from '@prisma/client';
1313

1414
// Mock next-auth
1515
vi.mock('next-auth', () => ({
16+
default: vi.fn(),
1617
getServerSession: vi.fn(),
1718
}));
1819

@@ -577,7 +578,7 @@ describe('GET /api/orders', () => {
577578

578579
expect(orderService.listOrders).toHaveBeenCalledWith(
579580
expect.objectContaining({
580-
storeId: null,
581+
storeId: undefined,
581582
})
582583
);
583584
});

0 commit comments

Comments
 (0)