Shumiland/tests/api/cron-tariffs.test.ts
Vadym Samoilenko cca4ea1d55
Some checks are pending
CI / Type Check (push) Waiting to run
CI / Lint (push) Waiting to run
CI / Unit Tests (push) Waiting to run
Deploy / Build & Push Image (push) Waiting to run
Deploy / Deploy to VPS (push) Blocked by required conditions
feat: implement full frontend — all sections, components, Figma Code Connect
- 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>
2026-05-10 16:40:56 +01:00

62 lines
2 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 CRON_SECRET = 'test-cron-secret' // matches vitest.setup.ts
function makeRequest(token?: string): NextRequest {
return new NextRequest('http://localhost/api/cron/tariffs', {
method: 'GET',
headers: token !== undefined ? { authorization: `Bearer ${token}` } : {},
})
}
let GET: (req: NextRequest) => Promise<Response>
beforeEach(async () => {
vi.resetModules()
mockSyncTariffs.mockReset()
vi.stubEnv('CRON_SECRET', CRON_SECRET)
const mod = await import('@/app/api/cron/tariffs/route')
GET = mod.GET
})
describe('GET /api/cron/tariffs', () => {
it('returns 401 when authorization header is missing', async () => {
const res = await GET(makeRequest())
expect(res.status).toBe(401)
})
it('returns 401 for a wrong token', async () => {
const res = await GET(makeRequest('wrong-token'))
expect(res.status).toBe(401)
})
it('returns 401 when CRON_SECRET is empty (no bypass allowed)', async () => {
vi.stubEnv('CRON_SECRET', '')
vi.resetModules()
const mod = await import('@/app/api/cron/tariffs/route')
const res = await mod.GET(makeRequest(''))
expect(res.status).toBe(401)
})
it('returns ok:true with sync counts on success', async () => {
mockSyncTariffs.mockResolvedValueOnce({ synced: 3, created: 1, hidden: 0 })
const res = await GET(makeRequest(CRON_SECRET))
expect(res.status).toBe(200)
const json = await res.json()
expect(json.ok).toBe(true)
expect(json.synced).toBe(3)
expect(json.created).toBe(1)
expect(json.hidden).toBe(0)
})
it('returns 500 when syncTariffs throws', async () => {
mockSyncTariffs.mockRejectedValueOnce(new Error('sync error'))
const res = await GET(makeRequest(CRON_SECRET))
expect(res.status).toBe(500)
expect((await res.json()).error).toBe('Sync failed')
})
})