summaryrefslogtreecommitdiff
path: root/packages/backend/test/unit/misc/is-renote.ts
blob: 3c628d82983b3f3d62dd372adc3dfe93c9412361 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
 * SPDX-FileCopyrightText: syuilo and misskey-project
 * SPDX-License-Identifier: AGPL-3.0-only
 */

import { isQuote, isRenote } from '@/misc/is-renote.js';
import { MiNote } from '@/models/Note.js';

const base: MiNote = {
	id: 'some-note-id',
	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,
	pageCount: 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,
	renoteChannelId: 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);
	});
});