Skip to content

Commit 2c624e2

Browse files
committed
fix unit tests
1 parent d5fd5ba commit 2c624e2

File tree

12 files changed

+40
-24
lines changed

12 files changed

+40
-24
lines changed

tests/unit/apiKey.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { afterAll, expect, test, beforeEach, vi, describe } from "vitest";
22
import { mockClient } from "aws-sdk-client-mock";
33
import init from "../../src/api/index.js";
44
import { createJwt } from "./auth.test.js";
5-
import { secretObject } from "./secret.testdata.js";
5+
import { testSecretObject } from "./secret.testdata.js";
66
import supertest from "supertest";
77
import {
88
ConditionalCheckFailedException,
@@ -31,7 +31,7 @@ vi.mock("../../src/api/functions/apiKey.js", () => {
3131
// Mock DynamoDB client
3232
const dynamoMock = mockClient(DynamoDBClient);
3333
const sqsMock = mockClient(SQSClient);
34-
const jwt_secret = secretObject["jwt_key"];
34+
const jwt_secret = testSecretObject["jwt_key"];
3535

3636
vi.stubEnv("JwtSigningKey", jwt_secret);
3737

tests/unit/auth.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import {
55
secretObject,
66
jwtPayload,
77
jwtPayloadNoGroups,
8+
testSecretObject,
89
} from "./secret.testdata.js";
910
import jwt from "jsonwebtoken";
1011
import { allAppRoles, AppRoles } from "../../src/common/roles.js";
1112
import { beforeEach, describe } from "node:test";
1213

1314
const app = await init();
14-
const jwt_secret = secretObject["jwt_key"];
15+
const jwt_secret = testSecretObject["jwt_key"];
1516
export function createJwt(date?: Date, groups?: string[], email?: string) {
1617
let modifiedPayload = {
1718
...jwtPayload,

tests/unit/discordEvent.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import { DynamoDBClient, PutItemCommand } from "@aws-sdk/client-dynamodb";
33
import { mockClient } from "aws-sdk-client-mock";
44
import init from "../../src/api/index.js";
55
import { createJwt } from "./auth.test.js";
6-
import { secretObject } from "./secret.testdata.js";
6+
import { testSecretObject } from "./secret.testdata.js";
77
import supertest from "supertest";
88
import { describe } from "node:test";
99
import { updateDiscord } from "../../src/api/functions/discord.js";
1010

1111
const ddbMock = mockClient(DynamoDBClient);
1212

13-
const jwt_secret = secretObject["jwt_key"];
13+
const jwt_secret = testSecretObject["jwt_key"];
1414
vi.stubEnv("JwtSigningKey", jwt_secret);
1515

1616
vi.mock("../../src/api/functions/discord.js", () => {

tests/unit/entraInviteUser.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { afterAll, expect, test, beforeEach, vi } from "vitest";
22
import init from "../../src/api/index.js";
33
import { createJwt } from "./auth.test.js";
4-
import { secretObject } from "./secret.testdata.js";
4+
import { testSecretObject } from "./secret.testdata.js";
55
import supertest from "supertest";
66
import { describe } from "node:test";
77

@@ -23,7 +23,7 @@ import {
2323
} from "../../src/api/functions/entraId.js";
2424
import { EntraInvitationError } from "../../src/common/errors/index.js";
2525

26-
const jwt_secret = secretObject["jwt_key"];
26+
const jwt_secret = testSecretObject["jwt_key"];
2727

2828
vi.stubEnv("JwtSigningKey", jwt_secret);
2929

tests/unit/eventPost.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import {
88
import { mockClient } from "aws-sdk-client-mock";
99
import init from "../../src/api/index.js";
1010
import { createJwt } from "./auth.test.js";
11-
import { secretJson, secretObject } from "./secret.testdata.js";
11+
import { testSecretObject } from "./secret.testdata.js";
1212
import supertest from "supertest";
1313
import { marshall } from "@aws-sdk/util-dynamodb";
1414

1515
const ddbMock = mockClient(DynamoDBClient);
16-
const jwt_secret = secretObject["jwt_key"];
16+
const jwt_secret = testSecretObject["jwt_key"];
1717
vi.stubEnv("JwtSigningKey", jwt_secret);
1818

1919
const app = await init();

tests/unit/events.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import {
88
import { mockClient } from "aws-sdk-client-mock";
99
import init from "../../src/api/index.js";
1010
import { createJwt } from "./auth.test.js";
11-
import { secretObject } from "./secret.testdata.js";
11+
import { testSecretObject } from "./secret.testdata.js";
1212
import supertest from "supertest";
1313
import { marshall } from "@aws-sdk/util-dynamodb";
1414

1515
const ddbMock = mockClient(DynamoDBClient);
16-
const jwt_secret = secretObject["jwt_key"];
16+
const jwt_secret = testSecretObject["jwt_key"];
1717
vi.stubEnv("JwtSigningKey", jwt_secret);
1818

1919
// Mock the Discord client to prevent the actual Discord API call

tests/unit/ical.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import {
66
dynamoEventWithRepeatExclusion,
77
dynamoTableData,
88
} from "./mockEventData.testdata.js";
9-
import { secretObject } from "./secret.testdata.js";
9+
import { testSecretObject } from "./secret.testdata.js";
1010
import { readFile } from "fs/promises";
1111

1212
const ddbMock = mockClient(DynamoDBClient);
13-
const jwt_secret = secretObject["jwt_key"];
13+
const jwt_secret = testSecretObject["jwt_key"];
1414
vi.stubEnv("JwtSigningKey", jwt_secret);
1515

1616
const app = await init();

tests/unit/linkry.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import {
99
import { mockClient } from "aws-sdk-client-mock";
1010
import init from "../../src/api/index.js";
1111
import { createJwt } from "./auth.test.js";
12-
import { secretObject } from "./secret.testdata.js";
12+
import { testSecretObject } from "./secret.testdata.js";
1313
import supertest from "supertest";
1414
import { dynamoTableData } from "./mockLinkryData.testdata.js";
1515
import { genericConfig } from "../../src/common/config.js";
1616

1717
const ddbMock = mockClient(DynamoDBClient);
18-
const jwt_secret = secretObject["jwt_key"];
18+
const jwt_secret = testSecretObject["jwt_key"];
1919
vi.stubEnv("JwtSigningKey", jwt_secret);
2020

2121
// Mock the Cloudfront KV client to prevent the actual Cloudfront KV call

tests/unit/logs.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import init from "../../src/api/index.js";
33
import { describe } from "node:test";
44
import { mockClient } from "aws-sdk-client-mock";
55
import { DynamoDBClient, QueryCommand } from "@aws-sdk/client-dynamodb";
6-
import { secretObject } from "./secret.testdata.js";
6+
import { testSecretObject } from "./secret.testdata.js";
77
import supertest from "supertest";
88
import { createJwt } from "./auth.test.js";
99
import { genericConfig } from "../../src/common/config.js";
1010
import { marshall } from "@aws-sdk/util-dynamodb";
1111
import { Modules } from "../../src/common/modules.js";
1212

1313
const ddbMock = mockClient(DynamoDBClient);
14-
const jwt_secret = secretObject["jwt_key"];
14+
const jwt_secret = testSecretObject["jwt_key"];
1515
vi.stubEnv("JwtSigningKey", jwt_secret);
1616

1717
const app = await init();

tests/unit/secret.testdata.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { SecretConfig } from "../../src/common/config.js";
22

33
const secretObject = {
4-
jwt_key: "somethingreallysecret",
54
discord_guild_id: "12345",
65
discord_bot_token: "12345",
76
entra_id_private_key: "",
@@ -13,10 +12,16 @@ const secretObject = {
1312
acm_passkit_signerKey_base64: "",
1413
apple_signing_cert_base64: "",
1514
redis_url: "",
16-
} as SecretConfig & { jwt_key: string };
15+
} as SecretConfig;
16+
17+
const testSecretObject = {
18+
jwt_key: "somethingreallysecret",
19+
};
1720

1821
const secretJson = JSON.stringify(secretObject);
1922

23+
const testSecretJson = JSON.stringify(testSecretObject);
24+
2025
const jwtPayload = {
2126
aud: "custom_jwt",
2227
iss: "custom_jwt",
@@ -69,4 +74,11 @@ const jwtPayloadNoGroups = {
6974
ver: "1.0",
7075
};
7176

72-
export { secretJson, secretObject, jwtPayload, jwtPayloadNoGroups };
77+
export {
78+
secretJson,
79+
secretObject,
80+
testSecretJson,
81+
testSecretObject,
82+
jwtPayload,
83+
jwtPayloadNoGroups,
84+
};

0 commit comments

Comments
 (0)