mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-23 14:53:07 +02:00
parent
c49ae672f2
commit
26c327145f
1 changed files with 43 additions and 0 deletions
43
test/api.ts
43
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
|
||||
}
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue