fix api config auth and image model compatibility
Some checks failed
Build & Push Docker Image / build-and-push (push) Has been cancelled
Some checks failed
Build & Push Docker Image / build-and-push (push) Has been cancelled
This commit is contained in:
@@ -9,6 +9,9 @@ const authMock = vi.hoisted(() => ({
|
||||
}))
|
||||
|
||||
const prismaMock = vi.hoisted(() => ({
|
||||
user: {
|
||||
findUnique: vi.fn<(...args: unknown[]) => Promise<{ id: string } | null>>(),
|
||||
},
|
||||
userPreference: {
|
||||
upsert: vi.fn(async () => ({
|
||||
userId: 'user-1',
|
||||
@@ -25,6 +28,7 @@ describe('api specific - user preference art style validation', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
prismaMock.user.findUnique.mockResolvedValue({ id: 'user-1' })
|
||||
})
|
||||
|
||||
it('accepts valid artStyle and persists normalized value', async () => {
|
||||
@@ -58,4 +62,27 @@ describe('api specific - user preference art style validation', () => {
|
||||
expect(body.error.code).toBe('INVALID_PARAMS')
|
||||
expect(prismaMock.userPreference.upsert).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('returns unauthorized when session user record is missing', async () => {
|
||||
prismaMock.user.findUnique.mockResolvedValueOnce(null)
|
||||
const mod = await import('@/app/api/user-preference/route')
|
||||
const req = buildMockRequest({
|
||||
path: '/api/user-preference',
|
||||
method: 'PATCH',
|
||||
body: { artStyle: 'realistic' },
|
||||
})
|
||||
|
||||
const res = await mod.PATCH(req, routeContext)
|
||||
const body = await res.json() as {
|
||||
error?: {
|
||||
code?: string
|
||||
message?: string
|
||||
}
|
||||
}
|
||||
|
||||
expect(res.status).toBe(401)
|
||||
expect(body.error?.code).toBe('UNAUTHORIZED')
|
||||
expect(body.error?.message).toBe('登录状态已失效,请重新登录')
|
||||
expect(prismaMock.userPreference.upsert).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user