Skip to content

Commit 2a92184

Browse files
davemarcoMarco
andauthored
refactor(webui): Migrate example tests to new Fastify architecture. (#1099)
Co-authored-by: Marco <[email protected]>
1 parent fe78f4f commit 2a92184

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

components/webui/server/src/app.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
import settings from "../settings.json" with {type: "json"};
77
import DbManager from "./plugins/DbManager.js";
88
import S3Manager from "./plugins/S3Manager.js";
9-
import exampleRoutes from "./routes/example.js";
109
import queryRoutes from "./routes/query.js";
1110
import staticRoutes from "./routes/static.js";
1211

@@ -59,7 +58,6 @@ const FastifyV1App: FastifyPluginAsync<AppPluginOptions> = async (
5958

6059
// Register the routes
6160
await fastify.register(staticRoutes);
62-
await fastify.register(exampleRoutes);
6361
await fastify.register(queryRoutes);
6462
};
6563

components/webui/server/src/routes/example.ts renamed to components/webui/server/src/fastify-v2/routes/api/example/index.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
import {TypeBoxTypeProvider} from "@fastify/type-provider-typebox";
1+
import {FastifyPluginAsyncTypebox} from "@fastify/type-provider-typebox";
22
import {Type} from "@sinclair/typebox";
3-
import {FastifyPluginAsync} from "fastify";
43

54

65
/**
76
* Creates example routes.
87
*
9-
* @param app
8+
* @param fastify
109
*/
11-
const routes: FastifyPluginAsync = async (app) => {
12-
const fastify = app.withTypeProvider<TypeBoxTypeProvider>();
13-
10+
const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
1411
fastify.get("/example/get/:name", {
1512
schema: {
1613
params: Type.Object({
@@ -32,4 +29,4 @@ const routes: FastifyPluginAsync = async (app) => {
3229
});
3330
};
3431

35-
export default routes;
32+
export default plugin;

components/webui/server/src/test/app.test.ts renamed to components/webui/server/src/test/example.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
import fastify from "fastify";
12
import {StatusCodes} from "http-status-codes";
23
import tap, {Test} from "tap";
34

4-
import {build} from "./tap.js";
5+
import routes from "../fastify-v2/routes/api/example/index.js";
56

67

78
tap.test("Tests the example routes", async (t: Test) => {
8-
const server = await build(t);
9+
const server = fastify();
10+
server.register(routes);
911

1012
let resp = await server.inject({
1113
method: "GET",
@@ -23,6 +25,3 @@ tap.test("Tests the example routes", async (t: Test) => {
2325
t.equal(resp.statusCode, StatusCodes.OK);
2426
t.match(JSON.parse(resp.body), {msg: String});
2527
});
26-
27-
// eslint-disable-next-line no-warning-comments
28-
// TODO: Add tests for `query` routes.

0 commit comments

Comments
 (0)