Preserve empty traffic periods

This commit is contained in:
2026-07-27 11:36:33 +00:00
parent e5bff2d3bb
commit d1110dd076
3 changed files with 80 additions and 1 deletions
@@ -50,6 +50,7 @@ integration('general access tracking persistence', () => {
worldStateId,
year: 185,
month: 3,
tickSeconds: 600,
generalId,
userId: 'access-user-a',
now: new Date('2026-07-26T03:05:00.000Z'),
@@ -100,6 +101,7 @@ integration('general access tracking persistence', () => {
worldStateId,
year: 185,
month: 4,
tickSeconds: 600,
generalId,
userId: 'access-user-b',
now: new Date('2026-07-26T03:15:00.000Z'),
@@ -120,6 +122,7 @@ integration('general access tracking persistence', () => {
worldStateId,
year: 185,
month: 4,
tickSeconds: 600,
generalId: secondGeneralId,
userId: 'access-user-c',
now: new Date('2026-07-26T03:15:01.000Z'),
@@ -154,6 +157,35 @@ integration('general access tracking persistence', () => {
},
],
});
await upsertGeneralAccess(db, {
worldStateId,
year: 185,
month: 6,
tickSeconds: 600,
generalId,
userId: 'access-user-b',
now: new Date('2026-07-26T03:35:00.000Z'),
periodStartedAt: new Date('2026-07-26T03:30:00.000Z'),
scoreStartedAt: new Date('2026-07-26T03:30:00.000Z'),
weight: 1,
});
await expect(
db.trafficPeriod.findUniqueOrThrow({
where: {
worldStateId_year_month: {
worldStateId,
year: 185,
month: 5,
},
},
})
).resolves.toMatchObject({
startedAt: new Date('2026-07-26T03:20:00.000Z'),
lastRefresh: new Date('2026-07-26T03:30:00.000Z'),
refresh: 0,
online: 0,
});
});
it('rolls back the period and member rows when the legacy access update fails', async () => {
@@ -174,6 +206,7 @@ integration('general access tracking persistence', () => {
worldStateId,
year: 186,
month: 1,
tickSeconds: 600,
generalId: rollbackGeneralId,
userId: 'rollback-user',
now: new Date('2026-07-26T03:20:00.000Z'),
@@ -80,8 +80,15 @@ describe('general access tracking', () => {
const periodStatement = queryRaw.mock.calls[0]![0] as { sql: string; values: unknown[] };
expect(periodStatement.sql).toContain('INSERT INTO traffic_period');
expect(periodStatement.sql).toContain('generate_series');
expect(periodStatement.sql).toContain('ON CONFLICT (world_state_id, year, month) DO UPDATE');
expect(periodStatement.values).toEqual([3, 185, 4, new Date('2026-07-26T03:00:00.000Z'), now, 2]);
expect(periodStatement.values).toContain(3);
expect(periodStatement.values).toContain(185);
expect(periodStatement.values).toContain(4);
expect(periodStatement.values).toContain(600);
expect(periodStatement.values).toContain(2);
expect(periodStatement.values).toContain(now);
expect(periodStatement.values).toContainEqual(new Date('2026-07-26T03:00:00.000Z'));
const memberStatement = executeRaw.mock.calls[0]![0] as { sql: string; values: unknown[] };
expect(memberStatement.sql).toContain('INSERT INTO traffic_period_general');