From bc3c0745e1bd1d6006115db2b4f1aa69dd42ebd9 Mon Sep 17 00:00:00 2001 From: kozakura913 <98575220+kozakura913@users.noreply.github.com> Date: Thu, 9 Jan 2025 10:05:18 +0900 Subject: [PATCH] =?UTF-8?q?fetch-outbox=E3=81=AE=E9=80=A3=E5=90=88?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0=20(#600)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test-federation/test/fetch-outbox.test.ts | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 packages/backend/test-federation/test/fetch-outbox.test.ts diff --git a/packages/backend/test-federation/test/fetch-outbox.test.ts b/packages/backend/test-federation/test/fetch-outbox.test.ts new file mode 100644 index 0000000000..dd7b6565f4 --- /dev/null +++ b/packages/backend/test-federation/test/fetch-outbox.test.ts @@ -0,0 +1,65 @@ +import { deepStrictEqual, strictEqual } from 'assert'; +import * as Misskey from 'cherrypick-js'; +import { createAccount, type LoginUser, resolveRemoteUser } from './utils.js'; + +describe('fetch-outbox', () => { + let alice: LoginUser, bob: LoginUser; + let bobInAliceHost: Misskey.entities.UserDetailedNotMe; + let bobNote: Misskey.entities.Note, bobRenote: Misskey.entities.Note; + + beforeAll(async () => { + [alice, bob] = await Promise.all([ + createAccount('a.test'), + createAccount('b.test'), + ]); + + [bobInAliceHost] = await Promise.all([ + resolveRemoteUser('b.test', bob.id, alice), + ]); + bobNote = (await bob.client.request('notes/create', { text: 'I am Bob!' })).createdNote; + bobRenote = (await bob.client.request('notes/create', { renoteId: bobNote.id })).createdNote; + }); + test('New User', async () => { + await alice.client.request('ap/fetch-outbox', { userId: bobInAliceHost.id, wait: true }); + const fetch_notes = await alice.client.request('users/notes', { userId: bobInAliceHost.id, withReplies: false, withRenotes: true }); + strictEqual(fetch_notes.length, 2, JSON.stringify(fetch_notes)); + deepStrictEqual(JSON.stringify(fetch_notes.map(note => { + return { + text: note.text, + createdAt: note.createdAt, + }; + })), JSON.stringify([ + { + text: bobRenote.text, + createdAt: bobRenote.createdAt, + }, { + text: bobNote.text, + createdAt: bobNote.createdAt, + }, + ])); + strictEqual(fetch_notes[0].renote?.id, fetch_notes[1].id); + }); + test('Know User (cache hit)', async () => { + //キャッシュを利用するためこのノートは取得されない + await bob.client.request('notes/create', { text: 'Bob Note 2' }); + await alice.client.request('ap/fetch-outbox', { userId: bobInAliceHost.id, wait: true }); + const fetch_notes = await alice.client.request('users/notes', { userId: bobInAliceHost.id, withReplies: false, withRenotes: true }); + //一度取得したノートは破棄されない + strictEqual(fetch_notes.length, 2, JSON.stringify(fetch_notes)); + deepStrictEqual(JSON.stringify(fetch_notes.map(note => { + return { + text: note.text, + createdAt: note.createdAt, + }; + })), JSON.stringify([ + { + text: bobRenote.text, + createdAt: bobRenote.createdAt, + }, { + text: bobNote.text, + createdAt: bobNote.createdAt, + }, + ])); + strictEqual(fetch_notes[0].renote?.id, fetch_notes[1].id); + }); +});