2021-05-16 11:12:18 +02:00
|
|
|
import WS from 'jest-websocket-mock';
|
|
|
|
import Stream from '../src/streaming';
|
|
|
|
|
|
|
|
describe('Streaming', () => {
|
|
|
|
test('success', async () => {
|
|
|
|
const server = new WS('wss://misskey.test/streaming');
|
|
|
|
const stream = new Stream('https://misskey.test', { token: 'TOKEN' });
|
|
|
|
const mainChannelReceived: any[] = [];
|
|
|
|
const main = stream.useSharedConnection('main');
|
2021-05-17 12:50:31 +02:00
|
|
|
main.on('meUpdated', payload => {
|
2021-05-16 11:12:18 +02:00
|
|
|
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,
|
2021-05-17 12:50:31 +02:00
|
|
|
type: 'meUpdated',
|
2021-05-16 11:12:18 +02:00
|
|
|
body: {
|
2021-05-17 12:50:31 +02:00
|
|
|
id: 'foo'
|
2021-05-16 11:12:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
expect(mainChannelReceived[0]).toEqual({
|
2021-05-17 12:50:31 +02:00
|
|
|
id: 'foo'
|
2021-05-16 11:12:18 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|