From cc3e823a7d6f58b6d1531f7de2162a5e812f6eb8 Mon Sep 17 00:00:00 2001 From: Blake Matthes Date: Tue, 30 Dec 2025 21:04:54 -0600 Subject: [PATCH] test(datamart): more work on datamart stuff --- backend/src/configs/scaler.config.ts | 8 +++ backend/src/datamart/datamart.routes.ts | 6 -- backend/src/scaler/datamartAdd.spec.ts | 87 +++++++++++++++++++++++++ backend/src/scaler/getDatamart.spec.ts | 77 ++++++++++++++++++++++ 4 files changed, 172 insertions(+), 6 deletions(-) create mode 100644 backend/src/scaler/datamartAdd.spec.ts create mode 100644 backend/src/scaler/getDatamart.spec.ts diff --git a/backend/src/configs/scaler.config.ts b/backend/src/configs/scaler.config.ts index 5f8bf38..1e57849 100644 --- a/backend/src/configs/scaler.config.ts +++ b/backend/src/configs/scaler.config.ts @@ -8,9 +8,13 @@ import type { Express } from "express"; import { apiReference } from "@scalar/express-api-reference"; // const port = 3000; import type { OpenAPIV3_1 } from "openapi-types"; +import { datamartAddSpec } from "../scaler/datamartAdd.spec.js"; +import { getDatamartSpec } from "../scaler/getDatamart.spec.js"; +import { prodLoginSpec } from "../scaler/login.spec.js"; import { prodRestartSpec } from "../scaler/prodSqlRestart.spec.js"; import { prodStartSpec } from "../scaler/prodSqlStart.spec.js"; import { prodStopSpec } from "../scaler/prodSqlStop.spec.js"; +import { prodRegisterSpec } from "../scaler/register.spec.js"; // all the specs import { statusSpec } from "../scaler/stats.spec.js"; @@ -62,6 +66,10 @@ export const setupApiDocsRoutes = (baseUrl: string, app: Express) => { ...prodStartSpec, ...prodStopSpec, ...prodRestartSpec, + ...prodLoginSpec, + ...prodRegisterSpec, + ...getDatamartSpec, + ...datamartAddSpec, // Add more specs here as you build features }, diff --git a/backend/src/datamart/datamart.routes.ts b/backend/src/datamart/datamart.routes.ts index b51903b..c212cf0 100644 --- a/backend/src/datamart/datamart.routes.ts +++ b/backend/src/datamart/datamart.routes.ts @@ -4,10 +4,4 @@ export const setupDatamartRoutes = (baseUrl: string, app: Express) => { //setup all the routes app.use(`${baseUrl}/api/datamart`, runQuery); - - app.all("*foo", (_, res) => { - res.status(400).json({ - message: "You have encountered a datamart route that dose not exist", - }); - }); }; diff --git a/backend/src/scaler/datamartAdd.spec.ts b/backend/src/scaler/datamartAdd.spec.ts new file mode 100644 index 0000000..7b1cdc3 --- /dev/null +++ b/backend/src/scaler/datamartAdd.spec.ts @@ -0,0 +1,87 @@ +import type { OpenAPIV3_1 } from "openapi-types"; + +export const datamartAddSpec: OpenAPIV3_1.PathsObject = { + "/api/datamart/add": { + post: { + summary: "Creates the new query", + description: "Queries can only be created on the main server.", + tags: ["Datamart"], + requestBody: { + required: true, + content: { + "application/json": { + schema: { + type: "object", + required: ["username", "password", "email"], + properties: { + username: { + type: "string", + example: "jdoe", + }, + name: { + type: "string", + format: "string", + example: "joe", + }, + email: { + type: "string", + format: "email", + example: "joe.doe@alpla.net", + }, + password: { + type: "string", + format: "password", + example: "superSecretPassword", + }, + }, + }, + }, + }, + }, + responses: { + "200": { + description: "User info", + content: { + "application/json": { + schema: { + type: "object", + properties: { + success: { + type: "boolean", + format: "true", + example: true, + }, + message: { + type: "string", + example: "User was created", + }, + }, + }, + }, + }, + }, + "400": { + description: "Invalid Data was sent over", + content: { + "application/json": { + schema: { + type: "object", + properties: { + success: { + type: "boolean", + format: "false", + example: false, + }, + message: { + type: "string", + format: "Invalid Data was sent over.", + }, + }, + }, + }, + }, + }, + }, + }, + }, +}; diff --git a/backend/src/scaler/getDatamart.spec.ts b/backend/src/scaler/getDatamart.spec.ts new file mode 100644 index 0000000..2180fc2 --- /dev/null +++ b/backend/src/scaler/getDatamart.spec.ts @@ -0,0 +1,77 @@ +import type { OpenAPIV3_1 } from "openapi-types"; + +export const getDatamartSpec: OpenAPIV3_1.PathsObject = { + "/api/datamart/{name}": { + get: { + summary: "Runs the query by name", + description: + "This will allow to run any query by its name and optional parameters to be sent over as well, up to 3 params can be added", + tags: ["Datamart"], + + parameters: [ + { + name: "name", + in: "path", + required: true, + description: "Name to look up", + schema: { + type: "string", + }, + example: "exampleName", + }, + { + name: "limit", + in: "query", + required: false, // 👈 optional + description: "Maximum number of records to return", + schema: { + type: "integer", + minimum: 1, + maximum: 100, + }, + example: 10, + }, + ], + + responses: { + "200": { + description: "Successful response", + content: { + "application/json": { + schema: { + type: "object", + properties: { + success: { type: "boolean", example: true }, + data: { + type: "object", + example: { + name: "exampleName", + value: "some value", + }, + }, + }, + }, + }, + }, + }, + "400": { + description: "Bad request", + content: { + "application/json": { + schema: { + type: "object", + properties: { + success: { type: "boolean", example: false }, + message: { + type: "string", + example: "Invalid name parameter", + }, + }, + }, + }, + }, + }, + }, + }, + }, +};