Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kozakura913 committed Jan 7, 2025
1 parent 5805a4a commit 6826ea9
Showing 1 changed file with 15 additions and 54 deletions.
69 changes: 15 additions & 54 deletions packages/backend/test-federation/test/fetch-outbox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,24 @@ import * as Misskey from 'cherrypick-js';
import { createAccount, type LoginUser, resolveRemoteUser } from './utils.js';

describe('fetch-outbox', () => {
let alice: LoginUser, bob: LoginUser, carol:LoginUser;
let bobInAliceHost: Misskey.entities.UserDetailedNotMe, carolInAliceHost: Misskey.entities.UserDetailedNotMe;
let alice: LoginUser, bob: LoginUser;
let bobInAliceHost: Misskey.entities.UserDetailedNotMe;
let bobNote: Misskey.entities.Note, bobRenote: Misskey.entities.Note;
let carolNote: Misskey.entities.Note, carolRenote: Misskey.entities.Note;

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

[bobInAliceHost, carolInAliceHost] = await Promise.all([
[bobInAliceHost] = await Promise.all([
resolveRemoteUser('b.test', bob.id, alice),
resolveRemoteUser('b.test', carol.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;
carolNote = (await carol.client.request('notes/create', { text: 'I am Carol!' })).createdNote;
carolRenote = (await carol.client.request('notes/create', { renoteId: carolNote.id })).createdNote;
});
test('includeAnnounce false(New User)', async () => {
await alice.client.request('ap/fetch-outbox', { userId: bobInAliceHost.id, wait: true, includeAnnounce: false });
const fetch_notes = await alice.client.request('users/notes', { userId: bobInAliceHost.id, withReplies: false, withRenotes: true });
strictEqual(fetch_notes.length, 1, JSON.stringify(fetch_notes));
deepStrictEqual(JSON.stringify(fetch_notes.map(note => {
return {
text: note.text,
createdAt: note.createdAt,
};
})), JSON.stringify([
{
text: bobNote.text,
createdAt: bobNote.createdAt,
},
]));
});
test('includeAnnounce true(Know User)', async () => {
await alice.client.request('ap/fetch-outbox', { userId: bobInAliceHost.id, wait: true, includeAnnounce: true });
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 => {
Expand All @@ -60,29 +39,11 @@ describe('fetch-outbox', () => {
]));
strictEqual(fetch_notes[0].renote?.id, fetch_notes[1].id);
});
test('includeAnnounce true(New User)', async () => {
await alice.client.request('ap/fetch-outbox', { userId: carolInAliceHost.id, wait: true, includeAnnounce: true });
const fetch_notes = await alice.client.request('users/notes', { userId: carolInAliceHost.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: carolRenote.text,
createdAt: carolRenote.createdAt,
}, {
text: carolNote.text,
createdAt: carolNote.createdAt,
},
]));
strictEqual(fetch_notes[0].renote?.id, fetch_notes[1].id);
});
test('includeAnnounce false(Know User)', async () => {
await alice.client.request('ap/fetch-outbox', { userId: carolInAliceHost.id, wait: true, includeAnnounce: false });
const fetch_notes = await alice.client.request('users/notes', { userId: carolInAliceHost.id, withReplies: false, withRenotes: true });
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 => {
Expand All @@ -92,11 +53,11 @@ describe('fetch-outbox', () => {
};
})), JSON.stringify([
{
text: carolRenote.text,
createdAt: carolRenote.createdAt,
text: bobRenote.text,
createdAt: bobRenote.createdAt,
}, {
text: carolNote.text,
createdAt: carolNote.createdAt,
text: bobNote.text,
createdAt: bobNote.createdAt,
},
]));
strictEqual(fetch_notes[0].renote?.id, fetch_notes[1].id);
Expand Down

0 comments on commit 6826ea9

Please sign in to comment.