2023-04-08 08:47:04 +09:00
|
|
|
import { expectType } from "tsd";
|
|
|
|
import * as Misskey from "../src";
|
2023-04-07 23:25:22 +09:00
|
|
|
|
2023-04-08 08:47:04 +09:00
|
|
|
describe("API", () => {
|
|
|
|
test("success", async () => {
|
2023-04-07 23:25:22 +09:00
|
|
|
const cli = new Misskey.api.APIClient({
|
2023-04-08 08:47:04 +09:00
|
|
|
origin: "https://misskey.test",
|
|
|
|
credential: "TOKEN",
|
2023-04-07 23:25:22 +09:00
|
|
|
});
|
2023-04-08 08:47:04 +09:00
|
|
|
const res = await cli.request("meta", { detail: true });
|
2023-04-07 23:25:22 +09:00
|
|
|
expectType<Misskey.entities.DetailedInstanceMetadata>(res);
|
|
|
|
});
|
|
|
|
|
2023-04-08 08:47:04 +09:00
|
|
|
test("conditional respose type (meta)", async () => {
|
2023-04-07 23:25:22 +09:00
|
|
|
const cli = new Misskey.api.APIClient({
|
2023-04-08 08:47:04 +09:00
|
|
|
origin: "https://misskey.test",
|
|
|
|
credential: "TOKEN",
|
2023-04-07 23:25:22 +09:00
|
|
|
});
|
|
|
|
|
2023-04-08 08:47:04 +09:00
|
|
|
const res = await cli.request("meta", { detail: true });
|
2023-04-07 23:25:22 +09:00
|
|
|
expectType<Misskey.entities.DetailedInstanceMetadata>(res);
|
|
|
|
|
2023-04-08 08:47:04 +09:00
|
|
|
const res2 = await cli.request("meta", { detail: false });
|
2023-04-07 23:25:22 +09:00
|
|
|
expectType<Misskey.entities.LiteInstanceMetadata>(res2);
|
|
|
|
|
2023-04-08 08:47:04 +09:00
|
|
|
const res3 = await cli.request("meta", {});
|
2023-04-07 23:25:22 +09:00
|
|
|
expectType<Misskey.entities.LiteInstanceMetadata>(res3);
|
|
|
|
|
2023-04-08 08:47:04 +09:00
|
|
|
const res4 = await cli.request("meta", { detail: true as boolean });
|
|
|
|
expectType<
|
|
|
|
| Misskey.entities.LiteInstanceMetadata
|
|
|
|
| Misskey.entities.DetailedInstanceMetadata
|
|
|
|
>(res4);
|
2023-04-07 23:25:22 +09:00
|
|
|
});
|
|
|
|
|
2023-04-08 08:47:04 +09:00
|
|
|
test("conditional respose type (users/show)", async () => {
|
2023-04-07 23:25:22 +09:00
|
|
|
const cli = new Misskey.api.APIClient({
|
2023-04-08 08:47:04 +09:00
|
|
|
origin: "https://misskey.test",
|
|
|
|
credential: "TOKEN",
|
2023-04-07 23:25:22 +09:00
|
|
|
});
|
|
|
|
|
2023-04-08 08:47:04 +09:00
|
|
|
const res = await cli.request("users/show", { userId: "xxxxxxxx" });
|
2023-04-07 23:25:22 +09:00
|
|
|
expectType<Misskey.entities.UserDetailed>(res);
|
|
|
|
|
2023-04-08 08:47:04 +09:00
|
|
|
const res2 = await cli.request("users/show", { userIds: ["xxxxxxxx"] });
|
2023-04-07 23:25:22 +09:00
|
|
|
expectType<Misskey.entities.UserDetailed[]>(res2);
|
|
|
|
});
|
|
|
|
});
|