2019-04-07 12:50:36 +00:00
|
|
|
process.env.NODE_ENV = 'test';
|
|
|
|
|
2019-01-25 10:37:45 +00:00
|
|
|
import * as assert from 'assert';
|
2019-04-07 12:50:36 +00:00
|
|
|
import * as childProcess from 'child_process';
|
2022-02-27 02:07:39 +00:00
|
|
|
import { Following } from '../src/models/entities/following.js';
|
2022-05-21 13:21:41 +00:00
|
|
|
import { connectStream, signup, request, post, startServer, shutdownServer, initTestDb } from './utils.js';
|
2019-01-23 03:15:27 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
describe('Streaming', () => {
|
|
|
|
let p: childProcess.ChildProcess;
|
|
|
|
let Followings: any;
|
2019-01-23 03:15:27 +00:00
|
|
|
|
2021-06-12 13:40:17 +00:00
|
|
|
beforeEach(async () => {
|
|
|
|
p = await startServer();
|
|
|
|
const connection = await initTestDb(true);
|
2020-01-09 05:35:04 +00:00
|
|
|
Followings = connection.getRepository(Following);
|
2021-06-12 13:40:17 +00:00
|
|
|
});
|
2019-01-23 03:15:27 +00:00
|
|
|
|
2021-06-12 13:40:17 +00:00
|
|
|
afterEach(async () => {
|
|
|
|
await shutdownServer(p);
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
2019-01-23 03:15:27 +00:00
|
|
|
|
2019-04-18 05:29:17 +00:00
|
|
|
const follow = async (follower: any, followee: any) => {
|
2019-04-07 12:50:36 +00:00
|
|
|
await Followings.save({
|
|
|
|
id: 'a',
|
|
|
|
createdAt: new Date(),
|
|
|
|
followerId: follower.id,
|
|
|
|
followeeId: followee.id,
|
|
|
|
followerHost: follower.host,
|
|
|
|
followerInbox: null,
|
|
|
|
followerSharedInbox: null,
|
|
|
|
followeeHost: followee.host,
|
|
|
|
followeeInbox: null,
|
2022-05-21 13:21:41 +00:00
|
|
|
followeeSharedInbox: null,
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
};
|
2019-01-23 03:15:27 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
it('mention event', () => new Promise(async done => {
|
|
|
|
const alice = await signup({ username: 'alice' });
|
|
|
|
const bob = await signup({ username: 'bob' });
|
2019-01-23 03:15:27 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
const ws = await connectStream(bob, 'main', ({ type, body }) => {
|
|
|
|
if (type == 'mention') {
|
|
|
|
assert.deepStrictEqual(body.userId, alice.id);
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
2019-01-23 03:15:27 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
post(alice, {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: 'foo @bob bar',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('renote event', () => new Promise(async done => {
|
|
|
|
const alice = await signup({ username: 'alice' });
|
|
|
|
const bob = await signup({ username: 'bob' });
|
|
|
|
const bobNote = await post(bob, {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: 'foo',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const ws = await connectStream(bob, 'main', ({ type, body }) => {
|
|
|
|
if (type == 'renote') {
|
|
|
|
assert.deepStrictEqual(body.renoteId, bobNote.id);
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
post(alice, {
|
2022-05-21 13:21:41 +00:00
|
|
|
renoteId: bobNote.id,
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('Home Timeline', () => {
|
|
|
|
it('自分の投稿が流れる', () => new Promise(async done => {
|
|
|
|
const post = {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: 'foo',
|
2019-04-07 12:50:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const me = await signup();
|
|
|
|
|
|
|
|
const ws = await connectStream(me, 'homeTimeline', ({ type, body }) => {
|
|
|
|
if (type == 'note') {
|
|
|
|
assert.deepStrictEqual(body.text, post.text);
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
request('/notes/create', post, me);
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('フォローしているユーザーの投稿が流れる', () => new Promise(async done => {
|
|
|
|
const alice = await signup({ username: 'alice' });
|
|
|
|
const bob = await signup({ username: 'bob' });
|
|
|
|
|
|
|
|
// Alice が Bob をフォロー
|
|
|
|
await request('/following/create', {
|
2022-05-21 13:21:41 +00:00
|
|
|
userId: bob.id,
|
2019-04-07 12:50:36 +00:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
const ws = await connectStream(alice, 'homeTimeline', ({ type, body }) => {
|
|
|
|
if (type == 'note') {
|
|
|
|
assert.deepStrictEqual(body.userId, bob.id);
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
post(bob, {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: 'foo',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('フォローしていないユーザーの投稿は流れない', () => new Promise(async done => {
|
|
|
|
const alice = await signup({ username: 'alice' });
|
|
|
|
const bob = await signup({ username: 'bob' });
|
|
|
|
|
|
|
|
let fired = false;
|
|
|
|
|
|
|
|
const ws = await connectStream(alice, 'homeTimeline', ({ type, body }) => {
|
|
|
|
if (type == 'note') {
|
|
|
|
fired = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
post(bob, {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: 'foo',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
assert.strictEqual(fired, false);
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}, 3000);
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('フォローしているユーザーのダイレクト投稿が流れる', () => new Promise(async done => {
|
|
|
|
const alice = await signup({ username: 'alice' });
|
|
|
|
const bob = await signup({ username: 'bob' });
|
|
|
|
|
|
|
|
// Alice が Bob をフォロー
|
|
|
|
await request('/following/create', {
|
2022-05-21 13:21:41 +00:00
|
|
|
userId: bob.id,
|
2019-04-07 12:50:36 +00:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
const ws = await connectStream(alice, 'homeTimeline', ({ type, body }) => {
|
|
|
|
if (type == 'note') {
|
|
|
|
assert.deepStrictEqual(body.userId, bob.id);
|
|
|
|
assert.deepStrictEqual(body.text, 'foo');
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Bob が Alice 宛てのダイレクト投稿
|
|
|
|
post(bob, {
|
|
|
|
text: 'foo',
|
|
|
|
visibility: 'specified',
|
2022-05-21 13:21:41 +00:00
|
|
|
visibleUserIds: [alice.id],
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('フォローしているユーザーでも自分が指定されていないダイレクト投稿は流れない', () => new Promise(async done => {
|
|
|
|
const alice = await signup({ username: 'alice' });
|
|
|
|
const bob = await signup({ username: 'bob' });
|
|
|
|
const carol = await signup({ username: 'carol' });
|
|
|
|
|
|
|
|
// Alice が Bob をフォロー
|
|
|
|
await request('/following/create', {
|
2022-05-21 13:21:41 +00:00
|
|
|
userId: bob.id,
|
2019-04-07 12:50:36 +00:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
let fired = false;
|
|
|
|
|
|
|
|
const ws = await connectStream(alice, 'homeTimeline', ({ type, body }) => {
|
|
|
|
if (type == 'note') {
|
|
|
|
fired = true;
|
|
|
|
}
|
|
|
|
});
|
2019-01-23 03:15:27 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
// Bob が Carol 宛てのダイレクト投稿
|
|
|
|
post(bob, {
|
|
|
|
text: 'foo',
|
|
|
|
visibility: 'specified',
|
2022-05-21 13:21:41 +00:00
|
|
|
visibleUserIds: [carol.id],
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
assert.strictEqual(fired, false);
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}, 3000);
|
|
|
|
}));
|
2019-01-23 04:35:22 +00:00
|
|
|
});
|
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
describe('Local Timeline', () => {
|
|
|
|
it('自分の投稿が流れる', () => new Promise(async done => {
|
|
|
|
const me = await signup();
|
|
|
|
|
|
|
|
const ws = await connectStream(me, 'localTimeline', ({ type, body }) => {
|
|
|
|
if (type == 'note') {
|
|
|
|
assert.deepStrictEqual(body.userId, me.id);
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
post(me, {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: 'foo',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
}));
|
2019-01-23 03:15:27 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
it('フォローしていないローカルユーザーの投稿が流れる', () => new Promise(async done => {
|
|
|
|
const alice = await signup({ username: 'alice' });
|
|
|
|
const bob = await signup({ username: 'bob' });
|
2019-01-23 03:15:27 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
const ws = await connectStream(alice, 'localTimeline', ({ type, body }) => {
|
|
|
|
if (type == 'note') {
|
|
|
|
assert.deepStrictEqual(body.userId, bob.id);
|
|
|
|
ws.close();
|
|
|
|
done();
|
2019-01-25 06:56:49 +00:00
|
|
|
}
|
2019-01-23 03:15:27 +00:00
|
|
|
});
|
2019-01-25 06:56:49 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
post(bob, {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: 'foo',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('リモートユーザーの投稿は流れない', () => new Promise(async done => {
|
|
|
|
const alice = await signup({ username: 'alice' });
|
|
|
|
const bob = await signup({ username: 'bob', host: 'example.com' });
|
|
|
|
|
|
|
|
let fired = false;
|
|
|
|
|
|
|
|
const ws = await connectStream(alice, 'localTimeline', ({ type, body }) => {
|
|
|
|
if (type == 'note') {
|
|
|
|
fired = true;
|
2019-01-25 06:56:49 +00:00
|
|
|
}
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
2019-01-25 07:14:09 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
post(bob, {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: 'foo',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
2019-01-25 07:14:09 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
assert.strictEqual(fired, false);
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}, 3000);
|
|
|
|
}));
|
2019-01-25 07:14:09 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
it('フォローしてたとしてもリモートユーザーの投稿は流れない', () => new Promise(async done => {
|
|
|
|
const alice = await signup({ username: 'alice' });
|
|
|
|
const bob = await signup({ username: 'bob', host: 'example.com' });
|
|
|
|
|
|
|
|
// Alice が Bob をフォロー
|
|
|
|
await request('/following/create', {
|
2022-05-21 13:21:41 +00:00
|
|
|
userId: bob.id,
|
2019-04-07 12:50:36 +00:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
let fired = false;
|
|
|
|
|
|
|
|
const ws = await connectStream(alice, 'localTimeline', ({ type, body }) => {
|
|
|
|
if (type == 'note') {
|
|
|
|
fired = true;
|
2019-01-25 07:14:09 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
post(bob, {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: 'foo',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
assert.strictEqual(fired, false);
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}, 3000);
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('ホーム指定の投稿は流れない', () => new Promise(async done => {
|
|
|
|
const alice = await signup({ username: 'alice' });
|
|
|
|
const bob = await signup({ username: 'bob' });
|
|
|
|
|
|
|
|
let fired = false;
|
|
|
|
|
|
|
|
const ws = await connectStream(alice, 'localTimeline', ({ type, body }) => {
|
|
|
|
if (type == 'note') {
|
|
|
|
fired = true;
|
2019-01-25 07:14:09 +00:00
|
|
|
}
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
2019-01-25 07:14:09 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
// ホーム指定
|
|
|
|
post(bob, {
|
|
|
|
text: 'foo',
|
2022-05-21 13:21:41 +00:00
|
|
|
visibility: 'home',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
assert.strictEqual(fired, false);
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}, 3000);
|
|
|
|
}));
|
|
|
|
|
2020-01-09 08:29:03 +00:00
|
|
|
it('フォローしているローカルユーザーのダイレクト投稿は流れない', () => new Promise(async done => {
|
2019-04-07 12:50:36 +00:00
|
|
|
const alice = await signup({ username: 'alice' });
|
|
|
|
const bob = await signup({ username: 'bob' });
|
2019-01-25 07:14:09 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
// Alice が Bob をフォロー
|
|
|
|
await request('/following/create', {
|
2022-05-21 13:21:41 +00:00
|
|
|
userId: bob.id,
|
2019-04-07 12:50:36 +00:00
|
|
|
}, alice);
|
2019-01-25 07:14:09 +00:00
|
|
|
|
2020-01-09 08:29:03 +00:00
|
|
|
let fired = false;
|
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
const ws = await connectStream(alice, 'localTimeline', ({ type, body }) => {
|
|
|
|
if (type == 'note') {
|
2020-01-09 08:29:03 +00:00
|
|
|
fired = true;
|
2019-01-25 07:14:09 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
// Bob が Alice 宛てのダイレクト投稿
|
|
|
|
post(bob, {
|
|
|
|
text: 'foo',
|
|
|
|
visibility: 'specified',
|
2022-05-21 13:21:41 +00:00
|
|
|
visibleUserIds: [alice.id],
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
2020-01-09 08:29:03 +00:00
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
assert.strictEqual(fired, false);
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}, 3000);
|
2019-04-07 12:50:36 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
it('フォローしていないローカルユーザーのフォロワー宛て投稿は流れない', () => new Promise(async done => {
|
|
|
|
const alice = await signup({ username: 'alice' });
|
|
|
|
const bob = await signup({ username: 'bob' });
|
|
|
|
|
|
|
|
let fired = false;
|
|
|
|
|
|
|
|
const ws = await connectStream(alice, 'localTimeline', ({ type, body }) => {
|
|
|
|
if (type == 'note') {
|
|
|
|
fired = true;
|
2019-01-25 07:14:09 +00:00
|
|
|
}
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// フォロワー宛て投稿
|
|
|
|
post(bob, {
|
|
|
|
text: 'foo',
|
2022-05-21 13:21:41 +00:00
|
|
|
visibility: 'followers',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
assert.strictEqual(fired, false);
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}, 3000);
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
2019-04-08 14:05:41 +00:00
|
|
|
describe('Hybrid Timeline', () => {
|
2019-04-07 12:50:36 +00:00
|
|
|
it('自分の投稿が流れる', () => new Promise(async done => {
|
|
|
|
const me = await signup();
|
|
|
|
|
2019-04-08 14:05:41 +00:00
|
|
|
const ws = await connectStream(me, 'hybridTimeline', ({ type, body }) => {
|
2019-04-07 12:50:36 +00:00
|
|
|
if (type == 'note') {
|
|
|
|
assert.deepStrictEqual(body.userId, me.id);
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
post(me, {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: 'foo',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('フォローしていないローカルユーザーの投稿が流れる', () => new Promise(async done => {
|
|
|
|
const alice = await signup({ username: 'alice' });
|
|
|
|
const bob = await signup({ username: 'bob' });
|
|
|
|
|
2019-04-08 14:05:41 +00:00
|
|
|
const ws = await connectStream(alice, 'hybridTimeline', ({ type, body }) => {
|
2019-04-07 12:50:36 +00:00
|
|
|
if (type == 'note') {
|
|
|
|
assert.deepStrictEqual(body.userId, bob.id);
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
post(bob, {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: 'foo',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('フォローしているリモートユーザーの投稿が流れる', () => new Promise(async done => {
|
|
|
|
const alice = await signup({ username: 'alice' });
|
|
|
|
const bob = await signup({ username: 'bob', host: 'example.com' });
|
|
|
|
|
|
|
|
// Alice が Bob をフォロー
|
|
|
|
await follow(alice, bob);
|
|
|
|
|
2019-04-08 14:05:41 +00:00
|
|
|
const ws = await connectStream(alice, 'hybridTimeline', ({ type, body }) => {
|
2019-04-07 12:50:36 +00:00
|
|
|
if (type == 'note') {
|
|
|
|
assert.deepStrictEqual(body.userId, bob.id);
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
post(bob, {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: 'foo',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('フォローしていないリモートユーザーの投稿は流れない', () => new Promise(async done => {
|
|
|
|
const alice = await signup({ username: 'alice' });
|
|
|
|
const bob = await signup({ username: 'bob', host: 'example.com' });
|
|
|
|
|
|
|
|
let fired = false;
|
|
|
|
|
2019-04-08 14:05:41 +00:00
|
|
|
const ws = await connectStream(alice, 'hybridTimeline', ({ type, body }) => {
|
2019-04-07 12:50:36 +00:00
|
|
|
if (type == 'note') {
|
|
|
|
fired = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
post(bob, {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: 'foo',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
assert.strictEqual(fired, false);
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}, 3000);
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('フォローしているユーザーのダイレクト投稿が流れる', () => new Promise(async done => {
|
|
|
|
const alice = await signup({ username: 'alice' });
|
|
|
|
const bob = await signup({ username: 'bob' });
|
|
|
|
|
|
|
|
// Alice が Bob をフォロー
|
|
|
|
await request('/following/create', {
|
2022-05-21 13:21:41 +00:00
|
|
|
userId: bob.id,
|
2019-04-07 12:50:36 +00:00
|
|
|
}, alice);
|
|
|
|
|
2019-04-08 14:05:41 +00:00
|
|
|
const ws = await connectStream(alice, 'hybridTimeline', ({ type, body }) => {
|
2019-04-07 12:50:36 +00:00
|
|
|
if (type == 'note') {
|
|
|
|
assert.deepStrictEqual(body.userId, bob.id);
|
|
|
|
assert.deepStrictEqual(body.text, 'foo');
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Bob が Alice 宛てのダイレクト投稿
|
|
|
|
post(bob, {
|
|
|
|
text: 'foo',
|
|
|
|
visibility: 'specified',
|
2022-05-21 13:21:41 +00:00
|
|
|
visibleUserIds: [alice.id],
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2019-04-18 05:39:49 +00:00
|
|
|
it('フォローしているユーザーのホーム投稿が流れる', () => new Promise(async done => {
|
|
|
|
const alice = await signup({ username: 'alice' });
|
|
|
|
const bob = await signup({ username: 'bob' });
|
|
|
|
|
|
|
|
// Alice が Bob をフォロー
|
|
|
|
await request('/following/create', {
|
2022-05-21 13:21:41 +00:00
|
|
|
userId: bob.id,
|
2019-04-18 05:39:49 +00:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
const ws = await connectStream(alice, 'hybridTimeline', ({ type, body }) => {
|
|
|
|
if (type == 'note') {
|
|
|
|
assert.deepStrictEqual(body.userId, bob.id);
|
|
|
|
assert.deepStrictEqual(body.text, 'foo');
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// ホーム投稿
|
|
|
|
post(bob, {
|
|
|
|
text: 'foo',
|
2022-05-21 13:21:41 +00:00
|
|
|
visibility: 'home',
|
2019-04-18 05:39:49 +00:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2019-04-18 05:34:47 +00:00
|
|
|
it('フォローしていないローカルユーザーのホーム投稿は流れない', () => new Promise(async done => {
|
|
|
|
const alice = await signup({ username: 'alice' });
|
|
|
|
const bob = await signup({ username: 'bob' });
|
|
|
|
|
|
|
|
let fired = false;
|
|
|
|
|
|
|
|
const ws = await connectStream(alice, 'hybridTimeline', ({ type, body }) => {
|
|
|
|
if (type == 'note') {
|
|
|
|
fired = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// ホーム投稿
|
|
|
|
post(bob, {
|
|
|
|
text: 'foo',
|
2022-05-21 13:21:41 +00:00
|
|
|
visibility: 'home',
|
2019-04-18 05:34:47 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
assert.strictEqual(fired, false);
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}, 3000);
|
|
|
|
}));
|
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
it('フォローしていないローカルユーザーのフォロワー宛て投稿は流れない', () => new Promise(async done => {
|
|
|
|
const alice = await signup({ username: 'alice' });
|
|
|
|
const bob = await signup({ username: 'bob' });
|
|
|
|
|
|
|
|
let fired = false;
|
|
|
|
|
2019-04-08 14:05:41 +00:00
|
|
|
const ws = await connectStream(alice, 'hybridTimeline', ({ type, body }) => {
|
2019-04-07 12:50:36 +00:00
|
|
|
if (type == 'note') {
|
|
|
|
fired = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// フォロワー宛て投稿
|
|
|
|
post(bob, {
|
|
|
|
text: 'foo',
|
2022-05-21 13:21:41 +00:00
|
|
|
visibility: 'followers',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
assert.strictEqual(fired, false);
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}, 3000);
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Global Timeline', () => {
|
|
|
|
it('フォローしていないローカルユーザーの投稿が流れる', () => new Promise(async done => {
|
|
|
|
const alice = await signup({ username: 'alice' });
|
|
|
|
const bob = await signup({ username: 'bob' });
|
|
|
|
|
|
|
|
const ws = await connectStream(alice, 'globalTimeline', ({ type, body }) => {
|
|
|
|
if (type == 'note') {
|
|
|
|
assert.deepStrictEqual(body.userId, bob.id);
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
post(bob, {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: 'foo',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('フォローしていないリモートユーザーの投稿が流れる', () => new Promise(async done => {
|
|
|
|
const alice = await signup({ username: 'alice' });
|
|
|
|
const bob = await signup({ username: 'bob', host: 'example.com' });
|
|
|
|
|
|
|
|
const ws = await connectStream(alice, 'globalTimeline', ({ type, body }) => {
|
|
|
|
if (type == 'note') {
|
|
|
|
assert.deepStrictEqual(body.userId, bob.id);
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
post(bob, {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: 'foo',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
}));
|
2019-04-22 17:50:59 +00:00
|
|
|
|
|
|
|
it('ホーム投稿は流れない', () => new Promise(async done => {
|
|
|
|
const alice = await signup({ username: 'alice' });
|
|
|
|
const bob = await signup({ username: 'bob' });
|
|
|
|
|
|
|
|
let fired = false;
|
|
|
|
|
|
|
|
const ws = await connectStream(alice, 'globalTimeline', ({ type, body }) => {
|
|
|
|
if (type == 'note') {
|
|
|
|
fired = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// ホーム投稿
|
|
|
|
post(bob, {
|
|
|
|
text: 'foo',
|
2022-05-21 13:21:41 +00:00
|
|
|
visibility: 'home',
|
2019-04-22 17:50:59 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
assert.strictEqual(fired, false);
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}, 3000);
|
|
|
|
}));
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('UserList Timeline', () => {
|
|
|
|
it('リストに入れているユーザーの投稿が流れる', () => new Promise(async done => {
|
|
|
|
const alice = await signup({ username: 'alice' });
|
|
|
|
const bob = await signup({ username: 'bob' });
|
|
|
|
|
|
|
|
// リスト作成
|
|
|
|
const list = await request('/users/lists/create', {
|
2022-05-21 13:21:41 +00:00
|
|
|
name: 'my list',
|
2019-04-07 12:50:36 +00:00
|
|
|
}, alice).then(x => x.body);
|
|
|
|
|
|
|
|
// Alice が Bob をリスイン
|
|
|
|
await request('/users/lists/push', {
|
|
|
|
listId: list.id,
|
2022-05-21 13:21:41 +00:00
|
|
|
userId: bob.id,
|
2019-04-07 12:50:36 +00:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
const ws = await connectStream(alice, 'userList', ({ type, body }) => {
|
|
|
|
if (type == 'note') {
|
|
|
|
assert.deepStrictEqual(body.userId, bob.id);
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
}, {
|
2022-05-21 13:21:41 +00:00
|
|
|
listId: list.id,
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
post(bob, {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: 'foo',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('リストに入れていないユーザーの投稿は流れない', () => new Promise(async done => {
|
|
|
|
const alice = await signup({ username: 'alice' });
|
|
|
|
const bob = await signup({ username: 'bob' });
|
|
|
|
|
|
|
|
// リスト作成
|
|
|
|
const list = await request('/users/lists/create', {
|
2022-05-21 13:21:41 +00:00
|
|
|
name: 'my list',
|
2019-04-07 12:50:36 +00:00
|
|
|
}, alice).then(x => x.body);
|
|
|
|
|
|
|
|
let fired = false;
|
|
|
|
|
|
|
|
const ws = await connectStream(alice, 'userList', ({ type, body }) => {
|
|
|
|
if (type == 'note') {
|
|
|
|
fired = true;
|
|
|
|
}
|
|
|
|
}, {
|
2022-05-21 13:21:41 +00:00
|
|
|
listId: list.id,
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
post(bob, {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: 'foo',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
assert.strictEqual(fired, false);
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}, 3000);
|
|
|
|
}));
|
|
|
|
|
|
|
|
// #4471
|
|
|
|
it('リストに入れているユーザーのダイレクト投稿が流れる', () => new Promise(async done => {
|
|
|
|
const alice = await signup({ username: 'alice' });
|
|
|
|
const bob = await signup({ username: 'bob' });
|
|
|
|
|
|
|
|
// リスト作成
|
|
|
|
const list = await request('/users/lists/create', {
|
2022-05-21 13:21:41 +00:00
|
|
|
name: 'my list',
|
2019-04-07 12:50:36 +00:00
|
|
|
}, alice).then(x => x.body);
|
|
|
|
|
|
|
|
// Alice が Bob をリスイン
|
|
|
|
await request('/users/lists/push', {
|
|
|
|
listId: list.id,
|
2022-05-21 13:21:41 +00:00
|
|
|
userId: bob.id,
|
2019-04-07 12:50:36 +00:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
const ws = await connectStream(alice, 'userList', ({ type, body }) => {
|
|
|
|
if (type == 'note') {
|
|
|
|
assert.deepStrictEqual(body.userId, bob.id);
|
|
|
|
assert.deepStrictEqual(body.text, 'foo');
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
}, {
|
2022-05-21 13:21:41 +00:00
|
|
|
listId: list.id,
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Bob が Alice 宛てのダイレクト投稿
|
|
|
|
post(bob, {
|
|
|
|
text: 'foo',
|
|
|
|
visibility: 'specified',
|
2022-05-21 13:21:41 +00:00
|
|
|
visibleUserIds: [alice.id],
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
// #4335
|
|
|
|
it('リストに入れているがフォローはしてないユーザーのフォロワー宛て投稿は流れない', () => new Promise(async done => {
|
|
|
|
const alice = await signup({ username: 'alice' });
|
|
|
|
const bob = await signup({ username: 'bob' });
|
|
|
|
|
|
|
|
// リスト作成
|
|
|
|
const list = await request('/users/lists/create', {
|
2022-05-21 13:21:41 +00:00
|
|
|
name: 'my list',
|
2019-04-07 12:50:36 +00:00
|
|
|
}, alice).then(x => x.body);
|
|
|
|
|
|
|
|
// Alice が Bob をリスイン
|
|
|
|
await request('/users/lists/push', {
|
|
|
|
listId: list.id,
|
2022-05-21 13:21:41 +00:00
|
|
|
userId: bob.id,
|
2019-04-07 12:50:36 +00:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
let fired = false;
|
|
|
|
|
|
|
|
const ws = await connectStream(alice, 'userList', ({ type, body }) => {
|
|
|
|
if (type == 'note') {
|
|
|
|
fired = true;
|
|
|
|
}
|
|
|
|
}, {
|
2022-05-21 13:21:41 +00:00
|
|
|
listId: list.id,
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// フォロワー宛て投稿
|
|
|
|
post(bob, {
|
|
|
|
text: 'foo',
|
2022-05-21 13:21:41 +00:00
|
|
|
visibility: 'followers',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
assert.strictEqual(fired, false);
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}, 3000);
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Hashtag Timeline', () => {
|
|
|
|
it('指定したハッシュタグの投稿が流れる', () => new Promise(async done => {
|
|
|
|
const me = await signup();
|
|
|
|
|
|
|
|
const ws = await connectStream(me, 'hashtag', ({ type, body }) => {
|
|
|
|
if (type == 'note') {
|
|
|
|
assert.deepStrictEqual(body.text, '#foo');
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
q: [
|
2022-05-21 13:21:41 +00:00
|
|
|
['foo'],
|
|
|
|
],
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
post(me, {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: '#foo',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('指定したハッシュタグの投稿が流れる (AND)', () => new Promise(async done => {
|
|
|
|
const me = await signup();
|
|
|
|
|
|
|
|
let fooCount = 0;
|
|
|
|
let barCount = 0;
|
|
|
|
let fooBarCount = 0;
|
|
|
|
|
|
|
|
const ws = await connectStream(me, 'hashtag', ({ type, body }) => {
|
|
|
|
if (type == 'note') {
|
|
|
|
if (body.text === '#foo') fooCount++;
|
|
|
|
if (body.text === '#bar') barCount++;
|
|
|
|
if (body.text === '#foo #bar') fooBarCount++;
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
q: [
|
2022-05-21 13:21:41 +00:00
|
|
|
['foo', 'bar'],
|
|
|
|
],
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
post(me, {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: '#foo',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
post(me, {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: '#bar',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
post(me, {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: '#foo #bar',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
assert.strictEqual(fooCount, 0);
|
|
|
|
assert.strictEqual(barCount, 0);
|
|
|
|
assert.strictEqual(fooBarCount, 1);
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}, 3000);
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('指定したハッシュタグの投稿が流れる (OR)', () => new Promise(async done => {
|
|
|
|
const me = await signup();
|
|
|
|
|
|
|
|
let fooCount = 0;
|
|
|
|
let barCount = 0;
|
|
|
|
let fooBarCount = 0;
|
|
|
|
let piyoCount = 0;
|
|
|
|
|
|
|
|
const ws = await connectStream(me, 'hashtag', ({ type, body }) => {
|
|
|
|
if (type == 'note') {
|
|
|
|
if (body.text === '#foo') fooCount++;
|
|
|
|
if (body.text === '#bar') barCount++;
|
|
|
|
if (body.text === '#foo #bar') fooBarCount++;
|
|
|
|
if (body.text === '#piyo') piyoCount++;
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
q: [
|
|
|
|
['foo'],
|
2022-05-21 13:21:41 +00:00
|
|
|
['bar'],
|
|
|
|
],
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
post(me, {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: '#foo',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
post(me, {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: '#bar',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
post(me, {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: '#foo #bar',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
post(me, {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: '#piyo',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
assert.strictEqual(fooCount, 1);
|
|
|
|
assert.strictEqual(barCount, 1);
|
|
|
|
assert.strictEqual(fooBarCount, 1);
|
|
|
|
assert.strictEqual(piyoCount, 0);
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}, 3000);
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('指定したハッシュタグの投稿が流れる (AND + OR)', () => new Promise(async done => {
|
|
|
|
const me = await signup();
|
|
|
|
|
|
|
|
let fooCount = 0;
|
|
|
|
let barCount = 0;
|
|
|
|
let fooBarCount = 0;
|
|
|
|
let piyoCount = 0;
|
|
|
|
let waaaCount = 0;
|
|
|
|
|
|
|
|
const ws = await connectStream(me, 'hashtag', ({ type, body }) => {
|
|
|
|
if (type == 'note') {
|
|
|
|
if (body.text === '#foo') fooCount++;
|
|
|
|
if (body.text === '#bar') barCount++;
|
|
|
|
if (body.text === '#foo #bar') fooBarCount++;
|
|
|
|
if (body.text === '#piyo') piyoCount++;
|
|
|
|
if (body.text === '#waaa') waaaCount++;
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
q: [
|
|
|
|
['foo', 'bar'],
|
2022-05-21 13:21:41 +00:00
|
|
|
['piyo'],
|
|
|
|
],
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
post(me, {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: '#foo',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
post(me, {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: '#bar',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
post(me, {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: '#foo #bar',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
post(me, {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: '#piyo',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
post(me, {
|
2022-05-21 13:21:41 +00:00
|
|
|
text: '#waaa',
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
assert.strictEqual(fooCount, 0);
|
|
|
|
assert.strictEqual(barCount, 0);
|
|
|
|
assert.strictEqual(fooBarCount, 1);
|
|
|
|
assert.strictEqual(piyoCount, 1);
|
|
|
|
assert.strictEqual(waaaCount, 0);
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}, 3000);
|
|
|
|
}));
|
|
|
|
});
|
2019-01-23 03:15:27 +00:00
|
|
|
});
|