Files
musicshare/packages/shared/src/dto.test.ts
T
chrisandClaude Opus 5.5 4402171f46 Comments on plays
- Anyone who can see a play can read its comments; the player and the people they follow can write.
  The author, the player and admins can delete; comments can be reported (admins see the text).
- Notifications: "commented on" for the player, "replied on" for earlier commenters, each with its
  own setting. Reaction and comment notifications now open the play.
- A 💬 chip with the count next to reactions on the feed and recent plays, opening the thread on
  the app (/play/[id]) and the website. Threads refresh every few seconds while open.
- Blocking removes comments between the two people. Plays with comments survive history trimming.
- Privacy page updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011Y2iUsKEWDuRGjK5FPmcUP
2026-10-15 13:32:14 -04:00

48 lines
1.7 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { sortFeed, type FeedItemDTO } from './dto';
function item(username: string, opts: { pinnedAt?: string; isPlaying?: boolean; updatedAt?: string }): FeedItemDTO {
return {
user: { id: username, username, displayName: null, avatarUrl: null },
track: { id: 't', title: 't', artist: 'a', album: null, artworkUrl: null, durationMs: null, isrc: null, links: {} },
isPlaying: opts.isPlaying ?? false,
source: 'spotify',
sourceApp: null,
sourceUrl: null,
progressMs: null,
updatedAt: opts.updatedAt ?? '2026-01-01T00:00:00.000Z',
listenId: null,
reactions: [],
commentCount: 0,
pinnedAt: opts.pinnedAt ?? null,
};
}
const names = (items: FeedItemDTO[]) => items.map((i) => i.user.username);
describe('sortFeed', () => {
it('puts pinned friends first, in the order they were pinned', () => {
const feed = sortFeed([
item('live', { isPlaying: true }),
item('pinnedSecond', { pinnedAt: '2026-01-02T00:00:00.000Z' }),
item('pinnedFirst', { pinnedAt: '2026-01-01T00:00:00.000Z' }),
]);
expect(names(feed)).toEqual(['pinnedFirst', 'pinnedSecond', 'live']);
});
it('then live listeners, then most recently updated', () => {
const feed = sortFeed([
item('old', { updatedAt: '2026-01-01T00:00:00.000Z' }),
item('recent', { updatedAt: '2026-01-03T00:00:00.000Z' }),
item('live', { isPlaying: true, updatedAt: '2025-12-01T00:00:00.000Z' }),
]);
expect(names(feed)).toEqual(['live', 'recent', 'old']);
});
it('does not mutate its input', () => {
const input = [item('b', {}), item('a', { isPlaying: true })];
sortFeed(input);
expect(names(input)).toEqual(['b', 'a']);
});
});