78 lines
2.2 KiB
TypeScript
78 lines
2.2 KiB
TypeScript
import { describe, test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
|
|
import { redisKeys } from '../realtime/redis/keys';
|
|
import {
|
|
parseRoundFromHash,
|
|
serializeRoundToHash,
|
|
} from '../realtime/redis/roundCache';
|
|
import {
|
|
parsePoolsFromHash,
|
|
serializePoolsToHash,
|
|
} from '../realtime/redis/poolCache';
|
|
import {
|
|
parseRealtimeEvent,
|
|
serializeRealtimeEvent,
|
|
} from '../realtime/redis/pubsub';
|
|
|
|
describe('redisKeys', () => {
|
|
test('builds stable key names', () => {
|
|
assert.equal(redisKeys.config(), 'prediqo:cp:config');
|
|
assert.equal(redisKeys.round(1, 1710000000000), 'prediqo:cp:round:1m:1710000000000');
|
|
assert.equal(redisKeys.pools(3, 1710000000000), 'prediqo:cp:pools:3m:1710000000000');
|
|
assert.equal(redisKeys.pubsubRound(1), 'prediqo:pubsub:cp:round:1m');
|
|
assert.equal(redisKeys.pubsubUser('user-1'), 'prediqo:pubsub:cp:user:user-1');
|
|
});
|
|
});
|
|
|
|
describe('roundCache serialization', () => {
|
|
test('round-trip round hash', () => {
|
|
const dto = {
|
|
id: 'round-1',
|
|
candleOpenMs: 1710000000000,
|
|
candleCloseMs: 1710000060000,
|
|
intervalMinutes: 1,
|
|
status: 'betting',
|
|
outcome: null,
|
|
openPrice: 100.5,
|
|
highPrice: null,
|
|
lowPrice: null,
|
|
closePrice: null,
|
|
settledAt: null,
|
|
shortPoolPercent: 42,
|
|
longPoolPercent: 58,
|
|
serverNowMs: 1710000001500,
|
|
secondsToBettingEnd: 25,
|
|
secondsToBettingStart: 0,
|
|
secondsToClose: 55,
|
|
version: 3,
|
|
};
|
|
const hash = serializeRoundToHash(dto);
|
|
const parsed = parseRoundFromHash(hash);
|
|
assert.deepEqual(parsed, dto);
|
|
});
|
|
});
|
|
|
|
describe('poolCache serialization', () => {
|
|
test('round-trip pool hash', () => {
|
|
const pools = { short: 120.5, long: 80.25 };
|
|
const hash = serializePoolsToHash(pools);
|
|
assert.deepEqual(parsePoolsFromHash(hash), pools);
|
|
});
|
|
});
|
|
|
|
describe('pubsub serialization', () => {
|
|
test('round-trip realtime event', () => {
|
|
const event = {
|
|
type: 'round.updated' as const,
|
|
intervalMinutes: 1,
|
|
payload: { status: 'betting' },
|
|
version: 2,
|
|
ts: 1710000000000,
|
|
};
|
|
const raw = serializeRealtimeEvent(event);
|
|
const parsed = parseRealtimeEvent(raw);
|
|
assert.deepEqual(parsed, event);
|
|
});
|
|
});
|