rudeshark.net/packages/firefish-js/test-d/api.ts

49 lines
1.5 KiB
TypeScript
Raw Normal View History

import { expectType } from "tsd";
2023-09-24 06:27:16 +02:00
import * as firefish from "../src";
describe("API", () => {
test("success", async () => {
2023-09-24 06:27:16 +02:00
const cli = new firefish.api.APIClient({
2023-07-03 00:18:30 +02:00
origin: "https://firefish.test",
credential: "TOKEN",
});
const res = await cli.request("meta", { detail: true });
2023-09-24 06:27:16 +02:00
expectType<firefish.entities.DetailedInstanceMetadata>(res);
});
test("conditional respose type (meta)", async () => {
2023-09-24 06:27:16 +02:00
const cli = new firefish.api.APIClient({
2023-07-03 00:18:30 +02:00
origin: "https://firefish.test",
credential: "TOKEN",
});
const res = await cli.request("meta", { detail: true });
2023-09-24 06:27:16 +02:00
expectType<firefish.entities.DetailedInstanceMetadata>(res);
const res2 = await cli.request("meta", { detail: false });
2023-09-24 06:27:16 +02:00
expectType<firefish.entities.LiteInstanceMetadata>(res2);
const res3 = await cli.request("meta", {});
2023-09-24 06:27:16 +02:00
expectType<firefish.entities.LiteInstanceMetadata>(res3);
const res4 = await cli.request("meta", { detail: true as boolean });
expectType<
2023-09-24 06:27:16 +02:00
| firefish.entities.LiteInstanceMetadata
| firefish.entities.DetailedInstanceMetadata
>(res4);
});
test("conditional respose type (users/show)", async () => {
2023-09-24 06:27:16 +02:00
const cli = new firefish.api.APIClient({
2023-07-03 00:18:30 +02:00
origin: "https://firefish.test",
credential: "TOKEN",
});
const res = await cli.request("users/show", { userId: "xxxxxxxx" });
2023-09-24 06:27:16 +02:00
expectType<firefish.entities.UserDetailed>(res);
const res2 = await cli.request("users/show", { userIds: ["xxxxxxxx"] });
2023-09-24 06:27:16 +02:00
expectType<firefish.entities.UserDetailed[]>(res2);
});
});