Skip to content

Commit 7130914

Browse files
committed
fix unit tests
1 parent 942f429 commit 7130914

File tree

7 files changed

+44
-5
lines changed

7 files changed

+44
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"lint": "yarn workspaces run lint",
1818
"prepare": "node .husky/install.mjs || true",
1919
"typecheck": "yarn workspaces run typecheck",
20-
"test:unit": "vitest run tests/unit && yarn workspace infra-core-ui run test:unit",
20+
"test:unit": "vitest run tests/unit --config tests/unit/vitest.config.ts && yarn workspace infra-core-ui run test:unit",
2121
"test:unit-ui": "yarn test:unit --ui",
2222
"test:unit-watch": "vitest tests/unit",
2323
"test:live": "vitest tests/live",

src/api/plugins/auth.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ const authPlugin: FastifyPluginAsync = async (fastify, _options) => {
233233
}
234234
if (err instanceof Error) {
235235
request.log.error(`Failed to verify JWT: ${err.toString()} `);
236+
throw err;
236237
}
237238
throw new UnauthenticatedError({
238239
message: "Invalid token.",

tests/unit/discordEvent.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe("Test Events <-> Discord integration", () => {
8787
beforeEach(() => {
8888
ddbMock.reset();
8989
smMock.reset();
90-
vi.resetAllMocks();
90+
vi.clearAllMocks();
9191
vi.useFakeTimers();
9292
});
9393
});

tests/unit/entraGroupManagement.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const app = await init();
4242

4343
describe("Test Modify Group and List Group Routes", () => {
4444
beforeEach(() => {
45-
vi.resetAllMocks();
45+
vi.clearAllMocks();
4646
smMock.on(GetSecretValueCommand).resolves({
4747
SecretString: JSON.stringify({ jwt_key: "test_jwt_key" }),
4848
});
@@ -130,7 +130,7 @@ describe("Test Modify Group and List Group Routes", () => {
130130
await app.close();
131131
});
132132
beforeEach(() => {
133-
vi.resetAllMocks();
133+
vi.clearAllMocks();
134134
vi.useFakeTimers();
135135
(getEntraIdToken as any).mockImplementation(async () => {
136136
return "ey.test.token";

tests/unit/entraInviteUser.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ describe("Test Microsoft Entra ID user invitation", () => {
9595
});
9696

9797
beforeEach(() => {
98-
vi.resetAllMocks();
98+
vi.clearAllMocks();
9999
vi.useFakeTimers();
100100
// Re-implement the mock
101101
(getEntraIdToken as any).mockImplementation(async () => {

tests/unit/vitest.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineConfig } from "vitest/config";
2+
3+
export default defineConfig({
4+
test: {
5+
setupFiles: "./tests/unit/vitest.setup.ts",
6+
},
7+
});

tests/unit/vitest.setup.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { vi } from "vitest";
2+
import { allAppRoles, AppRoles } from "../../src/common/roles.js";
3+
import { group } from "console";
4+
5+
vi.mock(
6+
import("../../src/api/functions/authorization.js"),
7+
async (importOriginal) => {
8+
const mod = await importOriginal();
9+
return {
10+
...mod,
11+
getUserRoles: vi.fn(async (_, __, userEmail) => {
12+
const mockUserRoles = {
13+
"[email protected]": [AppRoles.TICKETS_SCANNER],
14+
kLkvWTYwNnJfBkIK7mBi4niXXHYNR7ygbV8utlvFxjw: allAppRoles,
15+
};
16+
17+
return mockUserRoles[userEmail] || [];
18+
}),
19+
20+
getGroupRoles: vi.fn(async (_, __, groupId) => {
21+
const mockGroupRoles = {
22+
"0": allAppRoles,
23+
"1": [],
24+
"scanner-only": [AppRoles.TICKETS_SCANNER],
25+
};
26+
27+
return mockGroupRoles[groupId] || [];
28+
}),
29+
};
30+
},
31+
);

0 commit comments

Comments
 (0)