1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-05-15 05:45:42 +02:00
Files
misskey/packages/backend/test-federation/test/emoji.test.ts
かっこかり 6d15fe32d0 enhance(backend/test): Migrate tests to vitest (#16935)
* wip

* update fake-timers and migrate

* fix

* remove jest-mock

* fix

* fix

* fix

* fix

* attempt to fix unit tests

* attempt to fix e2e tests

* fix federation test [ci skip]

* attempt to fix e2e tests

* fix typecheck

* fix unit tests

* fix

* attempt to fix e2e

* fix

* Revert "attempt to fix e2e"

This reverts commit b7b7b05d85.

* attempt to fix e2e

* revert attempt to fix e2e

* update deps

* update vitest

* migrate

* attempt to fix e2e

* update

* fix

* remove vite swc plugin as oxc parser can handle decorators

* attempt to fix drive/files/create test

* Revert "attempt to fix drive/files/create test"

This reverts commit 4715153375.

* fix: エンドポイントにまつわるテストをunitからe2eに移動

* attempt to fix e2e

* remove swc

* attempt to fix e2e

* Revert "attempt to fix e2e"

This reverts commit 9fb86a4076.

* add logs for debug

* attempt to fix e2e

* Partially revert "attempt to fix e2e"

This reverts commit fb0008c85a.

* attempt to fix test

* fix: attempt to fix test

* Revert "fix: attempt to fix test"

This reverts commit ed2f5c40e8.

* Revert "attempt to fix test"

This reverts commit d7329c46f1.

* attempt to fix e2e

* fix: surpass eventemitter warning by increasing defaultMaxListeners

* attempt to fix e2e

* fix

* fix e2e not ending properly

* exp: add hanging-process reporter for investigation

* Revert "exp: add hanging-process reporter for investigation"

This reverts commit 26851f8282.

* update changelog
2026-04-20 14:57:29 +09:00

99 lines
3.9 KiB
TypeScript

import { describe, test, beforeAll } from 'vitest';
import assert, { deepStrictEqual, strictEqual } from 'assert';
import * as Misskey from 'misskey-js';
import { addCustomEmoji, createAccount, type LoginUser, resolveRemoteUser, sleep } from './utils.js';
describe('Emoji', () => {
let alice: LoginUser, bob: LoginUser;
let bobInA: Misskey.entities.UserDetailedNotMe, aliceInB: Misskey.entities.UserDetailedNotMe;
beforeAll(async () => {
[alice, bob] = await Promise.all([
createAccount('a.test'),
createAccount('b.test'),
]);
[bobInA, aliceInB] = await Promise.all([
resolveRemoteUser('b.test', bob.id, alice),
resolveRemoteUser('a.test', alice.id, bob),
]);
await bob.client.request('following/create', { userId: aliceInB.id });
await sleep();
});
test('Custom emoji are delivered with Note delivery', async () => {
const emoji = await addCustomEmoji('a.test');
await alice.client.request('notes/create', { text: `I love :${emoji.name}:` });
await sleep();
const notes = await bob.client.request('notes/timeline', {});
const noteInB = notes[0];
strictEqual(noteInB.text, `I love \u200b:${emoji.name}:\u200b`);
assert(noteInB.emojis != null);
assert(emoji.name in noteInB.emojis);
strictEqual(noteInB.emojis[emoji.name], emoji.url);
});
test('Custom emoji are delivered with Reaction delivery', async () => {
const emoji = await addCustomEmoji('a.test');
const note = (await alice.client.request('notes/create', { text: 'a' })).createdNote;
await sleep();
await alice.client.request('notes/reactions/create', { noteId: note.id, reaction: `:${emoji.name}:` });
await sleep();
const noteInB = (await bob.client.request('notes/timeline', {}))[0];
deepStrictEqual(noteInB.reactions[`:${emoji.name}@a.test:`], 1);
deepStrictEqual(noteInB.reactionEmojis[`${emoji.name}@a.test`], emoji.url);
});
test('Custom emoji are delivered with Profile delivery', async () => {
const emoji = await addCustomEmoji('a.test');
const renewedAlice = await alice.client.request('i/update', { name: `:${emoji.name}:` });
await sleep();
const renewedaliceInB = await bob.client.request('users/show', { userId: aliceInB.id });
strictEqual(renewedaliceInB.name, renewedAlice.name);
assert(emoji.name in renewedaliceInB.emojis);
strictEqual(renewedaliceInB.emojis[emoji.name], emoji.url);
});
test('Local-only custom emoji aren\'t delivered with Note delivery', async () => {
const emoji = await addCustomEmoji('a.test', { localOnly: true });
await alice.client.request('notes/create', { text: `I love :${emoji.name}:` });
await sleep();
const notes = await bob.client.request('notes/timeline', {});
const noteInB = notes[0];
strictEqual(noteInB.text, `I love \u200b:${emoji.name}:\u200b`);
// deepStrictEqual(noteInB.emojis, {}); // TODO: this fails (why?)
deepStrictEqual({ ...noteInB.emojis }, {});
});
test('Local-only custom emoji aren\'t delivered with Reaction delivery', async () => {
const emoji = await addCustomEmoji('a.test', { localOnly: true });
const note = (await alice.client.request('notes/create', { text: 'a' })).createdNote;
await sleep();
await alice.client.request('notes/reactions/create', { noteId: note.id, reaction: `:${emoji.name}:` });
await sleep();
const noteInB = (await bob.client.request('notes/timeline', {}))[0];
deepStrictEqual({ ...noteInB.reactions }, { '❤': 1 });
deepStrictEqual({ ...noteInB.reactionEmojis }, {});
});
test('Local-only custom emoji aren\'t delivered with Profile delivery', async () => {
const emoji = await addCustomEmoji('a.test', { localOnly: true });
const renewedAlice = await alice.client.request('i/update', { name: `:${emoji.name}:` });
await sleep();
const renewedaliceInB = await bob.client.request('users/show', { userId: aliceInB.id });
strictEqual(renewedaliceInB.name, renewedAlice.name);
deepStrictEqual({ ...renewedaliceInB.emojis }, {});
});
});