I also hardened the dashboard API helper so a bare origin
Build & Deploy / Build & Push Docker Image (push) Successful in 2m47s
Test / Type Check (all packages) (push) Successful in 54s
Build & Deploy / Deploy to VPS (push) Successful in 3s
Test / API Unit Tests (push) Successful in 47s
Test / Homepage Unit Tests (push) Successful in 44s
Test / Storefront Unit Tests (push) Successful in 42s
Test / Admin Unit Tests (push) Successful in 41s
Test / Dashboard Unit Tests (push) Successful in 42s
Test / API Integration Tests (push) Successful in 1m0s

This commit is contained in:
root
2026-07-02 01:43:27 -04:00
parent 56984c4ea7
commit 8ef61d7005
2 changed files with 24 additions and 2 deletions
+16
View File
@@ -15,6 +15,7 @@ afterEach(() => {
vi.restoreAllMocks()
Reflect.deleteProperty(globalThis, 'window')
Reflect.deleteProperty(globalThis, 'fetch')
delete process.env.NEXT_PUBLIC_API_URL
vi.resetModules()
})
@@ -38,6 +39,21 @@ describe('dashboard apiFetch', () => {
}))
})
it('normalizes a public API origin to the versioned API base', async () => {
installBrowser()
process.env.NEXT_PUBLIC_API_URL = 'https://api.rentaldrivego.ma'
const fetchMock = vi.fn(async () => ({
ok: true,
json: async () => ({ data: { ok: true } }),
}))
Object.defineProperty(globalThis, 'fetch', { configurable: true, value: fetchMock })
const { apiFetch } = await import('./api')
await apiFetch('/auth/account/start', { method: 'POST', body: JSON.stringify({}) })
expect(fetchMock).toHaveBeenCalledWith('https://api.rentaldrivego.ma/api/v1/auth/account/start', expect.any(Object))
})
it('does not force JSON content type for FormData payloads', async () => {
installBrowser()
const fetchMock = vi.fn(async () => ({ ok: true, json: async () => ({ data: { uploaded: true } }) }))
+8 -2
View File
@@ -1,7 +1,13 @@
export const API_BASE =
function normalizeApiBase(value: string): string {
const base = value.replace(/\/+$/, '')
return /\/api\/v1$/.test(base) ? base : `${base}/api/v1`
}
export const API_BASE = normalizeApiBase(
typeof window === 'undefined'
? (process.env.API_INTERNAL_URL || 'http://localhost:4000/api/v1')
: (process.env.NEXT_PUBLIC_API_URL || '/dashboard/api/v1')
: (process.env.NEXT_PUBLIC_API_URL || '/dashboard/api/v1'),
)
export const EMPLOYEE_PROFILE_KEY = 'employee_profile'