mirror of
https://github.com/paricafe/misskey.git
synced 2024-11-29 03:06:44 -06:00
80 lines
2 KiB
TypeScript
80 lines
2 KiB
TypeScript
import WS from 'jest-websocket-mock';
|
|
import Stream from '../src/streaming';
|
|
|
|
describe('Streaming', () => {
|
|
test('useChannel', async () => {
|
|
const server = new WS('wss://misskey.test/streaming');
|
|
const stream = new Stream('https://misskey.test', { token: 'TOKEN' });
|
|
const mainChannelReceived: any[] = [];
|
|
const main = stream.useChannel('main');
|
|
main.on('meUpdated', payload => {
|
|
mainChannelReceived.push(payload);
|
|
});
|
|
await server.connected;
|
|
const msg = JSON.parse(await server.nextMessage as string);
|
|
const mainChannelId = msg.body.id;
|
|
expect(msg.type).toEqual('connect');
|
|
expect(msg.body.channel).toEqual('main');
|
|
expect(mainChannelId != null).toEqual(true);
|
|
|
|
server.send(JSON.stringify({
|
|
type: 'channel',
|
|
body: {
|
|
id: mainChannelId,
|
|
type: 'meUpdated',
|
|
body: {
|
|
id: 'foo'
|
|
}
|
|
}
|
|
}));
|
|
|
|
expect(mainChannelReceived[0]).toEqual({
|
|
id: 'foo'
|
|
});
|
|
|
|
stream.close();
|
|
server.close();
|
|
});
|
|
|
|
/* TODO
|
|
test('useChannel with parameters', async () => {
|
|
});
|
|
*/
|
|
|
|
test('Connection#dispose', async () => {
|
|
const server = new WS('wss://misskey.test/streaming');
|
|
const stream = new Stream('https://misskey.test', { token: 'TOKEN' });
|
|
const mainChannelReceived: any[] = [];
|
|
const main = stream.useChannel('main');
|
|
main.on('meUpdated', payload => {
|
|
mainChannelReceived.push(payload);
|
|
});
|
|
await server.connected;
|
|
const msg = JSON.parse(await server.nextMessage as string);
|
|
const mainChannelId = msg.body.id;
|
|
expect(msg.type).toEqual('connect');
|
|
expect(msg.body.channel).toEqual('main');
|
|
expect(mainChannelId != null).toEqual(true);
|
|
main.dispose();
|
|
|
|
server.send(JSON.stringify({
|
|
type: 'channel',
|
|
body: {
|
|
id: mainChannelId,
|
|
type: 'meUpdated',
|
|
body: {
|
|
id: 'foo'
|
|
}
|
|
}
|
|
}));
|
|
|
|
expect(mainChannelReceived.length).toEqual(0);
|
|
|
|
stream.close();
|
|
server.close();
|
|
});
|
|
|
|
// TODO: SharedConnection#dispose して一定時間経ったら disconnect メッセージがサーバーに送られてくるかのテスト
|
|
|
|
// TODO: チャンネル接続が使いまわされるかのテスト
|
|
});
|