Replace polling with websocket live sync
This commit is contained in:
30
server/lib/liveSync.test.ts
Normal file
30
server/lib/liveSync.test.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { fallbackDashboardSnapshot } from '../../src/data/mockDashboard';
|
||||
import { buildSnapshotPatch } from './liveSync';
|
||||
|
||||
describe('buildSnapshotPatch', () => {
|
||||
it('returns only changed top-level dashboard sections', () => {
|
||||
const nextSnapshot = {
|
||||
...fallbackDashboardSnapshot,
|
||||
traffic: {
|
||||
...fallbackDashboardSnapshot.traffic,
|
||||
totalBytes: fallbackDashboardSnapshot.traffic.totalBytes + 512,
|
||||
},
|
||||
};
|
||||
|
||||
expect(buildSnapshotPatch(fallbackDashboardSnapshot, nextSnapshot)).toEqual({
|
||||
traffic: nextSnapshot.traffic,
|
||||
});
|
||||
});
|
||||
|
||||
it('returns a full patch when no previous snapshot exists', () => {
|
||||
expect(buildSnapshotPatch(null, fallbackDashboardSnapshot)).toEqual({
|
||||
service: fallbackDashboardSnapshot.service,
|
||||
traffic: fallbackDashboardSnapshot.traffic,
|
||||
users: fallbackDashboardSnapshot.users,
|
||||
attention: fallbackDashboardSnapshot.attention,
|
||||
userRecords: fallbackDashboardSnapshot.userRecords,
|
||||
system: fallbackDashboardSnapshot.system,
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user