summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2019-01-25 16:14:09 +0900
committersyuilo <syuilotan@yahoo.co.jp>2019-01-25 16:14:09 +0900
commit501379c82cbc93b2aa195aff7798271dfb0a879d (patch)
treeecfbf608cd2f2bc014b55e0c39bec99ffd7475dd
parentRefactoring (diff)
downloadmisskey-501379c82cbc93b2aa195aff7798271dfb0a879d.tar.gz
misskey-501379c82cbc93b2aa195aff7798271dfb0a879d.tar.bz2
misskey-501379c82cbc93b2aa195aff7798271dfb0a879d.zip
[Test] Add sone streaming tests
-rw-r--r--test/streaming.ts72
1 files changed, 71 insertions, 1 deletions
diff --git a/test/streaming.ts b/test/streaming.ts
index 6186e348a7..19cae8c9c0 100644
--- a/test/streaming.ts
+++ b/test/streaming.ts
@@ -35,6 +35,7 @@ const apiServer = http.createServer(app.callback());
//#region Utilities
const request = _request(apiServer);
const signup = _signup(request);
+const post = _post(request);
//#endregion
describe('Streaming', () => {
@@ -51,7 +52,6 @@ describe('Streaming', () => {
};
const me = await signup();
-
const ws = new WebSocket(`ws://localhost/streaming?i=${me.token}`);
ws.on('open', () => {
@@ -78,4 +78,74 @@ describe('Streaming', () => {
}));
});
}));
+
+ it('mention event', () => new Promise(async done => {
+ const alice = await signup({ username: 'alice' });
+ const bob = await signup({ username: 'bob' });
+ const aliceNote = {
+ text: 'foo @bob bar'
+ };
+
+ const ws = new WebSocket(`ws://localhost/streaming?i=${bob.token}`);
+
+ ws.on('open', () => {
+ ws.on('message', data => {
+ const msg = JSON.parse(data.toString());
+ if (msg.type == 'channel' && msg.body.id == 'a') {
+ if (msg.body.type == 'mention') {
+ expect(msg.body.body.text).eql(aliceNote.text);
+ ws.close();
+ done();
+ }
+ } else if (msg.type == 'connected' && msg.body.id == 'a') {
+ request('/notes/create', aliceNote, alice);
+ }
+ });
+
+ ws.send(JSON.stringify({
+ type: 'connect',
+ body: {
+ channel: 'main',
+ id: 'a',
+ pong: true
+ }
+ }));
+ });
+ }));
+
+ it('renote event', () => new Promise(async done => {
+ const alice = await signup({ username: 'alice' });
+ const bob = await signup({ username: 'bob' });
+ const bobNote = await post(bob, {
+ text: 'foo'
+ });
+
+ const ws = new WebSocket(`ws://localhost/streaming?i=${bob.token}`);
+
+ ws.on('open', () => {
+ ws.on('message', data => {
+ const msg = JSON.parse(data.toString());
+ if (msg.type == 'channel' && msg.body.id == 'a') {
+ if (msg.body.type == 'renote') {
+ expect(msg.body.body.renoteId).eql(bobNote.id);
+ ws.close();
+ done();
+ }
+ } else if (msg.type == 'connected' && msg.body.id == 'a') {
+ request('/notes/create', {
+ renoteId: bobNote.id
+ }, alice);
+ }
+ });
+
+ ws.send(JSON.stringify({
+ type: 'connect',
+ body: {
+ channel: 'main',
+ id: 'a',
+ pong: true
+ }
+ }));
+ });
+ }));
});