Refactoring

This commit is contained in:
syuilo 2019-01-25 15:56:49 +09:00
parent 3330c3f548
commit 92b45d1a9d
No known key found for this signature in database
GPG Key ID: BDC4C49D06AB9D69
1 changed files with 24 additions and 24 deletions

View File

@ -45,37 +45,37 @@ describe('Streaming', () => {
server.close(); server.close();
}); });
it('投稿がタイムラインに流れる', done => { it('投稿がタイムラインに流れる', () => new Promise(async done => {
const post = { const post = {
text: 'foo' text: 'foo'
}; };
signup().then(me => { const me = await signup();
const ws = new WebSocket(`ws://localhost/streaming?i=${me.token}`);
ws.on('open', () => { const ws = new WebSocket(`ws://localhost/streaming?i=${me.token}`);
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);
ws.close();
done();
}
} else if (msg.type == 'connected' && msg.body.id == 'a') {
request('/notes/create', post, me);
}
});
ws.send(JSON.stringify({ ws.on('open', () => {
type: 'connect', ws.on('message', data => {
body: { const msg = JSON.parse(data.toString());
channel: 'homeTimeline', if (msg.type == 'channel' && msg.body.id == 'a') {
id: 'a', if (msg.body.type == 'note') {
pong: true expect(msg.body.body.text).eql(post.text);
ws.close();
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
}
}));
}); });
}); }));
}); });