fix: complete first version issue remediation

This commit is contained in:
hectorzhao
2026-07-11 10:14:37 +08:00
parent 709ac97764
commit 208a6c23f8
73 changed files with 1549 additions and 245 deletions
+25 -3
View File
@@ -183,6 +183,8 @@ describe('ChannelsService', () => {
srcId: '10690000',
desiredConnections: 2,
windowSize: 32,
rateLimitPerSecond: 750,
config: { extensionDigits: 4 },
});
await service.createGroup({ code: 'G-MOBILE', name: '移动组', carrier: 'mobile', retryEnabled: true, retryTimeLimitMinutes: 750 });
await service.createRouteRule({ tenantId: 'tenant-1', applicationId: 'app-1', groupId: 'group-1', carrier: 'mobile' });
@@ -191,10 +193,10 @@ describe('ChannelsService', () => {
data: expect.objectContaining({
protocol: 'CMPP',
cmppVersion: '2.0',
rateLimitPerSecond: 100,
rateLimitPerSecond: 750,
sendRegion: '全国',
status: 'active',
config: expect.objectContaining({ desiredConnections: 2, windowSize: 32 }),
config: expect.objectContaining({ desiredConnections: 2, windowSize: 32, extensionDigits: 4 }),
}),
});
expect(prisma.cmppConnectionState.create).toHaveBeenCalledWith({
@@ -263,6 +265,23 @@ describe('ChannelsService', () => {
})).rejects.toThrow('cmppVersion must be 2.0 or 3.0');
});
it('rejects invalid channel rate limits and extension digit counts', async () => {
const prisma = createPrismaMock();
const service = new ChannelsService(prisma as never);
const channel = {
code: 'CMPP-CONFIG',
name: '配置校验通道',
gatewayHost: '127.0.0.1',
gatewayPort: 17890,
account: 'sp',
passwordCipher: 'secret',
srcId: '10690000',
};
await expect(service.createChannel({ ...channel, rateLimitPerSecond: 2001 })).rejects.toThrow('rateLimitPerSecond must be between 1 and 2000');
await expect(service.createChannel({ ...channel, config: { extensionDigits: 3 } })).rejects.toThrow('extensionDigits must be one of 0, 2, 4, or 6');
});
it('updates CMPP channel configuration without requiring password changes', async () => {
const prisma = createPrismaMock();
const service = new ChannelsService(prisma as never);
@@ -277,6 +296,8 @@ describe('ChannelsService', () => {
srcId: '10690001',
desiredConnections: 3,
windowSize: 64,
rateLimitPerSecond: 320,
config: { extensionDigits: 2 },
unitPrice: 4,
})).resolves.toEqual(expect.objectContaining({
id: 'channel-1',
@@ -292,7 +313,8 @@ describe('ChannelsService', () => {
gatewayPort: 27890,
carrier: 'all',
passwordCipher: undefined,
config: expect.objectContaining({ desiredConnections: 3, windowSize: 64 }),
rateLimitPerSecond: 320,
config: expect.objectContaining({ desiredConnections: 3, windowSize: 64, extensionDigits: 2 }),
}),
});
expect(prisma.operationLog.create).toHaveBeenCalledWith({