 b990ae6b23
			
		
	
	b990ae6b23
	
	
	
		
			
			* test(backend): add federation test
* fix(ci): install pnpm
* fix(ci): cd
* fix(ci): build entire project
* fix(ci): skip frontend build
* fix(ci): pull submodule when checkout
* chore: show log for debugging
* Revert "chore: show log for debugging"
This reverts commit a930964b8d.
* fix(ci): build entire project
* chore: omit unused globals
* refactor: use strictEqual and simplify some asserts
* test: follow requests
* refactor: add resolveRemoteNote function
* refactor: refine resolveRemoteUser function
* refactor: cache admin credentials
* refactor: simplify assertion with excluded fields
* refactor: use assert
* test: note
* chore: labeler detect federation
* test: blocking
* test: move
* fix: use appropriate TLD
* chore: shorter purge interval
* fix(ci): change TLD
* refactor: delete trivial comment
* test(user): isCat
* chore: use jest
* chore: omit logs
* chore: add memo
* fix(ci): omit unnecessary build
* test: pinning Note
* fix: build daemon in container
* style: indent
* test(streaming): timeline
* chore: rename
* fix: delete role after test
* refactor: resolve users by uri
* fix: delete antenna after test
* test: api timeline
* test: Note deletion
* refactor: sleep function
* test: notification
* style: indent
* refactor: type-safe host
* docs: update description
* refactor: resolve function params
* fix(block): wrong test name
* fix: invalid type
* fix: longer timeout for fire testing
* test(timeline): hashtag
* test(note): vote delivery
* fix: wrong description
* fix: hashtag channel param type
* refactor: wrap basic cases
* test(timeline): add homeTimeline tests
* fix(timeline): correct wrong case and description
* test(notification): add tests for Note
* refactor(user): wrap profile consistency with describe
* chore(note): add issue link
* test(timeline): add test
* test(user): suspension
* test: emoji
* refactor: fetch admin first
* perf: faster tests
* test(drive): sensitive flag
* test(emoji): add tests
* chore: ignore .config/docker.env
* chore: hard-coded tester IP address
* test(emoji): custom emoji are surrounded by zero width space
* refactor: client and username as property
* test(notification): mute
* fix(notification): correct description
* test(block): mention
* refactor(emoji): addCustomEmoji function
* fix: typo
* test(note): add reaction tests
* test(timeline): Note deletion
* fix: unnecessary ts-expect-error
* refactor: unnecessary fetch mocking
* chore: add TODO comments
* test(user): deletion
* chore: enable --frozen-lockfile
* fix(ci): copying configs
* docs: update CONTRIBUTING.md
* docs: fix typo
* chore: set default sleep duration
* fix(notification): omit flaky tests
* fix(notification): correct type
* test(notification): add api endpoint tests
* chore: remove redundant mute test
* refactor: use param client
* fix: start timer after trigger
* refactor: remove unnecessary any
* chore: shorter timeout for checking if fired
* fix(block): remove outdated comment
* refactor: shorten remote user variable name
* refactor(block): use existing function
* refactor: file upload
* docs: update description
* test(user): ffVisibility
* fix: `/api/signin` -> `/api/signin-flow`
* test: abuse report
* refactor: use existing type
* refactor: extract duplicate configs to template file
* fix: typo
* fix: avoid conflict
* refactor: change container dependency
* perf: start misskey parallelly
* fix: remove dependency
* chore(backend): add typecheck
* test: add check for #14728
* chore: enable eslint check
* perf: don't start linked services when test
* test(note): remote note deletion for moderation
* chore: define config template
* chore: write setup script
* refactor: omit unnecessary conditional
* refactor: clarify scope
* refactor: omit type assertion
* refactor: omit logs
* style
* refactor: redundant promise
* refactor: unnecessary imports
* refactor: use readable error code
* refactor: cache set in signin function
* refactor: optimize import
		
	
		
			
				
	
	
		
			225 lines
		
	
	
		
			7.5 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			225 lines
		
	
	
		
			7.5 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import { deepStrictEqual, rejects, strictEqual } from 'node:assert';
 | |
| import * as Misskey from 'misskey-js';
 | |
| import { assertNotificationReceived, createAccount, type LoginUser, resolveRemoteNote, resolveRemoteUser, sleep } from './utils.js';
 | |
