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
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:
@@ -15,6 +15,7 @@ afterEach(() => {
|
|||||||
vi.restoreAllMocks()
|
vi.restoreAllMocks()
|
||||||
Reflect.deleteProperty(globalThis, 'window')
|
Reflect.deleteProperty(globalThis, 'window')
|
||||||
Reflect.deleteProperty(globalThis, 'fetch')
|
Reflect.deleteProperty(globalThis, 'fetch')
|
||||||
|
delete process.env.NEXT_PUBLIC_API_URL
|
||||||
vi.resetModules()
|
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 () => {
|
it('does not force JSON content type for FormData payloads', async () => {
|
||||||
installBrowser()
|
installBrowser()
|
||||||
const fetchMock = vi.fn(async () => ({ ok: true, json: async () => ({ data: { uploaded: true } }) }))
|
const fetchMock = vi.fn(async () => ({ ok: true, json: async () => ({ data: { uploaded: true } }) }))
|
||||||
|
|||||||
@@ -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'
|
typeof window === 'undefined'
|
||||||
? (process.env.API_INTERNAL_URL || 'http://localhost:4000/api/v1')
|
? (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'
|
export const EMPLOYEE_PROFILE_KEY = 'employee_profile'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user