SkateSpots/src/lib/cordn/unread.test.ts

28 lines
909 B
TypeScript

import { afterEach, describe, expect, it } from 'vitest';
import { clearCordnSeen, readCordnSeen, writeCordnSeen } from './unread';
const PK = 'a'.repeat(64);
const GID = 'skatespots:community';
describe('cordn unread cursor', () => {
afterEach(() => localStorage.clear());
it('distinguishes never-seen from seen-at-zero', () => {
expect(readCordnSeen(PK, GID)).toBeNull();
writeCordnSeen(PK, GID, 0);
expect(readCordnSeen(PK, GID)).toBe(0);
});
it('round-trips the newest timestamp per account + room', () => {
writeCordnSeen(PK, GID, 1_700_000_000);
expect(readCordnSeen(PK, GID)).toBe(1_700_000_000);
expect(readCordnSeen('b'.repeat(64), GID)).toBeNull();
expect(readCordnSeen(PK, 'other:room')).toBeNull();
});
it('clears a cursor', () => {
writeCordnSeen(PK, GID, 42);
clearCordnSeen(PK, GID);
expect(readCordnSeen(PK, GID)).toBeNull();
});
});