2024-04-14 03:23:48 +02:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2024-10-09 21:09:55 +02:00
|
|
|
import { isPureRenote, isQuote, isRenote } from '@/misc/is-renote.js';
|
2024-04-14 03:23:48 +02:00
|
|
|
import { MiNote } from '@/models/Note.js';
|
|
|
|
|
|
|
|
const base: MiNote = {
|
|
|
|
id: 'some-note-id',
|
2024-04-25 12:56:19 +02:00
|
|
|
updatedAt: null,
|
2024-04-14 03:23:48 +02:00
|
|
|
replyId: null,
|
|
|
|
reply: null,
|
|
|
|
renoteId: null,
|
|
|
|
renote: null,
|
|
|
|
threadId: null,
|
|
|
|
text: null,
|
|
|
|
name: null,
|
|
|
|
cw: null,
|
|
|
|
userId: 'some-user-id',
|
|
|
|
user: null,
|
|
|
|
localOnly: false,
|
|
|
|
reactionAcceptance: null,
|
|
|
|
renoteCount: 0,
|
|
|
|
repliesCount: 0,
|
|
|
|
clippedCount: 0,
|
|
|
|
reactions: {},
|
|
|
|
visibility: 'public',
|
|
|
|
uri: null,
|
|
|
|
url: null,
|
|
|
|
fileIds: [],
|
|
|
|
attachedFileTypes: [],
|
|
|
|
visibleUserIds: [],
|
|
|
|
mentions: [],
|
|
|
|
mentionedRemoteUsers: '',
|
|
|
|
reactionAndUserPairCache: [],
|
|
|
|
emojis: [],
|
|
|
|
tags: [],
|
|
|
|
hasPoll: false,
|
|
|
|
channelId: null,
|
|
|
|
channel: null,
|
|
|
|
userHost: null,
|
|
|
|
replyUserId: null,
|
|
|
|
replyUserHost: null,
|
|
|
|
renoteUserId: null,
|
|
|
|
renoteUserHost: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('misc:is-renote', () => {
|
|
|
|
test('note without renoteId should not be Renote', () => {
|
|
|
|
expect(isRenote(base)).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('note with renoteId should be Renote and not be Quote', () => {
|
|
|
|
const note: MiNote = { ...base, renoteId: 'some-renote-id' };
|
|
|
|
expect(isRenote(note)).toBe(true);
|
|
|
|
expect(isQuote(note as any)).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('note with renoteId and text should be Quote', () => {
|
|
|
|
const note: MiNote = { ...base, renoteId: 'some-renote-id', text: 'some-text' };
|
|
|
|
expect(isRenote(note)).toBe(true);
|
|
|
|
expect(isQuote(note as any)).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('note with renoteId and cw should be Quote', () => {
|
|
|
|
const note: MiNote = { ...base, renoteId: 'some-renote-id', cw: 'some-cw' };
|
|
|
|
expect(isRenote(note)).toBe(true);
|
|
|
|
expect(isQuote(note as any)).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('note with renoteId and replyId should be Quote', () => {
|
|
|
|
const note: MiNote = { ...base, renoteId: 'some-renote-id', replyId: 'some-reply-id' };
|
|
|
|
expect(isRenote(note)).toBe(true);
|
|
|
|
expect(isQuote(note as any)).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('note with renoteId and poll should be Quote', () => {
|
|
|
|
const note: MiNote = { ...base, renoteId: 'some-renote-id', hasPoll: true };
|
|
|
|
expect(isRenote(note)).toBe(true);
|
|
|
|
expect(isQuote(note as any)).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('note with renoteId and non-empty fileIds should be Quote', () => {
|
|
|
|
const note: MiNote = { ...base, renoteId: 'some-renote-id', fileIds: ['some-file-id'] };
|
|
|
|
expect(isRenote(note)).toBe(true);
|
|
|
|
expect(isQuote(note as any)).toBe(true);
|
|
|
|
});
|
2024-10-09 21:09:55 +02:00
|
|
|
|
|
|
|
describe('isPureRenote', () => {
|
|
|
|
it('should return true when note is pure renote', () => {
|
2024-10-12 21:51:45 +02:00
|
|
|
const note = new MiNote({ renoteId: 'abc123', fileIds: [] });
|
2024-10-09 21:09:55 +02:00
|
|
|
const result = isPureRenote(note);
|
|
|
|
expect(result).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return false when note is quote', () => {
|
2024-10-12 21:51:45 +02:00
|
|
|
const note = new MiNote({ renoteId: 'abc123', text: 'text', fileIds: [] });
|
2024-10-09 21:09:55 +02:00
|
|
|
const result = isPureRenote(note);
|
|
|
|
expect(result).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return false when note is not renote', () => {
|
2024-10-12 21:51:45 +02:00
|
|
|
const note = new MiNote({ renoteId: null, fileIds: [] });
|
2024-10-09 21:09:55 +02:00
|
|
|
const result = isPureRenote(note);
|
|
|
|
expect(result).toBeFalsy();
|
|
|
|
});
|
|
|
|
});
|
2024-04-14 03:23:48 +02:00
|
|
|
});
|