|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: syuilo and misskey-project |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-only |
| 4 | + */ |
| 5 | + |
| 6 | +import { Test } from '@nestjs/testing'; |
| 7 | + |
| 8 | +import { CoreModule } from '@/core/CoreModule.js'; |
| 9 | +import { NoteCreateService } from '@/core/NoteCreateService.js'; |
| 10 | +import { GlobalModule } from '@/GlobalModule.js'; |
| 11 | +import { MiNote } from '@/models/Note.js'; |
| 12 | +import { IPoll } from '@/models/Poll.js'; |
| 13 | +import { MiDriveFile } from '@/models/DriveFile.js'; |
| 14 | + |
| 15 | +describe('NoteCreateService', () => { |
| 16 | + let noteCreateService: NoteCreateService; |
| 17 | + |
| 18 | + beforeAll(async () => { |
| 19 | + const app = await Test.createTestingModule({ |
| 20 | + imports: [GlobalModule, CoreModule], |
| 21 | + }).compile(); |
| 22 | + noteCreateService = app.get<NoteCreateService>(NoteCreateService); |
| 23 | + }); |
| 24 | + |
| 25 | + describe('is-renote', () => { |
| 26 | + const base: MiNote = { |
| 27 | + id: 'some-note-id', |
| 28 | + replyId: null, |
| 29 | + reply: null, |
| 30 | + renoteId: null, |
| 31 | + renote: null, |
| 32 | + threadId: null, |
| 33 | + text: null, |
| 34 | + name: null, |
| 35 | + cw: null, |
| 36 | + userId: 'some-user-id', |
| 37 | + user: null, |
| 38 | + localOnly: false, |
| 39 | + reactionAcceptance: null, |
| 40 | + renoteCount: 0, |
| 41 | + repliesCount: 0, |
| 42 | + clippedCount: 0, |
| 43 | + reactions: {}, |
| 44 | + visibility: 'public', |
| 45 | + uri: null, |
| 46 | + url: null, |
| 47 | + fileIds: [], |
| 48 | + attachedFileTypes: [], |
| 49 | + visibleUserIds: [], |
| 50 | + mentions: [], |
| 51 | + mentionedRemoteUsers: '', |
| 52 | + reactionAndUserPairCache: [], |
| 53 | + emojis: [], |
| 54 | + tags: [], |
| 55 | + hasPoll: false, |
| 56 | + channelId: null, |
| 57 | + channel: null, |
| 58 | + userHost: null, |
| 59 | + replyUserId: null, |
| 60 | + replyUserHost: null, |
| 61 | + renoteUserId: null, |
| 62 | + renoteUserHost: null, |
| 63 | + }; |
| 64 | + |
| 65 | + const poll: IPoll = { |
| 66 | + choices: ['kinoko', 'takenoko'], |
| 67 | + multiple: false, |
| 68 | + expiresAt: null, |
| 69 | + }; |
| 70 | + |
| 71 | + const file: MiDriveFile = { |
| 72 | + id: 'some-file-id', |
| 73 | + userId: null, |
| 74 | + user: null, |
| 75 | + userHost: null, |
| 76 | + md5: '', |
| 77 | + name: '', |
| 78 | + type: '', |
| 79 | + size: 0, |
| 80 | + comment: null, |
| 81 | + blurhash: null, |
| 82 | + properties: {}, |
| 83 | + storedInternal: false, |
| 84 | + url: '', |
| 85 | + thumbnailUrl: null, |
| 86 | + webpublicUrl: null, |
| 87 | + webpublicType: null, |
| 88 | + accessKey: null, |
| 89 | + thumbnailAccessKey: null, |
| 90 | + webpublicAccessKey: null, |
| 91 | + uri: null, |
| 92 | + src: null, |
| 93 | + folderId: null, |
| 94 | + folder: null, |
| 95 | + isSensitive: false, |
| 96 | + maybeSensitive: false, |
| 97 | + maybePorn: false, |
| 98 | + isLink: false, |
| 99 | + requestHeaders: null, |
| 100 | + requestIp: null, |
| 101 | + }; |
| 102 | + |
| 103 | + test('note without renote should not be Renote', () => { |
| 104 | + const note = { renote: null }; |
| 105 | + expect(noteCreateService['isRenote'](note)).toBe(false); |
| 106 | + }); |
| 107 | + |
| 108 | + test('note with renote should be Renote and not be Quote', () => { |
| 109 | + const note = { renote: base }; |
| 110 | + expect(noteCreateService['isRenote'](note)).toBe(true); |
| 111 | + expect(noteCreateService['isQuote'](note)).toBe(false); |
| 112 | + }); |
| 113 | + |
| 114 | + test('note with renote and text should be Quote', () => { |
| 115 | + const note = { renote: base, text: 'some-text' }; |
| 116 | + expect(noteCreateService['isRenote'](note)).toBe(true); |
| 117 | + expect(noteCreateService['isQuote'](note)).toBe(true); |
| 118 | + }); |
| 119 | + |
| 120 | + test('note with renote and cw should be Quote', () => { |
| 121 | + const note = { renote: base, cw: 'some-cw' }; |
| 122 | + expect(noteCreateService['isRenote'](note)).toBe(true); |
| 123 | + expect(noteCreateService['isQuote'](note)).toBe(true); |
| 124 | + }); |
| 125 | + |
| 126 | + test('note with renote and reply should be Quote', () => { |
| 127 | + const note = { renote: base, reply: { ...base, id: 'another-note-id' } }; |
| 128 | + expect(noteCreateService['isRenote'](note)).toBe(true); |
| 129 | + expect(noteCreateService['isQuote'](note)).toBe(true); |
| 130 | + }); |
| 131 | + |
| 132 | + test('note with renote and poll should be Quote', () => { |
| 133 | + const note = { renote: base, poll }; |
| 134 | + expect(noteCreateService['isRenote'](note)).toBe(true); |
| 135 | + expect(noteCreateService['isQuote'](note)).toBe(true); |
| 136 | + }); |
| 137 | + |
| 138 | + test('note with renote and non-empty files should be Quote', () => { |
| 139 | + const note = { renote: base, files: [file] }; |
| 140 | + expect(noteCreateService['isRenote'](note)).toBe(true); |
| 141 | + expect(noteCreateService['isQuote'](note)).toBe(true); |
| 142 | + }); |
| 143 | + }); |
| 144 | +}); |
0 commit comments