feat: 优化通道运营商与金额展示
This commit is contained in:
@@ -174,6 +174,51 @@ function createPrismaMock() {
|
||||
}
|
||||
|
||||
describe('ChannelsService', () => {
|
||||
it('sorts all filtered channels by today submit count before pagination', async () => {
|
||||
const prisma = createPrismaMock();
|
||||
const candidates = [
|
||||
{ id: 'channel-low', name: '乙通道' },
|
||||
{ id: 'channel-high', name: '甲通道' },
|
||||
{ id: 'channel-zero', name: '丙通道' },
|
||||
];
|
||||
const fullChannels = candidates.map((channel) => ({ ...channel, connectionStates: [] }));
|
||||
prisma.smsChannel.findMany
|
||||
.mockResolvedValueOnce(candidates)
|
||||
.mockResolvedValueOnce([fullChannels[0], fullChannels[1]]);
|
||||
prisma.$queryRaw.mockResolvedValue([
|
||||
{ channelId: 'channel-low', total: 3 },
|
||||
{ channelId: 'channel-high', total: 12 },
|
||||
]);
|
||||
const service = new ChannelsService(prisma as never);
|
||||
|
||||
const result = await service.listChannelsPage({ page: 1, pageSize: 2 });
|
||||
|
||||
expect(result.items.map((channel) => channel.id)).toEqual(['channel-high', 'channel-low']);
|
||||
expect(result.total).toBe(3);
|
||||
expect(prisma.smsChannel.findMany).toHaveBeenNthCalledWith(2, {
|
||||
where: { id: { in: ['channel-high', 'channel-low'] } },
|
||||
include: { connectionStates: true },
|
||||
});
|
||||
});
|
||||
|
||||
it('uses channel name and id as a stable tie breaker for zero-submit channels', async () => {
|
||||
const prisma = createPrismaMock();
|
||||
const candidates = [
|
||||
{ id: 'channel-b', name: 'A通道' },
|
||||
{ id: 'channel-a', name: 'A通道' },
|
||||
{ id: 'channel-c', name: 'B通道' },
|
||||
];
|
||||
prisma.smsChannel.findMany
|
||||
.mockResolvedValueOnce(candidates)
|
||||
.mockResolvedValueOnce(candidates);
|
||||
prisma.$queryRaw.mockResolvedValue([]);
|
||||
const service = new ChannelsService(prisma as never);
|
||||
|
||||
const result = await service.listChannelsPage({ page: 1, pageSize: 10 });
|
||||
|
||||
expect(result.items.map((channel) => channel.id)).toEqual(['channel-a', 'channel-b', 'channel-c']);
|
||||
});
|
||||
|
||||
it('creates channel report requirements only from the report field library', async () => {
|
||||
const prisma = createPrismaMock();
|
||||
const service = new ChannelsService(prisma as never);
|
||||
|
||||
Reference in New Issue
Block a user