fix: simplify balance billing and govern operation logs

This commit is contained in:
hectorzhao
2026-07-14 17:40:32 +08:00
parent f35691f185
commit 28dad93e3e
40 changed files with 740 additions and 395 deletions
@@ -0,0 +1,28 @@
import { OperationLogRetentionService } from './operation-log-retention.service';
describe('OperationLogRetentionService', () => {
const originalEnv = { ...process.env };
afterEach(() => {
process.env = { ...originalEnv };
});
it('archives expired logs in bounded batches using the configured retention window', async () => {
process.env.OPERATION_LOG_RETENTION_DAYS = '90';
process.env.OPERATION_LOG_ARCHIVE_BATCH_SIZE = '2';
process.env.OPERATION_LOG_ARCHIVE_MAX_BATCHES = '3';
const prisma = {
$executeRaw: jest.fn()
.mockResolvedValueOnce(2)
.mockResolvedValueOnce(1),
};
const service = new OperationLogRetentionService(prisma as never);
await expect(service.archiveExpiredLogs(new Date('2026-07-14T00:00:00.000Z'))).resolves.toEqual({
archived: 3,
cutoff: new Date('2026-04-15T00:00:00.000Z'),
retentionDays: 90,
});
expect(prisma.$executeRaw).toHaveBeenCalledTimes(2);
});
});