mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2026-11-20 02:03:35 +08:00
Add user CRUD, account-scoped navigation history and favorites. Unify HTTP mocks, backend contracts and route configuration. Reuse existing scrolling components and add Harness reuse guidance.
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { APP_CATCH_KEY } from '@/app-config'
|
|
import { injectRequestHeaders } from '@/axios/axios-interceptor/request/plugins/request-headers'
|
|
import type { RequestInterceptorConfig } from '@/axios/types'
|
|
import { setStorage } from '@/utils/cache'
|
|
import { AxiosHeaders } from 'axios'
|
|
|
|
afterEach(() => {
|
|
localStorage.clear()
|
|
vi.unstubAllEnvs()
|
|
})
|
|
|
|
it('sends Bearer credentials only to the configured API origin and path', () => {
|
|
vi.stubEnv('VITE_API_BASE_URL', 'https://api.example.test/v1/')
|
|
setStorage(APP_CATCH_KEY.token, 'test-token', 'localStorage')
|
|
const config = (url: string): RequestInterceptorConfig => ({
|
|
url,
|
|
headers: new AxiosHeaders(),
|
|
})
|
|
const owned = config('https://api.example.test/v1/admin/users')
|
|
|
|
injectRequestHeaders(owned, '')
|
|
expect(owned.headers?.Authorization).toBe('Bearer test-token')
|
|
|
|
for (const url of [
|
|
'https://other.example.test/v1/admin/users',
|
|
'https://api.example.test/v10/admin/users',
|
|
]) {
|
|
const foreign = config(url)
|
|
|
|
injectRequestHeaders(foreign, '')
|
|
expect(foreign.headers?.Authorization).toBeUndefined()
|
|
}
|
|
|
|
const explicit = config('https://api.example.test/v1/admin/users')
|
|
|
|
explicit.headers = { authorization: 'Bearer supplied-token' }
|
|
injectRequestHeaders(explicit, '')
|
|
expect(explicit.headers.authorization).toBe('Bearer supplied-token')
|
|
})
|