summaryrefslogtreecommitdiff
path: root/packages/backend/test-federation/test/move.test.ts
blob: 56a57de8a4e5567c6f55dc87d0ad986256fe986f (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
import assert, { strictEqual } from 'node:assert';
import { createAccount, type LoginUser, sleep } from './utils.js';

describe('Move', () => {
	test('Minimum move', async () => {
		const [alice, bob] = await Promise.all([
			createAccount('a.test'),
			createAccount('b.test'),
		]);

		await bob.client.request('i/update', { alsoKnownAs: [`@${alice.username}@a.test`] });
		await alice.client.request('i/move', { moveToAccount: `@${bob.username}@b.test` });
	});

	/** @see https://github.com/misskey-dev/misskey/issues/11320 */
	describe('Following relation is transferred after move', () => {
		let alice: LoginUser, bob: LoginUser, carol: LoginUser;

		beforeAll(async () => {
			[alice, bob] = await Promise.all([
				createAccount('a.test'),
				createAccount('b.test'),
			]);
			carol = await createAccount('a.test');

			// Follow @carol@a.test ==> @alice@a.test
			await carol.client.request('following/create', { userId: alice.id });

			// Move @alice@a.test ==> @bob@b.test
			await bob.client.request('i/update', { alsoKnownAs: [`@${alice.username}@a.test`] });
			await alice.client.request('i/move', { moveToAccount: `@${bob.username}@b.test` });
			await sleep();
		});

		test('Check from follower', async () => {
			const following = await carol.client.request('users/following', { userId: carol.id });
			strictEqual(following.length, 2);
			const followees = following.map(({ followee }) => followee);
			assert(followees.every(followee => followee != null));
			assert(followees.some(({ id, url }) => id === alice.id && url === null));
			assert(followees.some(({ url }) => url === `https://b.test/@${bob.username}`));
		});

		test('Check from followee', async () => {
			const followers = await bob.client.request('users/followers', { userId: bob.id });
			strictEqual(followers.length, 1);
			const follower = followers[0].follower;
			assert(follower != null);
			strictEqual(follower.url, `https://a.test/@${carol.username}`);
		});
	});
});