mirror of
https://activitypub.software/TransFem-org/Sharkey
synced 2024-12-04 11:47:27 +00:00
add test
This commit is contained in:
parent
99276028ae
commit
a385bd0227
1 changed files with 37 additions and 1 deletions
|
@ -2,7 +2,7 @@ import WS from 'jest-websocket-mock';
|
||||||
import Stream from '../src/streaming';
|
import Stream from '../src/streaming';
|
||||||
|
|
||||||
describe('Streaming', () => {
|
describe('Streaming', () => {
|
||||||
test('success', async () => {
|
test('useSharedConnection', async () => {
|
||||||
const server = new WS('wss://misskey.test/streaming');
|
const server = new WS('wss://misskey.test/streaming');
|
||||||
const stream = new Stream('https://misskey.test', { token: 'TOKEN' });
|
const stream = new Stream('https://misskey.test', { token: 'TOKEN' });
|
||||||
const mainChannelReceived: any[] = [];
|
const mainChannelReceived: any[] = [];
|
||||||
|
@ -31,5 +31,41 @@ describe('Streaming', () => {
|
||||||
expect(mainChannelReceived[0]).toEqual({
|
expect(mainChannelReceived[0]).toEqual({
|
||||||
id: 'foo'
|
id: 'foo'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
server.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('SharedConnection#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.useSharedConnection('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);
|
||||||
|
|
||||||
|
server.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO: SharedConnection#dispose して一定時間経ったら disconnect メッセージがサーバーに送られてくるかのテスト
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue