2023-04-07 03:56:46 +02:00
|
|
|
process.env.NODE_ENV = "test";
|
2018-10-15 23:37:21 +02:00
|
|
|
|
2023-04-07 03:56:46 +02:00
|
|
|
import * as assert from "assert";
|
|
|
|
import * as childProcess from "child_process";
|
|
|
|
import {
|
|
|
|
async,
|
|
|
|
post,
|
|
|
|
react,
|
2023-10-20 02:10:30 +02:00
|
|
|
request,
|
2023-04-07 03:56:46 +02:00
|
|
|
shutdownServer,
|
2023-10-20 02:10:30 +02:00
|
|
|
signup,
|
|
|
|
startServer,
|
|
|
|
uploadFile,
|
2023-04-07 03:56:46 +02:00
|
|
|
} from "./utils.js";
|
2018-10-15 23:37:21 +02:00
|
|
|
|
2023-04-07 03:56:46 +02:00
|
|
|
describe("API", () => {
|
2019-04-07 14:50:36 +02:00
|
|
|
let p: childProcess.ChildProcess;
|
2022-02-19 06:05:32 +01:00
|
|
|
let alice: any;
|
|
|
|
let bob: any;
|
|
|
|
let carol: any;
|
2019-04-07 14:50:36 +02:00
|
|
|
|
2022-02-19 06:05:32 +01:00
|
|
|
before(async () => {
|
|
|
|
p = await startServer();
|
2023-04-07 03:56:46 +02:00
|
|
|
alice = await signup({ username: "alice" });
|
|
|
|
bob = await signup({ username: "bob" });
|
|
|
|
carol = await signup({ username: "carol" });
|
2019-04-07 14:50:36 +02:00
|
|
|
});
|
2018-10-15 23:37:21 +02:00
|
|
|
|
2022-02-19 06:05:32 +01:00
|
|
|
after(async () => {
|
|
|
|
await shutdownServer(p);
|
2019-01-23 05:35:22 +01:00
|
|
|
});
|
|
|
|
|
2023-04-07 03:56:46 +02:00
|
|
|
describe("General validation", () => {
|
|
|
|
it("wrong type", async(async () => {
|
|
|
|
const res = await request("/test", {
|
2022-02-19 06:05:32 +01:00
|
|
|
required: true,
|
|
|
|
string: 42,
|
2018-10-15 23:37:21 +02:00
|
|
|
});
|
2019-04-07 14:50:36 +02:00
|
|
|
assert.strictEqual(res.status, 400);
|
2018-10-15 23:37:21 +02:00
|
|
|
}));
|
|
|
|
|
2023-04-07 03:56:46 +02:00
|
|
|
it("missing require param", async(async () => {
|
|
|
|
const res = await request("/test", {
|
|
|
|
string: "a",
|
2018-10-15 23:37:21 +02:00
|
|
|
});
|
2019-04-07 14:50:36 +02:00
|
|
|
assert.strictEqual(res.status, 400);
|
2018-10-15 23:37:21 +02:00
|
|
|
}));
|
|
|
|
|
2023-04-07 03:56:46 +02:00
|
|
|
it("invalid misskey:id (empty string)", async(async () => {
|
|
|
|
const res = await request("/test", {
|
2022-02-19 06:05:32 +01:00
|
|
|
required: true,
|
2023-04-07 03:56:46 +02:00
|
|
|
id: "",
|
2018-10-15 23:37:21 +02:00
|
|
|
});
|
2019-04-07 14:50:36 +02:00
|
|
|
assert.strictEqual(res.status, 400);
|
2018-10-15 23:37:21 +02:00
|
|
|
}));
|
|
|
|
|
2023-04-07 03:56:46 +02:00
|
|
|
it("valid misskey:id", async(async () => {
|
|
|
|
const res = await request("/test", {
|
2022-02-19 06:05:32 +01:00
|
|
|
required: true,
|
2023-04-07 03:56:46 +02:00
|
|
|
id: "8wvhjghbxu",
|
2018-10-15 23:37:21 +02:00
|
|
|
});
|
2019-04-07 14:50:36 +02:00
|
|
|
assert.strictEqual(res.status, 200);
|
2018-10-16 01:54:36 +02:00
|
|
|
}));
|
|
|
|
|
2023-04-07 03:56:46 +02:00
|
|
|
it("default value", async(async () => {
|
|
|
|
const res = await request("/test", {
|
2022-02-19 06:05:32 +01:00
|
|
|
required: true,
|
2023-04-07 03:56:46 +02:00
|
|
|
string: "a",
|
2018-10-16 02:45:36 +02:00
|
|
|
});
|
2019-04-07 14:50:36 +02:00
|
|
|
assert.strictEqual(res.status, 200);
|
2023-04-07 03:56:46 +02:00
|
|
|
assert.strictEqual(res.body.default, "hello");
|
2018-10-16 02:45:36 +02:00
|
|
|
}));
|
|
|
|
|
2023-04-07 03:56:46 +02:00
|
|
|
it("can set null even if it has default value", async(async () => {
|
|
|
|
const res = await request("/test", {
|
2022-02-19 06:05:32 +01:00
|
|
|
required: true,
|
|
|
|
nullableDefault: null,
|
2018-10-16 02:45:36 +02:00
|
|
|
});
|
2019-04-07 14:50:36 +02:00
|
|
|
assert.strictEqual(res.status, 200);
|
2022-02-19 06:05:32 +01:00
|
|
|
assert.strictEqual(res.body.nullableDefault, null);
|
2018-10-16 03:18:47 +02:00
|
|
|
}));
|
|
|
|
|
2023-04-07 03:56:46 +02:00
|
|
|
it("cannot set undefined if it has default value", async(async () => {
|
|
|
|
const res = await request("/test", {
|
2022-02-19 06:05:32 +01:00
|
|
|
required: true,
|
|
|
|
nullableDefault: undefined,
|
2018-10-16 03:18:47 +02:00
|
|
|
});
|
2019-04-07 14:50:36 +02:00
|
|
|
assert.strictEqual(res.status, 200);
|
2023-04-07 03:56:46 +02:00
|
|
|
assert.strictEqual(res.body.nullableDefault, "hello");
|
2019-01-25 02:58:39 +01:00
|
|
|
}));
|
|
|
|
});
|
2018-10-15 23:37:21 +02:00
|
|
|
});
|