first commit
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { expect, test } from 'vitest'
|
||||
|
||||
const baseUrl = import.meta.env.E2E_API_BASE_URL?.replace(/\/$/, '')
|
||||
const username = import.meta.env.E2E_USERNAME
|
||||
const password = import.meta.env.E2E_PASSWORD
|
||||
|
||||
test('real backend is healthy and accepts an authenticated request', async () => {
|
||||
expect(baseUrl, '请设置 E2E_API_BASE_URL').toBeTruthy()
|
||||
expect(username, '请设置 E2E_USERNAME').toBeTruthy()
|
||||
expect(password, '请设置 E2E_PASSWORD').toBeTruthy()
|
||||
|
||||
const health = await fetch(`${baseUrl}/health`)
|
||||
expect(health.status).toBe(200)
|
||||
expect(await health.json()).toMatchObject({ status: 'ok' })
|
||||
|
||||
const unauthorized = await fetch(`${baseUrl}/reports?limit=1`)
|
||||
expect(unauthorized.status).toBe(401)
|
||||
|
||||
const login = await fetch(`${baseUrl}/auth/login`, {
|
||||
method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username, password }),
|
||||
})
|
||||
expect(login.status).toBe(200)
|
||||
const token = (await login.json()).access_token
|
||||
expect(token).toBeTruthy()
|
||||
|
||||
const reports = await fetch(`${baseUrl}/reports?limit=1`, { headers: { Authorization: `Bearer ${token}` } })
|
||||
expect(reports.status).toBe(200)
|
||||
expect(await reports.json()).toBeInstanceOf(Array)
|
||||
})
|
||||
Reference in New Issue
Block a user