2023-04-08 02:44:27 +02:00
|
|
|
import { expectType } from "tsd";
|
2023-09-24 06:27:16 +02:00
|
|
|
import * as firefish from "../src";
|
2023-04-08 02:44:27 +02:00
|
|
|
|
|
|
|
describe("Streaming", () => {
|
|
|
|
test("emit type", async () => {
|
2023-09-24 06:27:16 +02:00
|
|
|
const stream = new firefish.Stream("https://firefish.test", {
|
2023-04-08 02:44:27 +02:00
|
|
|
token: "TOKEN",
|
|
|
|
});
|
|
|
|
const mainChannel = stream.useChannel("main");
|
|
|
|
mainChannel.on("notification", (notification) => {
|
2023-09-24 06:27:16 +02:00
|
|
|
expectType<firefish.entities.Notification>(notification);
|
2023-04-08 02:44:27 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("params type", async () => {
|
2023-09-24 06:27:16 +02:00
|
|
|
const stream = new firefish.Stream("https://firefish.test", {
|
2023-04-08 02:44:27 +02:00
|
|
|
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) => {
|
2023-09-24 06:27:16 +02:00
|
|
|
expectType<firefish.entities.MessagingMessage>(message);
|
2023-04-08 02:44:27 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|