mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2024-12-15 17:35:44 +01:00
8c5d9a6295
* fix(backend): incorrect logic for determining whether Quote or not * Update CHANGELOG.md --------- Co-authored-by: syuilo <4439005+syuilo@users.noreply.github.com>
144 lines
3.7 KiB
TypeScript
144 lines
3.7 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import { Test } from '@nestjs/testing';
|
|
|
|
import { CoreModule } from '@/core/CoreModule.js';
|
|
import { NoteCreateService } from '@/core/NoteCreateService.js';
|
|
import { GlobalModule } from '@/GlobalModule.js';
|
|
import { MiNote } from '@/models/Note.js';
|
|
import { IPoll } from '@/models/Poll.js';
|
|
import { MiDriveFile } from '@/models/DriveFile.js';
|
|
|
|
describe('NoteCreateService', () => {
|
|
let noteCreateService: NoteCreateService;
|
|
|
|
beforeAll(async () => {
|
|
const app = await Test.createTestingModule({
|
|
imports: [GlobalModule, CoreModule],
|
|
}).compile();
|
|
noteCreateService = app.get<NoteCreateService>(NoteCreateService);
|
|
});
|
|
|
|
describe('is-renote', () => {
|
|
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,
|
|
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,
|
|
};
|
|
|
|
const poll: IPoll = {
|
|
choices: ['kinoko', 'takenoko'],
|
|
multiple: false,
|
|
expiresAt: null,
|
|
};
|
|
|
|
const file: MiDriveFile = {
|
|
id: 'some-file-id',
|
|
userId: null,
|
|
user: null,
|
|
userHost: null,
|
|
md5: '',
|
|
name: '',
|
|
type: '',
|
|
size: 0,
|
|
comment: null,
|
|
blurhash: null,
|
|
properties: {},
|
|
storedInternal: false,
|
|
url: '',
|
|
thumbnailUrl: null,
|
|
webpublicUrl: null,
|
|
webpublicType: null,
|
|
accessKey: null,
|
|
thumbnailAccessKey: null,
|
|
webpublicAccessKey: null,
|
|
uri: null,
|
|
src: null,
|
|
folderId: null,
|
|
folder: null,
|
|
isSensitive: false,
|
|
maybeSensitive: false,
|
|
maybePorn: false,
|
|
isLink: false,
|
|
requestHeaders: null,
|
|
requestIp: null,
|
|
};
|
|
|
|
test('note without renote should not be Renote', () => {
|
|
const note = { renote: null };
|
|
expect(noteCreateService['isRenote'](note)).toBe(false);
|
|
});
|
|
|
|
test('note with renote should be Renote and not be Quote', () => {
|
|
const note = { renote: base };
|
|
expect(noteCreateService['isRenote'](note)).toBe(true);
|
|
expect(noteCreateService['isQuote'](note)).toBe(false);
|
|
});
|
|
|
|
test('note with renote and text should be Quote', () => {
|
|
const note = { renote: base, text: 'some-text' };
|
|
expect(noteCreateService['isRenote'](note)).toBe(true);
|
|
expect(noteCreateService['isQuote'](note)).toBe(true);
|
|
});
|
|
|
|
test('note with renote and cw should be Quote', () => {
|
|
const note = { renote: base, cw: 'some-cw' };
|
|
expect(noteCreateService['isRenote'](note)).toBe(true);
|
|
expect(noteCreateService['isQuote'](note)).toBe(true);
|
|
});
|
|
|
|
test('note with renote and reply should be Quote', () => {
|
|
const note = { renote: base, reply: { ...base, id: 'another-note-id' } };
|
|
expect(noteCreateService['isRenote'](note)).toBe(true);
|
|
expect(noteCreateService['isQuote'](note)).toBe(true);
|
|
});
|
|
|
|
test('note with renote and poll should be Quote', () => {
|
|
const note = { renote: base, poll };
|
|
expect(noteCreateService['isRenote'](note)).toBe(true);
|
|
expect(noteCreateService['isQuote'](note)).toBe(true);
|
|
});
|
|
|
|
test('note with renote and non-empty files should be Quote', () => {
|
|
const note = { renote: base, files: [file] };
|
|
expect(noteCreateService['isRenote'](note)).toBe(true);
|
|
expect(noteCreateService['isQuote'](note)).toBe(true);
|
|
});
|
|
});
|
|
});
|