Skip to content

Commit

Permalink
tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
syuilo committed Oct 4, 2023
1 parent a40734d commit 610b68c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
2 changes: 0 additions & 2 deletions packages/backend/src/server/api/endpoints/users/notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import { ApiError } from '../../error.js';
export const meta = {
tags: ['users', 'notes'],

description: 'Show all notes that this user created.',

res: {
type: 'array',
optional: false, nullable: false,
Expand Down
26 changes: 15 additions & 11 deletions packages/backend/test/e2e/timelines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ process.env.NODE_ENV = 'test';
process.env.FORCE_FOLLOW_REMOTE_USER_FOR_TESTING = 'true';

import * as assert from 'assert';
import { signup, api, post, react, startServer, waitFire, sleep, uploadUrl } from '../utils.js';
import { signup, api, post, react, startServer, waitFire, sleep, uploadUrl, randomString } from '../utils.js';
import type { INestApplicationContext } from '@nestjs/common';
import type * as misskey from 'misskey-js';

function genHost() {
return randomString() + '.example.com';
}

let app: INestApplicationContext;

beforeAll(async () => {
Expand Down Expand Up @@ -290,7 +294,7 @@ describe('Timelines', () => {
});

test.concurrent('フォローしているリモートユーザーのノートが含まれる', async () => {
const [alice, bob] = await Promise.all([signup(), signup({ host: 'example.com' })]);
const [alice, bob] = await Promise.all([signup(), signup({ host: genHost() })]);

await api('/following/create', { userId: bob.id }, alice);
const bobNote = await post(bob, { text: 'hi' });
Expand All @@ -303,7 +307,7 @@ describe('Timelines', () => {
});

test.concurrent('フォローしているリモートユーザーの visibility: home なノートが含まれる', async () => {
const [alice, bob] = await Promise.all([signup(), signup({ host: 'example.com' })]);
const [alice, bob] = await Promise.all([signup(), signup({ host: genHost() })]);

await api('/following/create', { userId: bob.id }, alice);
const bobNote = await post(bob, { text: 'hi', visibility: 'home' });
Expand Down Expand Up @@ -355,7 +359,7 @@ describe('Timelines', () => {
});

test.concurrent('リモートユーザーのノートが含まれない', async () => {
const [alice, bob] = await Promise.all([signup(), signup({ host: 'example.com' })]);
const [alice, bob] = await Promise.all([signup(), signup({ host: genHost() })]);

const bobNote = await post(bob, { text: 'hi' });

Expand Down Expand Up @@ -487,7 +491,7 @@ describe('Timelines', () => {
});

test.concurrent('リモートユーザーのノートが含まれない', async () => {
const [alice, bob] = await Promise.all([signup(), signup({ host: 'example.com' })]);
const [alice, bob] = await Promise.all([signup(), signup({ host: genHost() })]);

const bobNote = await post(bob, { text: 'hi' });

Expand All @@ -499,7 +503,7 @@ describe('Timelines', () => {
});

test.concurrent('フォローしているリモートユーザーのノートが含まれる', async () => {
const [alice, bob] = await Promise.all([signup(), signup({ host: 'example.com' })]);
const [alice, bob] = await Promise.all([signup(), signup({ host: genHost() })]);

await api('/following/create', { userId: bob.id }, alice);
const bobNote = await post(bob, { text: 'hi' });
Expand All @@ -512,7 +516,7 @@ describe('Timelines', () => {
});

test.concurrent('フォローしているリモートユーザーの visibility: home なノートが含まれる', async () => {
const [alice, bob] = await Promise.all([signup(), signup({ host: 'example.com' })]);
const [alice, bob] = await Promise.all([signup(), signup({ host: genHost() })]);

await api('/following/create', { userId: bob.id }, alice);
const bobNote = await post(bob, { text: 'hi', visibility: 'home' });
Expand Down Expand Up @@ -704,7 +708,7 @@ describe('Timelines', () => {

await sleep(100); // redisに追加されるのを待つ

const res = await api('/users/notes', {}, alice);
const res = await api('/users/notes', { userId: bob.id }, alice);

assert.strictEqual(res.body.some((note: any) => note.id === bobNote.id), false);
});
Expand All @@ -717,7 +721,7 @@ describe('Timelines', () => {

await sleep(100); // redisに追加されるのを待つ

const res = await api('/users/notes', {}, alice);
const res = await api('/users/notes', { userId: bob.id }, alice);

assert.strictEqual(res.body.some((note: any) => note.id === bobNote.id), true);
assert.strictEqual(res.body.find((note: any) => note.id === bobNote.id).text, 'hi');
Expand All @@ -732,7 +736,7 @@ describe('Timelines', () => {

await sleep(100); // redisに追加されるのを待つ

const res = await api('/users/notes', {}, alice);
const res = await api('/users/notes', { userId: bob.id }, alice);

assert.strictEqual(res.body.some((note: any) => note.id === bobNote1.id), true);
assert.strictEqual(res.body.some((note: any) => note.id === bobNote2.id), false);
Expand All @@ -747,7 +751,7 @@ describe('Timelines', () => {

await sleep(100); // redisに追加されるのを待つ

const res = await api('/users/notes', { withReplies: true }, alice);
const res = await api('/users/notes', { userId: bob.id, withReplies: true }, alice);

assert.strictEqual(res.body.some((note: any) => note.id === bobNote1.id), true);
assert.strictEqual(res.body.some((note: any) => note.id === bobNote2.id), true);
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const relativeFetch = async (path: string, init?: RequestInit | undefined
return await fetch(new URL(path, `http://127.0.0.1:${port}/`).toString(), init);
};

function randomString(chars = 'abcdefghijklmnopqrstuvwxyz0123456789', length = 16) {
export function randomString(chars = 'abcdefghijklmnopqrstuvwxyz0123456789', length = 16) {
let randomString = '';
for (let i = 0; i < length; i++) {
randomString += chars[Math.floor(Math.random() * chars.length)];
Expand Down

0 comments on commit 610b68c

Please sign in to comment.