[Test] Add sone streaming tests

This commit is contained in:
syuilo 2019-01-25 16:14:09 +09:00
parent 92b45d1a9d
commit 501379c82c
No known key found for this signature in database
GPG Key ID: BDC4C49D06AB9D69

View File

@ -35,6 +35,7 @@ const apiServer = http.createServer(app.callback());
//#region Utilities //#region Utilities
const request = _request(apiServer); const request = _request(apiServer);
const signup = _signup(request); const signup = _signup(request);
const post = _post(request);
//#endregion //#endregion
describe('Streaming', () => { describe('Streaming', () => {
@ -51,7 +52,6 @@ describe('Streaming', () => {
}; };
const me = await signup(); const me = await signup();
const ws = new WebSocket(`ws://localhost/streaming?i=${me.token}`); const ws = new WebSocket(`ws://localhost/streaming?i=${me.token}`);
ws.on('open', () => { 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
}
}));
});
}));
}); });