Files
eSIM-Tools/tests/simyo/device-change-handler.test.js
Abner 59a7a97c29 feat: CORS 多源支持 + Simyo 代理修复 + API 响应处理重构
- CORS 支持逗号分隔多源列表和通配符,新增 isAllowedOrigin/resolveCorsOrigin
- Simyo 代理路径从 req.path 改为 req.originalUrl,修复查询参数丢失
- Simyo 客户端配置提取为常量,支持环境变量覆盖
- API 端点检测浏览器协议,HTTP 访问时使用相对路径
- handleApiResponse 重构:content-type 检查、HTTP 错误优先、兼容三种响应格式
- 新增 X-Session-Token 头透传
- Logger 简化,移除前端模块依赖
- 同步更新测试 mock 以匹配新接口契约
2026-05-24 20:36:05 +08:00

60 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Simyo 设备更换处理模块集成测试
*/
import { deviceChangeHandler } from '../../src/simyo/js/modules/device-change-handler.js';
import { stateManager } from '../../src/simyo/js/modules/state-manager.js';
describe('Simyo DeviceChangeHandler 集成覆盖', () => {
beforeEach(() => {
stateManager.clearSession();
stateManager.set('sessionToken', 'test-session-token');
global.fetch.mockReset();
});
it('应完成设备更换主流程applyNewEsim -> verifyCode', async () => {
const jsonHeaders = { get: (name) => name === 'content-type' ? 'application/json' : null };
global.fetch
.mockResolvedValueOnce({
headers: jsonHeaders,
ok: true,
json: async () => ({
success: true,
result: {
message: 'apply success',
remainingNumberOfTries: 3
}
})
})
.mockResolvedValueOnce({
headers: jsonHeaders,
ok: true,
json: async () => ({
success: true,
result: {
message: 'verify success',
remainingNumberOfTries: 2
}
})
});
const applyResult = await deviceChangeHandler.applyNewEsim();
const verifyResult = await deviceChangeHandler.verifyCode('123456');
expect(applyResult.success).toBe(true);
expect(verifyResult.success).toBe(true);
expect(stateManager.get('validationCode')).toBe('123456');
expect(global.fetch).toHaveBeenCalledTimes(2);
expect(global.fetch).toHaveBeenNthCalledWith(
1,
'/api/simyo/settings/simcard',
expect.objectContaining({ method: 'POST' })
);
expect(global.fetch).toHaveBeenNthCalledWith(
2,
'/api/simyo/esim/verify-code',
expect.objectContaining({ method: 'POST' })
);
});
});