fix: connect operations pages to real backend
This commit is contained in:
@@ -3,7 +3,7 @@ import { OperationsService } from './operations.service';
|
||||
function createPrismaMock() {
|
||||
return {
|
||||
smsBatchTask: {
|
||||
findMany: jest.fn(),
|
||||
findMany: jest.fn().mockResolvedValue([{ id: 'task-1', taskNo: 'BATCH-1' }]),
|
||||
count: jest.fn().mockResolvedValue(3),
|
||||
},
|
||||
smsMessageRecord: {
|
||||
@@ -25,12 +25,38 @@ function createPrismaMock() {
|
||||
accountTransaction: {
|
||||
aggregate: jest.fn().mockResolvedValue({ _count: { _all: 2 }, _sum: { amountCents: -20, smsUnits: -2 } }),
|
||||
},
|
||||
tenantAccount: {
|
||||
findMany: jest.fn().mockResolvedValue([{ tenantId: 'tenant-1', balanceCents: 1000, tenant: { name: '租户A' } }]),
|
||||
},
|
||||
rechargeOrder: {
|
||||
findMany: jest.fn().mockResolvedValue([{ id: 'order-1', tenantId: 'tenant-1', amountCents: 1000 }]),
|
||||
},
|
||||
smsTemplate: {
|
||||
count: jest.fn().mockResolvedValue(1),
|
||||
},
|
||||
smsSignature: {
|
||||
count: jest.fn().mockResolvedValue(1),
|
||||
},
|
||||
enterpriseCertification: {
|
||||
count: jest.fn().mockResolvedValue(1),
|
||||
},
|
||||
cmppConnectionState: {
|
||||
groupBy: jest.fn().mockResolvedValue([{ status: 'online', _count: { _all: 1 }, _sum: { currentConnections: 2, desiredConnections: 2 } }]),
|
||||
},
|
||||
operationLog: {
|
||||
findMany: jest.fn(),
|
||||
groupBy: jest.fn(),
|
||||
findMany: jest.fn().mockResolvedValue([{
|
||||
id: 'log-1',
|
||||
tenantId: 'tenant-1',
|
||||
tenant: { name: '租户A' },
|
||||
user: { displayName: '运营' },
|
||||
action: 'billing.manual_recharge',
|
||||
resource: 'recharge_order',
|
||||
resourceId: 'order-1',
|
||||
detail: { amountCents: 1000 },
|
||||
createdAt: new Date('2026-07-02T01:00:00.000Z'),
|
||||
}]),
|
||||
count: jest.fn().mockResolvedValue(1),
|
||||
groupBy: jest.fn().mockResolvedValue([{ resource: 'recharge_order', _count: { _all: 1 } }]),
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -72,6 +98,7 @@ describe('OperationsService', () => {
|
||||
expect.objectContaining({
|
||||
taskCount: 3,
|
||||
uplinkCount: 1,
|
||||
pendingAuditCount: 6,
|
||||
gatewayConnections: [{ status: 'online', _count: { _all: 1 }, _sum: { currentConnections: 2, desiredConnections: 2 } }],
|
||||
}),
|
||||
);
|
||||
@@ -104,4 +131,26 @@ describe('OperationsService', () => {
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('returns paginated operation logs with normalized detail cards', async () => {
|
||||
const prisma = createPrismaMock();
|
||||
const service = new OperationsService(prisma as never);
|
||||
|
||||
await expect(service.systemLogs({ tenantId: 'tenant-1', keyword: '充值', page: 1, pageSize: 5 })).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
total: 1,
|
||||
page: 1,
|
||||
pageSize: 5,
|
||||
modules: ['recharge_order'],
|
||||
items: [
|
||||
expect.objectContaining({
|
||||
level: 'success',
|
||||
tenant: '租户A',
|
||||
module: 'recharge_order',
|
||||
action: 'billing.manual_recharge',
|
||||
}),
|
||||
],
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user