summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2019-01-22 18:30:49 +0900
committersyuilo <syuilotan@yahoo.co.jp>2019-01-22 18:30:49 +0900
commit26c327145f84b30c96a4ca128a2296ab8b9a6f7e (patch)
tree0211b6b9604a216a2befc00105ab4592eb4726cd /test
parentUpdate @types/koa-router requirement from 7.0.35 to 7.0.38 (#3951) (diff)
downloadmisskey-26c327145f84b30c96a4ca128a2296ab8b9a6f7e.tar.gz
misskey-26c327145f84b30c96a4ca128a2296ab8b9a6f7e.tar.bz2
misskey-26c327145f84b30c96a4ca128a2296ab8b9a6f7e.zip
[Test] Add streaming test
#3955
Diffstat (limited to 'test')
-rw-r--r--test/api.ts43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/api.ts b/test/api.ts
index d82014e754..d87380a1d7 100644
--- a/test/api.ts
+++ b/test/api.ts
@@ -1,10 +1,17 @@
/*
* Tests of API
+ *
+ * How to run the tests:
+ * > mocha test/api.ts --require ts-node/register
+ *
+ * To specify test:
+ * > mocha test/api.ts --require ts-node/register -g 'test name'
*/
import * as http from 'http';
import * as fs from 'fs';
import * as assert from 'chai';
+import * as WebSocket from 'ws';
assert.use(require('chai-http'));
const expect = assert.expect;
@@ -20,6 +27,7 @@ process.on('unhandledRejection', console.dir);
//#endregion
const app = require('../built/server/api').default;
+require('../built/server').default();
const db = require('../built/db/mongodb').default;
const server = http.createServer(app.callback());
@@ -1231,4 +1239,39 @@ describe('API', () => {
expect(res).have.status(400);
}));
});
+
+ describe('streaming', () => {
+ it('投稿がタイムラインに流れる', done => {
+ const post = {
+ text: 'foo'
+ };
+
+ signup().then(me => {
+ const ws = new WebSocket(`ws://localhost/streaming?i=${me.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 == 'note') {
+ expect(msg.body.body.text).eql(post.text);
+ done();
+ }
+ } else if (msg.type == 'connected' && msg.body.id == 'a') {
+ request('/notes/create', post, me);
+ }
+ });
+
+ ws.send(JSON.stringify({
+ type: 'connect',
+ body: {
+ channel: 'homeTimeline',
+ id: 'a',
+ pong: true
+ }
+ }));
+ });
+ });
+ });
+ });
});