Skip to content

Commit 8826641

Browse files
committed
Update validate-agent-name.test.ts
1 parent 87b44f7 commit 8826641

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

backend/src/api/__tests__/validate-agent-name.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ import type {
1919
} from 'express'
2020

2121
function createMockReq(query: Record<string, any>): Partial<ExpressRequest> {
22-
return { query, headers: {} } as any
22+
return {
23+
query,
24+
headers: { 'x-codebuff-api-key': 'test-api-key' }
25+
} as any
2326
}
2427

2528
function createMockRes() {
@@ -127,4 +130,15 @@ describe('validateAgentNameHandler', () => {
127130
expect(res.jsonPayload.valid).toBe(false)
128131
expect(res.jsonPayload.message).toBe('Invalid request')
129132
})
133+
134+
it('returns 403 for requests without API key', async () => {
135+
const req = { query: { agentId: 'test' }, headers: {} } as any
136+
const res = createMockRes()
137+
138+
await validateAgentNameHandler(req as any, res as any, noopNext)
139+
140+
expect(res.status).toHaveBeenCalledWith(403)
141+
expect(res.jsonPayload.valid).toBe(false)
142+
expect(res.jsonPayload.message).toBe('API key required')
143+
})
130144
})

0 commit comments

Comments
 (0)