47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import { GET } from '../route'
|
|
|
|
describe('GET /api/dingtalk/config', () => {
|
|
const originalEnv = process.env
|
|
|
|
beforeEach(() => {
|
|
jest.resetModules()
|
|
process.env = { ...originalEnv }
|
|
})
|
|
|
|
afterAll(() => {
|
|
process.env = originalEnv
|
|
})
|
|
|
|
it('缺少服务端 clientId/clientSecret 时不暴露默认钉钉配置', async () => {
|
|
delete process.env.DINGTALK_CLIENT_ID
|
|
delete process.env.DINGTALK_CLIENT_SECRET
|
|
|
|
const response = await GET()
|
|
const data = await response.json()
|
|
|
|
expect(response.status).toBe(200)
|
|
expect(data).toEqual({
|
|
enabled: false,
|
|
clientId: null,
|
|
callbackUrl: null,
|
|
})
|
|
})
|
|
|
|
it('配置完整时只返回前端需要的 clientId 和回调地址', async () => {
|
|
process.env.DINGTALK_CLIENT_ID = 'client-id'
|
|
process.env.DINGTALK_CLIENT_SECRET = 'client-secret'
|
|
process.env.DINGTALK_CALLBACK_URL = 'https://portal.example.com/dingtalk-callback'
|
|
|
|
const response = await GET()
|
|
const data = await response.json()
|
|
|
|
expect(response.status).toBe(200)
|
|
expect(data).toEqual({
|
|
enabled: true,
|
|
clientId: 'client-id',
|
|
callbackUrl: 'https://portal.example.com/dingtalk-callback',
|
|
})
|
|
expect(JSON.stringify(data)).not.toContain('client-secret')
|
|
})
|
|
})
|