ci(app): testing and other app config changes
This commit is contained in:
29
tests/examplequery.test.ts
Normal file
29
tests/examplequery.test.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
|
||||
import { connectProdSql } from "../backend/src/prodSql/prodSqlConnection.controller.js";
|
||||
|
||||
let pool: any;
|
||||
|
||||
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 && 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");
|
||||
});
|
||||
});
|
||||
42
tests/sendEmail.test.ts
Normal file
42
tests/sendEmail.test.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
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,
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user