|
|
@@ -9,7 +9,20 @@ vi.mock('@/server/modules/agora/agora-token.service', () => ({
|
|
|
AgoraTokenService: vi.fn().mockImplementation(() => ({
|
|
|
generateRtcToken: vi.fn().mockReturnValue('mock-rtc-token'),
|
|
|
generateRtmToken: vi.fn().mockReturnValue('mock-rtm-token'),
|
|
|
- validateTokenParams: vi.fn(),
|
|
|
+ validateTokenParams: vi.fn().mockImplementation((type: 'rtc' | 'rtm', channel?: string, userId?: string) => {
|
|
|
+ if (type === 'rtc' && !channel) {
|
|
|
+ throw new Error('RTC Token需要提供channel参数')
|
|
|
+ }
|
|
|
+ if (type === 'rtm' && !userId) {
|
|
|
+ throw new Error('RTM Token需要提供userId参数')
|
|
|
+ }
|
|
|
+ if (channel && channel.length > 64) {
|
|
|
+ throw new Error('频道名称长度不能超过64个字符')
|
|
|
+ }
|
|
|
+ if (userId && userId.length > 64) {
|
|
|
+ throw new Error('用户ID长度不能超过64个字符')
|
|
|
+ }
|
|
|
+ }),
|
|
|
getTokenInfo: vi.fn().mockImplementation((token, type) => ({
|
|
|
token,
|
|
|
type,
|
|
|
@@ -190,7 +203,7 @@ describe('Agora Token API 集成测试', () => {
|
|
|
test('路由参数验证 - 无效Token类型', async () => {
|
|
|
// 使用无效的type参数
|
|
|
const response = await client.agora.token.$get({
|
|
|
- query: { type: 'rtc' as any, channel: 'test-channel' }
|
|
|
+ query: { type: 'invalid-type' as any, channel: 'test-channel' }
|
|
|
},
|
|
|
{
|
|
|
headers: {
|
|
|
@@ -203,7 +216,7 @@ describe('Agora Token API 集成测试', () => {
|
|
|
})
|
|
|
|
|
|
test('路由参数验证 - 缺少必需参数', async () => {
|
|
|
- // 测试缺少channel参数
|
|
|
+ // 测试缺少channel参数 - 业务逻辑验证应该返回400错误
|
|
|
const response1 = await client.agora.token.$get({
|
|
|
query: { type: 'rtc' } // 缺少channel参数
|
|
|
},
|
|
|
@@ -213,7 +226,7 @@ describe('Agora Token API 集成测试', () => {
|
|
|
}
|
|
|
})
|
|
|
|
|
|
- // 由于Zod验证,应该返回400错误
|
|
|
+ // 由于业务逻辑验证,应该返回400错误
|
|
|
expect(response1.status).toBe(400)
|
|
|
|
|
|
// 测试缺少userId参数
|
|
|
@@ -226,7 +239,7 @@ describe('Agora Token API 集成测试', () => {
|
|
|
}
|
|
|
})
|
|
|
|
|
|
- // 由于Zod验证,应该返回400错误
|
|
|
+ // 由于业务逻辑验证,应该返回400错误
|
|
|
expect(response2.status).toBe(400)
|
|
|
})
|
|
|
|