- All 8 home page sections: Hero, Locations slider, WhyParents accordion, Birthday pricing cards, Video, Gallery, Reviews slider, News - UI components: NavLink, BtnPrimary, BtnGradient, BtnDetails, AccordionItem - Layout: sticky Header (NavLink + BtnPrimary), Footer with logo - Figma Code Connect: 5 components published (.figma.tsx + figma.config.json) - Public assets: all Figma images and SVGs exported - Pages: /kvytky, /lokatsii, /blog, /dni-narodzhennia, /grupovi-vidviduvannia - Tests: Vitest unit/api suites, Playwright e2e screenshots - Payload CMS: blocks, collections, seed data updates - Hero negative-margin to extend behind sticky header - Custom Tailwind breakpoints: lg=1440px, xl=1920px - Fix ESLint config: drop FlatCompat, use eslint-config-next flat export - Add tsconfig.tsbuildinfo, test-results/, agentdb.rvf* to .gitignore Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
61 lines
1.9 KiB
TypeScript
61 lines
1.9 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
import { NextRequest } from 'next/server'
|
|
|
|
const mockSyncTariffs = vi.fn()
|
|
vi.mock('@/lib/syncTariffs', () => ({ syncTariffs: mockSyncTariffs }))
|
|
|
|
const SYNC_SECRET = 'test-sync-secret'
|
|
|
|
function makeRequest(token?: string): NextRequest {
|
|
return new NextRequest('http://localhost/api/tariffs/sync', {
|
|
method: 'POST',
|
|
headers: token !== undefined ? { authorization: `Bearer ${token}` } : {},
|
|
})
|
|
}
|
|
|
|
let POST: (req: NextRequest) => Promise<Response>
|
|
|
|
beforeEach(async () => {
|
|
vi.resetModules()
|
|
mockSyncTariffs.mockReset()
|
|
vi.stubEnv('SYNC_SECRET', SYNC_SECRET)
|
|
const mod = await import('@/app/api/tariffs/sync/route')
|
|
POST = mod.POST
|
|
})
|
|
|
|
describe('POST /api/tariffs/sync', () => {
|
|
it('returns 401 when authorization header is missing', async () => {
|
|
const res = await POST(makeRequest())
|
|
expect(res.status).toBe(401)
|
|
})
|
|
|
|
it('returns 401 for a wrong token', async () => {
|
|
const res = await POST(makeRequest('bad-token'))
|
|
expect(res.status).toBe(401)
|
|
})
|
|
|
|
it('returns 401 when SYNC_SECRET is empty (no bypass allowed)', async () => {
|
|
vi.stubEnv('SYNC_SECRET', '')
|
|
vi.resetModules()
|
|
const mod = await import('@/app/api/tariffs/sync/route')
|
|
const res = await mod.POST(makeRequest(''))
|
|
expect(res.status).toBe(401)
|
|
})
|
|
|
|
it('returns ok:true with sync counts on success', async () => {
|
|
mockSyncTariffs.mockResolvedValueOnce({ synced: 5, created: 0, hidden: 2 })
|
|
const res = await POST(makeRequest(SYNC_SECRET))
|
|
expect(res.status).toBe(200)
|
|
const json = await res.json()
|
|
expect(json.ok).toBe(true)
|
|
expect(json.synced).toBe(5)
|
|
expect(json.hidden).toBe(2)
|
|
})
|
|
|
|
it('returns 500 when syncTariffs throws', async () => {
|
|
mockSyncTariffs.mockRejectedValueOnce(new Error('sync error'))
|
|
const res = await POST(makeRequest(SYNC_SECRET))
|
|
expect(res.status).toBe(500)
|
|
expect((await res.json()).error).toBe('Sync failed')
|
|
})
|
|
})
|