summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2021-06-27 21:17:42 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2021-06-27 21:17:42 +0900
commitb6df8cc1f58404b62415f2321ebe12240cd9d48e (patch)
tree530054805622bce007524534a34a8113bfdd8218
parentImprove type (diff)
downloadmisskey-b6df8cc1f58404b62415f2321ebe12240cd9d48e.tar.gz
misskey-b6df8cc1f58404b62415f2321ebe12240cd9d48e.tar.bz2
misskey-b6df8cc1f58404b62415f2321ebe12240cd9d48e.zip
Add tests
-rw-r--r--test-d/streaming.ts14
-rw-r--r--test/streaming.ts34
2 files changed, 46 insertions, 2 deletions
diff --git a/test-d/streaming.ts b/test-d/streaming.ts
index 6b186bd45a..7ff7f95999 100644
--- a/test-d/streaming.ts
+++ b/test-d/streaming.ts
@@ -9,4 +9,18 @@ describe('Streaming', () => {
expectType<Misskey.entities.Notification>(notification);
});
});
+
+ test('params type', async () => {
+ const stream = new Misskey.Stream('https://misskey.test', { token: 'TOKEN' });
+ // TODO: 「stream.useChannel の第二引数として受け入れる型が
+ // {
+ // otherparty?: User['id'] | null;
+ // group?: UserGroup['id'] | null;
+ // }
+ // になっている」というテストを行いたいけどtsdでの書き方がわからない
+ const messagingChannel = stream.useChannel('messaging', { otherparty: 'aaa' });
+ messagingChannel.on('message', message => {
+ expectType<Misskey.entities.MessagingMessage>(message);
+ });
+ });
});
diff --git a/test/streaming.ts b/test/streaming.ts
index 7de85ce775..d346d8cabc 100644
--- a/test/streaming.ts
+++ b/test/streaming.ts
@@ -36,10 +36,40 @@ describe('Streaming', () => {
server.close();
});
- /* TODO
test('useChannel with parameters', async () => {
+ const server = new WS('wss://misskey.test/streaming');
+ const stream = new Stream('https://misskey.test', { token: 'TOKEN' });
+ const messagingChannelReceived: any[] = [];
+ const messaging = stream.useChannel('messaging', { otherparty: 'aaa' });
+ messaging.on('message', payload => {
+ messagingChannelReceived.push(payload);
+ });
+ await server.connected;
+ const msg = JSON.parse(await server.nextMessage as string);
+ const messagingChannelId = msg.body.id;
+ expect(msg.type).toEqual('connect');
+ expect(msg.body.channel).toEqual('messaging');
+ expect(msg.body.params).toEqual({ otherparty: 'aaa' });
+ expect(messagingChannelId != null).toEqual(true);
+
+ server.send(JSON.stringify({
+ type: 'channel',
+ body: {
+ id: messagingChannelId,
+ type: 'message',
+ body: {
+ id: 'foo'
+ }
+ }
+ }));
+
+ expect(messagingChannelReceived[0]).toEqual({
+ id: 'foo'
+ });
+
+ stream.close();
+ server.close();
});
- */
test('Connection#dispose', async () => {
const server = new WS('wss://misskey.test/streaming');