| 
 | |
| describe('Block', () => {
 | |
| 	describe('Check follow', () => {
 | |
| 		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),
 | |
| 			]);
 | |
| 		});
 | |
| 
 | |
| 		test('Cannot follow if blocked', async () => {
 | |
| 			await alice.client.request('blocking/create', { userId: bobInA.id });
 | |
| 			await sleep();
 | |
| 			await rejects(
 | |
| 				async () => await bob.client.request('following/create', { userId: aliceInB.id }),
 | |
| 				(err: any) => {
 | |
| 					strictEqual(err.code, 'BLOCKED');
 | |
| 					return true;
 | |
| 				},
 | |
| 			);
 | |
| 
 | |
| 			const following = await bob.client.request('users/following', { userId: bob.id });
 | |
| 			strictEqual(following.length, 0);
 | |
| 			const followers = await alice.client.request('users/followers', { userId: alice.id });
 | |
| 			strictEqual(followers.length, 0);
 | |
| 		});
 | |
| 
 | |
| 		// FIXME: this is invalid case
 | |
| 		test('Cannot follow even if unblocked', async () => {
 | |
| 			// unblock here
 | |
| 			await alice.client.request('blocking/delete', { userId: bobInA.id });
 | |
| 			await sleep();
 | |
| 
 | |
| 			// TODO: why still being blocked?
 | |
| 			await rejects(
 | |
| 				async () => await bob.client.request('following/create', { userId: aliceInB.id }),
 | |
| 				(err: any) => {
 | |
| 					strictEqual(err.code, 'BLOCKED');
 | |
| 					return true;
 | |
| 				},
 | |
| 			);
 | |
| 		});
 | |
| 
 | |
| 		test.skip('Can follow if unblocked', async () => {
 | |
| 			await alice.client.request('blocking/delete', { userId: bobInA.id });
 | |
| 			await sleep();
 | |
| 
 | |
| 			await bob.client.request('following/create', { userId: aliceInB.id });
 | |
| 			await sleep();
 | |
| 
 | |
| 			const following = await bob.client.request('users/following', { userId: bob.id });
 | |
| 			strictEqual(following.length, 1);
 | |
| 			const followers = await alice.client.request('users/followers', { userId: alice.id });
 | |
| 			strictEqual(followers.length, 1);
 | |
| 		});
 | |
| 
 | |
| 		test.skip('Remove follower when block them', async () => {
 | |
| 			test('before block', async () => {
 | |
| 				const following = await bob.client.request('users/following', { userId: bob.id });
 | |
| 				strictEqual(following.length, 1);
 | |
| 				const followers = await alice.client.request('users/followers', { userId: alice.id });
 | |
| 				strictEqual(followers.length, 1);
 | |
| 			});
 | |
| 
 | |
| 			await alice.client.request('blocking/create', { userId: bobInA.id });
 | |
| 			await sleep();
 | |
| 
 | |
| 			test('after block', async () => {
 | |
| 				const following = await bob.client.request('users/following', { userId: bob.id });
 | |
| 				strictEqual(following.length, 0);
 | |
| 				const followers = await alice.client.request('users/followers', { userId: alice.id });
 | |
| 				strictEqual(followers.length, 0);
 | |
| 			});
 | |
| 		});
 | |
| 	});
 | |
| 
 | |
| 	describe('Check reply', () => {
 | |
| 		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),
 | |
| 			]);
 | |
| 		});
 | |
| 
 | |
| 		test('Cannot reply if blocked', async () => {
 | |
| 			await alice.client.request('blocking/create', { userId: bobInA.id });
 | |
| 			await sleep();
 | |
| 
 | |
| 			const note = (await alice.client.request('notes/create', { text: 'a' })).createdNote;
 | |
| 			const resolvedNote = await resolveRemoteNote('a.test', note.id, bob);
 | |
| 			await rejects(
 | |
| 				async () => await bob.client.request('notes/create', { text: 'b', replyId: resolvedNote.id }),
 | |
| 				(err: any) => {
 | |
| 					strictEqual(err.code, 'YOU_HAVE_BEEN_BLOCKED');
 | |
| 					return true;
 | |
| 				},
 | |
| 			);
 | |
| 		});
 | |
| 
 | |
| 		test('Can reply if unblocked', async () => {
 | |
| 			await alice.client.request('blocking/delete', { userId: bobInA.id });
 | |
| 			await sleep();
 | |
| 
 | |
| 			const note = (await alice.client.request('notes/create', { text: 'a' })).createdNote;
 | |
| 			const resolvedNote = await resolveRemoteNote('a.test', note.id, bob);
 | |
| 			const reply = (await bob.client.request('notes/create', { text: 'b', replyId: resolvedNote.id })).createdNote;
 | |
| 
 | |
| 			await resolveRemoteNote('b.test', reply.id, alice);
 | |
| 		});
 | |
| 	});
 | |
| 
 | |
| 	describe('Check reaction', () => {
 | |
| 		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),
 | |
| 			]);
 | |
| 		});
 | |
| 
 | |
| 		test('Cannot reaction if blocked', async () => {
 | |
| 			await alice.client.request('blocking/create', { userId: bobInA.id });
 | |
| 			await sleep();
 | |
| 
 | |
| 			const note = (await alice.client.request('notes/create', { text: 'a' })).createdNote;
 | |
| 			const resolvedNote = await resolveRemoteNote('a.test', note.id, bob);
 | |
| 			await rejects(
 | |
| 				async () => await bob.client.request('notes/reactions/create', { noteId: resolvedNote.id, reaction: '😅' }),
 | |
| 				(err: any) => {
 | |
| 					strictEqual(err.code, 'YOU_HAVE_BEEN_BLOCKED');
 | |
| 					return true;
 | |
| 				},
 | |
| 			);
 | |
| 		});
 | |
| 
 | |
| 		// FIXME: this is invalid case
 | |
| 		test('Cannot reaction even if unblocked', async () => {
 | |
| 			// unblock here
 | |
| 			await alice.client.request('blocking/delete', { userId: bobInA.id });
 | |
| 			await sleep();
 | |
| 
 | |
| 			const note = (await alice.client.request('notes/create', { text: 'a' })).createdNote;
 | |
| 			const resolvedNote = await resolveRemoteNote('a.test', note.id, bob);
 | |
| 
 | |
| 			// TODO: why still being blocked?
 | |
| 			await rejects(
 | |
| 				async () => await bob.client.request('notes/reactions/create', { noteId: resolvedNote.id, reaction: '😅' }),
 | |
| 				(err: any) => {
 | |
| 					strictEqual(err.code, 'YOU_HAVE_BEEN_BLOCKED');
 | |
| 					return true;
 | |
| 				},
 | |
| 			);
 | |
| 		});
 | |
| 
 | |
| 		test.skip('Can reaction if unblocked', async () => {
 | |
| 			await alice.client.request('blocking/delete', { userId: bobInA.id });
 | |
| 			await sleep();
 | |
| 
 | |
| 			const note = (await alice.client.request('notes/create', { text: 'a' })).createdNote;
 | |
| 			const resolvedNote = await resolveRemoteNote('a.test', note.id, bob);
 | |
| 			await bob.client.request('notes/reactions/create', { noteId: resolvedNote.id, reaction: '😅' });
 | |
| 
 | |
| 			const _note = await alice.client.request('notes/show', { noteId: note.id });
 | |
| 			deepStrictEqual(_note.reactions, { '😅': 1 });
 | |
| 		});
 | |
| 	});
 | |
| 
 | |
| 	describe('Check mention', () => {
 | |
| 		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),
 | |
| 			]);
 | |
| 		});
 | |
| 
 | |
| 		/** NOTE: You should mute the target to stop receiving notifications */
 | |
| 		test('Can mention and notified even if blocked', async () => {
 | |
| 			await alice.client.request('blocking/create', { userId: bobInA.id });
 | |
| 			await sleep();
 | |
| 
 | |
| 			const text = `@${alice.username}@a.test plz unblock me!`;
 | |
| 			await assertNotificationReceived(
 | |
| 				'a.test', alice,
 | |
| 				async () => await bob.client.request('notes/create', { text }),
 | |
| 				notification => notification.type === 'mention' && notification.userId === bobInA.id && notification.note.text === text,
 | |
| 				true,
 | |
| 			);
 | |
| 		});
 | |
| 	});
 | |
| });
 |