fix test issues
Build & Deploy / Build & Push Docker Image (push) Successful in 3m1s
Test / Type Check (all packages) (push) Successful in 55s
Build & Deploy / Deploy to VPS (push) Successful in 5s
Test / API Unit Tests (push) Successful in 47s
Test / Homepage Unit Tests (push) Successful in 42s
Test / Carplace Unit Tests (push) Successful in 42s
Test / Admin Unit Tests (push) Successful in 40s
Test / Dashboard Unit Tests (push) Successful in 41s
Test / API Integration Tests (push) Successful in 1m0s

This commit is contained in:
root
2026-07-02 18:50:03 -04:00
parent e3f40410e9
commit f330efb1ad
8 changed files with 102 additions and 21 deletions
+10 -1
View File
@@ -1,11 +1,13 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
import { CarplaceApiError, carplaceFetch, carplaceFetchOrDefault, carplacePost } from './api'
afterEach(() => {
delete process.env.NEXT_PUBLIC_API_URL
delete process.env.NEXT_PUBLIC_CARPLACE_DIRECT_API
delete process.env.API_INTERNAL_URL
vi.restoreAllMocks()
Reflect.deleteProperty(globalThis, 'window')
Reflect.deleteProperty(globalThis, 'fetch')
vi.resetModules()
})
describe('carplace API helpers', () => {
@@ -13,6 +15,7 @@ describe('carplace API helpers', () => {
const fetchMock = vi.fn(async () => ({ ok: true, json: async () => ({ data: [{ id: 'vehicle_1' }] }) }))
Object.defineProperty(globalThis, 'fetch', { configurable: true, value: fetchMock })
const { carplaceFetch } = await import('./api')
await expect(carplaceFetch('/carplace/vehicles')).resolves.toEqual([{ id: 'vehicle_1' }])
expect(fetchMock).toHaveBeenCalledWith(expect.stringMatching(/\/api\/v1\/carplace\/vehicles$/), {
cache: 'no-store',
@@ -30,6 +33,7 @@ describe('carplace API helpers', () => {
})),
})
const { carplaceFetch } = await import('./api')
await expect(carplaceFetch('/carplace/book')).rejects.toMatchObject({
name: 'CarplaceApiError',
message: 'Vehicle unavailable',
@@ -45,14 +49,18 @@ describe('carplace API helpers', () => {
value: vi.fn(async () => ({ ok: false, status: 500, json: async () => ({ message: 'Down' }) })),
})
const { carplaceFetchOrDefault } = await import('./api')
await expect(carplaceFetchOrDefault('/carplace/homepage', { hero: null })).resolves.toEqual({ hero: null })
})
it('posts JSON payloads and unwraps successful responses', async () => {
process.env.NEXT_PUBLIC_API_URL = 'https://api.example.com/api/v1'
process.env.NEXT_PUBLIC_CARPLACE_DIRECT_API = 'true'
Object.defineProperty(globalThis, 'window', { configurable: true, value: {} })
const fetchMock = vi.fn(async () => ({ ok: true, json: async () => ({ data: { id: 'reservation_1' } }) }))
Object.defineProperty(globalThis, 'fetch', { configurable: true, value: fetchMock })
const { carplacePost } = await import('./api')
await expect(carplacePost('/site/reservations', { vehicleId: 'vehicle_1' })).resolves.toEqual({ id: 'reservation_1' })
expect(fetchMock).toHaveBeenCalledWith('https://api.example.com/api/v1/site/reservations', expect.objectContaining({
method: 'POST',
@@ -68,6 +76,7 @@ describe('carplace API helpers', () => {
value: vi.fn(async () => ({ ok: false, status: 502, json: async () => { throw new Error('bad json') } })),
})
const { carplaceFetch } = await import('./api')
await expect(carplaceFetch('/site/homepage')).rejects.toMatchObject({
name: 'CarplaceApiError',
message: 'Request failed',