Sharkey/packages/backend/test/unit/models/LatestNote.ts

67 lines
2.2 KiB
TypeScript
Raw Normal View History

2024-10-09 21:09:55 +02:00
import { SkLatestNote } from '@/models/LatestNote.js';
import { MiNote } from '@/models/Note.js';
describe(SkLatestNote, () => {
describe('keyFor', () => {
it('should include userId', () => {
2024-10-12 21:30:38 +02:00
const note = new MiNote({ userId: 'abc123', fileIds: [] });
2024-10-09 21:09:55 +02:00
const key = SkLatestNote.keyFor(note);
expect(key.userId).toBe(note.userId);
});
it('should include isPublic when is public', () => {
2024-10-12 21:30:38 +02:00
const note = new MiNote({ visibility: 'public', fileIds: [] });
2024-10-09 21:09:55 +02:00
const key = SkLatestNote.keyFor(note);
expect(key.isPublic).toBeTruthy();
});
it('should include isPublic when is home-only', () => {
2024-10-12 21:30:38 +02:00
const note = new MiNote({ visibility: 'home', fileIds: [] });
2024-10-09 21:09:55 +02:00
const key = SkLatestNote.keyFor(note);
expect(key.isPublic).toBeFalsy();
});
it('should include isPublic when is followers-only', () => {
2024-10-12 21:30:38 +02:00
const note = new MiNote({ visibility: 'followers', fileIds: [] });
2024-10-09 21:09:55 +02:00
const key = SkLatestNote.keyFor(note);
expect(key.isPublic).toBeFalsy();
});
it('should include isPublic when is specified', () => {
2024-10-12 21:30:38 +02:00
const note = new MiNote({ visibility: 'specified', fileIds: [] });
2024-10-09 21:09:55 +02:00
const key = SkLatestNote.keyFor(note);
expect(key.isPublic).toBeFalsy();
});
it('should include isReply when is reply', () => {
2024-10-12 21:30:38 +02:00
const note = new MiNote({ replyId: 'abc123', fileIds: [] });
2024-10-09 21:09:55 +02:00
const key = SkLatestNote.keyFor(note);
expect(key.isReply).toBeTruthy();
});
it('should include isReply when is not reply', () => {
2024-10-12 21:30:38 +02:00
const note = new MiNote({ replyId: null, fileIds: [] });
2024-10-09 21:09:55 +02:00
const key = SkLatestNote.keyFor(note);
expect(key.isReply).toBeFalsy();
});
it('should include isQuote when is quote', () => {
2024-10-12 21:30:38 +02:00
const note = new MiNote({ renoteId: 'abc123', text: 'text', fileIds: [] });
2024-10-09 21:09:55 +02:00
const key = SkLatestNote.keyFor(note);
expect(key.isQuote).toBeTruthy();
});
it('should include isQuote when is reblog', () => {
2024-10-12 21:30:38 +02:00
const note = new MiNote({ renoteId: 'abc123', fileIds: [] });
2024-10-09 21:09:55 +02:00
const key = SkLatestNote.keyFor(note);
expect(key.isQuote).toBeFalsy();
});
it('should include isQuote when is neither quote nor reblog', () => {
2024-10-12 21:30:38 +02:00
const note = new MiNote({ renoteId: null, fileIds: [] });
2024-10-09 21:09:55 +02:00
const key = SkLatestNote.keyFor(note);
expect(key.isQuote).toBeFalsy();
});
});
});