test(test): added in vitest to start doing more testing before deploying
This commit is contained in:
0
backend/datamart/datamart.controller.test.ts
Normal file
0
backend/datamart/datamart.controller.test.ts
Normal file
68
backend/datamart/getDatamart.route.test.ts
Normal file
68
backend/datamart/getDatamart.route.test.ts
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
import express from "express";
|
||||||
|
import request from "supertest";
|
||||||
|
import { describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
|
vi.mock("../db/db.controller.js", () => ({
|
||||||
|
db: {},
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock("../logger/logger.controller.js", () => ({
|
||||||
|
createLogger: () => ({
|
||||||
|
info: vi.fn(),
|
||||||
|
error: vi.fn(),
|
||||||
|
warn: vi.fn(),
|
||||||
|
debug: vi.fn(),
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock("./datamart.controller.js", () => ({
|
||||||
|
runDatamartQuery: vi.fn(async ({ name, options }) => ({
|
||||||
|
success: true,
|
||||||
|
message: `Ran ${name}`,
|
||||||
|
data: {
|
||||||
|
name,
|
||||||
|
options,
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
}));
|
||||||
|
|
||||||
|
import { runDatamartQuery } from "./datamart.controller.js";
|
||||||
|
import getDatamartRoute from "./getDatamart.route.js";
|
||||||
|
|
||||||
|
function createTestApp() {
|
||||||
|
const app = express();
|
||||||
|
|
||||||
|
app.use(express.json());
|
||||||
|
app.use("/datamart", getDatamartRoute);
|
||||||
|
|
||||||
|
return app;
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("GET /datamart/:name", () => {
|
||||||
|
it("runs a datamart query by name and returns api response", async () => {
|
||||||
|
const app = createTestApp();
|
||||||
|
|
||||||
|
const res = await request(app).get("/datamart/orders").query({
|
||||||
|
value: "123",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(res.status).toBe(200);
|
||||||
|
|
||||||
|
expect(runDatamartQuery).toHaveBeenCalledWith({
|
||||||
|
name: "orders",
|
||||||
|
options: {
|
||||||
|
value: "123",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(res.body.success).toBe(true);
|
||||||
|
expect(res.body.module).toBe("datamart");
|
||||||
|
expect(res.body.subModule).toBe("query");
|
||||||
|
expect(res.body.data).toEqual({
|
||||||
|
name: "orders",
|
||||||
|
options: {
|
||||||
|
value: "123",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
1366
package-lock.json
generated
1366
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -5,6 +5,7 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "dotenvx run -f .env -- vitest",
|
"test": "dotenvx run -f .env -- vitest",
|
||||||
|
"test:run": "dotenvx run -f .env -- vitest run",
|
||||||
"dev": "concurrently -n \"server,frontend\" -c \"#007755, #1F73D1\" \"npm run dev:app\" \"npm run dev:frontend\"",
|
"dev": "concurrently -n \"server,frontend\" -c \"#007755, #1F73D1\" \"npm run dev:app\" \"npm run dev:frontend\"",
|
||||||
"dev:app": "dotenvx run -f .env -- tsx watch backend/server.ts",
|
"dev:app": "dotenvx run -f .env -- tsx watch backend/server.ts",
|
||||||
"dev:frontend": "cd frontend && npm run dev",
|
"dev:frontend": "cd frontend && npm run dev",
|
||||||
@@ -59,9 +60,11 @@
|
|||||||
"cz-conventional-changelog": "^3.3.0",
|
"cz-conventional-changelog": "^3.3.0",
|
||||||
"npm-check-updates": "^19.6.5",
|
"npm-check-updates": "^19.6.5",
|
||||||
"openapi-types": "^12.1.3",
|
"openapi-types": "^12.1.3",
|
||||||
|
"supertest": "^7.2.2",
|
||||||
"ts-node-dev": "^2.0.0",
|
"ts-node-dev": "^2.0.0",
|
||||||
"tsx": "^4.21.0",
|
"tsx": "^4.21.0",
|
||||||
"typescript": "^5.9.3"
|
"typescript": "^5.9.3",
|
||||||
|
"vitest": "^4.1.8"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@dotenvx/dotenvx": "^1.57.0",
|
"@dotenvx/dotenvx": "^1.57.0",
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
// import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
|
|
||||||
// import { connectProdSql } from "../backend/src/prodSql/prodSqlConnection.controller.js";
|
|
||||||
|
|
||||||
// let pool: unknown;
|
|
||||||
|
|
||||||
// describe("Prod SQL connection", () => {
|
|
||||||
// // This may take seconds, so give plenty of time
|
|
||||||
// vi.setTimeout(30000);
|
|
||||||
|
|
||||||
// beforeAll(async () => {
|
|
||||||
// pool = await connectProdSql();
|
|
||||||
// });
|
|
||||||
|
|
||||||
// afterAll(async () => {
|
|
||||||
// if (pool?.close) await pool.close();
|
|
||||||
// });
|
|
||||||
|
|
||||||
// it("should connect and return expected data", async () => {
|
|
||||||
// // Example query — use something safe and consistent
|
|
||||||
// const result = await pool
|
|
||||||
// .request()
|
|
||||||
// .query("SELECT TOP 1 id, name FROM Users ORDER BY id ASC");
|
|
||||||
|
|
||||||
// expect(result.recordset).toBeDefined();
|
|
||||||
// expect(Array.isArray(result.recordset)).toBe(true);
|
|
||||||
// expect(result.recordset.length).toBeGreaterThan(0);
|
|
||||||
// expect(result.recordset[0]).toHaveProperty("id");
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
import { describe, expect, test, vi } from "vitest";
|
|
||||||
import { sendEmail } from "../backend/src/utils/sendEmail.utils";
|
|
||||||
|
|
||||||
// Mock the logger before imports
|
|
||||||
vi.mock("../backend/src/logger/logger.controller", () => ({
|
|
||||||
createLogger: () => ({
|
|
||||||
info: vi.fn(),
|
|
||||||
error: vi.fn(),
|
|
||||||
debug: vi.fn(),
|
|
||||||
fatal: vi.fn(),
|
|
||||||
}),
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe("Mail sending", () => {
|
|
||||||
test("should send an email successfully", async () => {
|
|
||||||
const result = await sendEmail({
|
|
||||||
email: "blake.matthes@alpla.com",
|
|
||||||
subject: "LST - Testing system",
|
|
||||||
template: "testEmail",
|
|
||||||
context: { name: "blake" },
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(result).toMatchObject({
|
|
||||||
success: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(result?.message).toContain("blake.matthes@alpla.com");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("should handle email send failure gracefully", async () => {
|
|
||||||
const badResult = await sendEmail({
|
|
||||||
email: "invalid-address",
|
|
||||||
subject: "LST - Testing system",
|
|
||||||
template: "",
|
|
||||||
context: {},
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(badResult).toMatchObject({
|
|
||||||
success: false,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -3,6 +3,6 @@ import { defineConfig } from "vitest/config";
|
|||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
test: {
|
test: {
|
||||||
globals: true,
|
globals: true,
|
||||||
include: ["tests/**/*.test.ts"], // ← point to your tests folder
|
include: ["backend/**/*.test.ts"], // ← point to your tests folder
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user