Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"lint": "yarn workspaces run lint",
"prepare": "node .husky/install.mjs || true",
"typecheck": "yarn workspaces run typecheck",
"test:unit": "cross-env RunEnvironment='dev' vitest run tests/unit --config tests/unit/vitest.config.ts && yarn workspace infra-core-ui run test:unit",
"test:unit": "cross-env RunEnvironment='dev' vitest run --coverage tests/unit --config tests/unit/vitest.config.ts && yarn workspace infra-core-ui run test:unit",
"test:unit-ui": "yarn test:unit --ui",
"test:unit-watch": "vitest tests/unit",
"test:live": "vitest tests/live",
Expand All @@ -38,6 +38,7 @@
"@typescript-eslint/eslint-plugin": "^8.0.1",
"@typescript-eslint/parser": "^8.0.1",
"@vitejs/plugin-react": "^4.3.1",
"@vitest/coverage-istanbul": "2.1.9",
"@vitest/ui": "^2.0.5",
"aws-sdk-client-mock": "^4.1.0",
"concurrently": "^9.1.2",
Expand Down
3 changes: 3 additions & 0 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ export function transformCommaSeperatedName(name: string) {
if (name.includes(",")) {
try {
const split = name.split(",");
if (split.filter((x) => x !== " " && x !== "").length !== 2) {
return name;
}
return `${split[1].slice(1, split[1].length).split(" ")[0]} ${split[0]}`;
} catch {
return name;
Expand Down
29 changes: 29 additions & 0 deletions tests/unit/common/sqsMessage.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { expect, test, describe } from "vitest";
import { parseSQSPayload } from "../../../src/common/types/sqsMessage.js";
import { ZodError } from "zod";

describe("SQS Message Parsing Tests", () => {
test("Ping message parses correctly", () => {
const payload = {
metadata: {
reqId: "12345",
initiator: "unit-test",
},
function: "ping",
payload: {},
};
const response = parseSQSPayload(payload);
expect(response).toStrictEqual(payload);
});
test("Invalid function doesn't parse", () => {
const payload = {
metadata: {
reqId: "12345",
initiator: "unit-test",
},
function: "invalid_function",
payload: {},
};
expect(parseSQSPayload(payload)).toBeInstanceOf(ZodError);
});
});
29 changes: 29 additions & 0 deletions tests/unit/common/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { expect, test, describe } from "vitest";
import { transformCommaSeperatedName } from "../../../src/common/utils.js";

describe("Comma-seperated name transformer tests", () => {
test("Already-transformed names are returned as-is", () => {
const output = transformCommaSeperatedName("Test User");
expect(output).toEqual("Test User");
});
test("Last, First is returned as First Last", () => {
const output = transformCommaSeperatedName("User, Test");
expect(output).toEqual("Test User");
});
test("Last, First Middle is returned as First Last", () => {
const output = transformCommaSeperatedName("User, Test Thing");
expect(output).toEqual("Test User");
});
test("`Last, ` is returned as-is", () => {
const output = transformCommaSeperatedName("User, ");
expect(output).toEqual("User, ");
});
test("`Last,` is returned as-is", () => {
const output = transformCommaSeperatedName("User,");
expect(output).toEqual("User,");
});
test("`, Test` is returned as-is", () => {
const output = transformCommaSeperatedName(", Test");
expect(output).toEqual(", Test");
});
});
33 changes: 27 additions & 6 deletions tests/unit/vending.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
import { expect, test } from "vitest";
import { afterAll, describe, expect, test } from "vitest";
import init from "../../src/api/index.js";
import { beforeEach } from "node:test";
import supertest from "supertest";

const app = await init();
test("Test getting events", async () => {
const response = await app.inject({
method: "GET",
url: "/api/v1/vending/items",
describe("Vending routes tests", async () => {
test("Test getting vending items", async () => {
const response = await app.inject({
method: "GET",
url: "/api/v1/vending/items",
});
expect(response.statusCode).toBe(200);
});
test("Test adding vending items", async () => {
const response = await supertest(app.server)
.post("/api/v1/vending/items")
.send({
name: "Test",
imageUrl: "https://google.com",
price: 1,
});
expect(response.statusCode).toBe(200);
expect(response.body).toStrictEqual({ status: "Not implemented." });
});
afterAll(async () => {
await app.close();
});
beforeEach(() => {
(app as any).nodeCache.flushAll();
});
expect(response.statusCode).toBe(200);
});
4 changes: 4 additions & 0 deletions tests/unit/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ const __dirname = path.dirname(__filename);
export default defineConfig({
test: {
setupFiles: "./tests/unit/vitest.setup.ts",
coverage: {
provider: "istanbul",
include: ["src/api/**/*.ts", "src/common/**/*.ts"],
},
},
resolve: {
alias: {
Expand Down
Loading
Loading