wildflock/test/app.test.ts

41 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-07-29 18:10:00 +00:00
// For more information about this file see https://dove.feathersjs.com/guides/cli/app.test.html
2023-07-29 21:50:42 +00:00
import assert from "assert";
import axios from "axios";
import type { Server } from "http";
import { app } from "../src/app";
2023-07-29 18:10:00 +00:00
2023-07-29 21:50:42 +00:00
const port = app.get("port");
const appUrl = `http://${app.get("host")}:${port}`;
2023-07-29 18:10:00 +00:00
2023-07-29 21:50:42 +00:00
describe("Feathers application tests", () => {
let server: Server;
2023-07-29 18:10:00 +00:00
before(async () => {
2023-07-29 21:50:42 +00:00
server = await app.listen(port);
});
2023-07-29 18:10:00 +00:00
after(async () => {
2023-07-29 21:50:42 +00:00
await app.teardown();
});
2023-07-29 18:10:00 +00:00
2023-07-29 21:50:42 +00:00
it("starts and shows the index page", async () => {
const { data } = await axios.get<string>(appUrl);
2023-07-29 18:10:00 +00:00
2023-07-29 21:50:42 +00:00
assert.ok(data.indexOf('<html lang="en">') !== -1);
});
2023-07-29 18:10:00 +00:00
2023-07-29 21:50:42 +00:00
it("shows a 404 JSON error", async () => {
2023-07-29 18:10:00 +00:00
try {
await axios.get(`${appUrl}/path/to/nowhere`, {
2023-07-29 21:50:42 +00:00
responseType: "json",
});
assert.fail("should never get here");
2023-07-29 18:10:00 +00:00
} catch (error: any) {
2023-07-29 21:50:42 +00:00
const { response } = error;
assert.strictEqual(response?.status, 404);
assert.strictEqual(response?.data?.code, 404);
assert.strictEqual(response?.data?.name, "NotFound");
2023-07-29 18:10:00 +00:00
}
2023-07-29 21:50:42 +00:00
});
});