feat(plan5): API GET /api/creation/preview (TDD)
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import { GET } from './route'
|
||||
import * as creationSheets from '@/lib/creationSheets'
|
||||
import { getServerSession } from 'next-auth'
|
||||
|
||||
jest.mock('next-auth')
|
||||
jest.mock('@/lib/creationSheets')
|
||||
jest.mock('@/lib/prisma', () => ({
|
||||
prisma: { productCreation: { findMany: jest.fn().mockResolvedValue([]) } },
|
||||
}))
|
||||
|
||||
const mockSession = getServerSession as jest.MockedFunction<typeof getServerSession>
|
||||
const mockFetch = creationSheets.fetchPendingProducts as jest.MockedFunction<typeof creationSheets.fetchPendingProducts>
|
||||
|
||||
const makePending = (tab: string, row: number, specific: Record<string, string> = {}) => ({
|
||||
tab, rowNumber: row, sku: `SKU-${row}`, title: `Produit ${row}`,
|
||||
priceMarket: '99', priceActual: '79', stock: 5, weightKg: 2,
|
||||
vendor: 'BOSCH', famille: tab, sousFamille: '', comment: '',
|
||||
collectionId: '10', subCollectionId: '', hasPhoto: false,
|
||||
specificFields: specific,
|
||||
})
|
||||
|
||||
describe('GET /api/creation/preview', () => {
|
||||
beforeEach(() => {
|
||||
mockSession.mockResolvedValue({ user: { id: 'u1', role: 'admin' } } as never)
|
||||
mockFetch.mockResolvedValue([
|
||||
makePending('OUTILLAGE', 2, { 'Puissance (AN)': '1500W' }),
|
||||
makePending('CARRELAGE', 3),
|
||||
])
|
||||
})
|
||||
|
||||
it('retourne 401 sans session', async () => {
|
||||
mockSession.mockResolvedValue(null)
|
||||
const res = await GET(new Request('http://localhost') as never)
|
||||
expect(res.status).toBe(401)
|
||||
})
|
||||
|
||||
it('retourne les produits groupés par onglet', async () => {
|
||||
const res = await GET(new Request('http://localhost') as never)
|
||||
const body = await res.json()
|
||||
expect(body.byTab['OUTILLAGE']).toHaveLength(1)
|
||||
expect(body.byTab['CARRELAGE']).toHaveLength(1)
|
||||
expect(body.total).toBe(2)
|
||||
})
|
||||
|
||||
it('liste les colonnes spécifiques uniques', async () => {
|
||||
const res = await GET(new Request('http://localhost') as never)
|
||||
const body = await res.json()
|
||||
expect(body.specificColumns).toContain('Puissance (AN)')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user