Skip to content

Commit 4be2265

Browse files
committed
chore: remove env from constants
1 parent a12d390 commit 4be2265

3 files changed

Lines changed: 33 additions & 20 deletions

File tree

packages/features/calAIPhone/providers/retellAI/RetellSDKClient.test.ts

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { Retell } from "retell-sdk";
2-
import { describe, it, expect, beforeEach, vi } from "vitest";
2+
import { describe, it, expect, beforeEach, vi, beforeAll } from "vitest";
33

44
import logger from "@calcom/lib/logger";
55

6-
import { RetellSDKClient } from "./RetellSDKClient";
76
import type {
87
CreateLLMRequest,
98
UpdateLLMRequest,
@@ -14,6 +13,8 @@ import type {
1413
RetellDynamicVariables,
1514
} from "./types";
1615

16+
let RetellSDKClient: typeof import("./RetellSDKClient").RetellSDKClient;
17+
1718
vi.mock("retell-sdk", () => ({
1819
Retell: vi.fn().mockImplementation(() => ({
1920
llm: {
@@ -41,10 +42,6 @@ vi.mock("retell-sdk", () => ({
4142
})),
4243
}));
4344

44-
vi.mock("@calcom/lib/constants", () => ({
45-
RETELL_API_KEY: "test-retell-api-key",
46-
}));
47-
4845
vi.mock("@calcom/lib/logger", () => ({
4946
default: {
5047
getSubLogger: vi.fn().mockReturnValue({
@@ -56,7 +53,21 @@ vi.mock("@calcom/lib/logger", () => ({
5653
},
5754
}));
5855

56+
const TEST_API_KEY = "test-retell-api-key";
57+
5958
describe("RetellSDKClient", () => {
59+
beforeAll(() => {
60+
const originalEnv = process.env.RETELL_AI_KEY;
61+
vi.stubEnv("RETELL_AI_KEY", TEST_API_KEY);
62+
63+
return () => {
64+
if (originalEnv !== undefined) {
65+
vi.stubEnv("RETELL_AI_KEY", originalEnv);
66+
} else {
67+
vi.unstubAllEnvs();
68+
}
69+
};
70+
});
6071
let client: RetellSDKClient;
6172
let mockRetellInstance: any;
6273
let mockLogger: any;
@@ -100,24 +111,30 @@ describe("RetellSDKClient", () => {
100111
});
101112

102113
describe("constructor", () => {
114+
beforeAll(async () => {
115+
// Reset modules and reimport with mocked env var
116+
vi.resetModules();
117+
const module = await import("./RetellSDKClient");
118+
RetellSDKClient = module.RetellSDKClient;
119+
});
120+
103121
it("should create client with default logger when no custom logger provided", () => {
104122
client = new RetellSDKClient();
105123

106124
expect(logger.getSubLogger).toHaveBeenCalledWith({ prefix: ["retellSDKClient:"] });
107-
expect(Retell).toHaveBeenCalledWith({ apiKey: "test-retell-api-key" });
125+
expect(Retell).toHaveBeenCalledWith({ apiKey: TEST_API_KEY });
108126
});
109127

110128
it("should create client with custom logger", () => {
111129
client = new RetellSDKClient(mockLogger);
112130

113131
expect(logger.getSubLogger).not.toHaveBeenCalled();
114-
expect(Retell).toHaveBeenCalledWith({ apiKey: "test-retell-api-key" });
132+
expect(Retell).toHaveBeenCalledWith({ apiKey: TEST_API_KEY });
115133
});
116134

117-
it("should throw error when RETELL_API_KEY is not configured", async () => {
118-
vi.doMock("@calcom/lib/constants", () => ({
119-
RETELL_API_KEY: undefined,
120-
}));
135+
it("should throw error when RETELL_AI_KEY is not configured", async () => {
136+
vi.unstubAllEnvs();
137+
vi.stubEnv("RETELL_AI_KEY", "");
121138

122139
vi.resetModules();
123140
const { RetellSDKClient: TestRetellSDKClient } = await import("./RetellSDKClient");
@@ -126,9 +143,8 @@ describe("RetellSDKClient", () => {
126143
new TestRetellSDKClient();
127144
}).toThrow("RETELL_API_KEY is not configured");
128145

129-
vi.doMock("@calcom/lib/constants", () => ({
130-
RETELL_API_KEY: "test-retell-api-key",
131-
}));
146+
// Restore the env var
147+
vi.stubEnv("RETELL_AI_KEY", TEST_API_KEY);
132148
});
133149
});
134150

packages/features/calAIPhone/providers/retellAI/RetellSDKClient.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Retell } from "retell-sdk";
22

3-
import { RETELL_API_KEY } from "@calcom/lib/constants";
43
import { HttpError } from "@calcom/lib/http-error";
54
import logger from "@calcom/lib/logger";
65

@@ -16,6 +15,8 @@ import type {
1615
ImportPhoneNumberParams,
1716
} from "./types";
1817

18+
const RETELL_API_KEY = process.env.RETELL_AI_KEY;
19+
1920
export class RetellSDKClient implements RetellAIRepository {
2021
private client: Retell;
2122
private logger: ReturnType<typeof logger.getSubLogger>;

packages/lib/constants.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ export const WEBAPP_URL =
2121
// So for development purpose, we would stick to localhost only
2222
export const WEBAPP_URL_FOR_OAUTH = IS_PRODUCTION || IS_DEV ? WEBAPP_URL : "http://localhost:3000";
2323

24-
/**
25-
* ⚠️ Server-only! Do NOT import from client-side code.
26-
*/
27-
export const RETELL_API_KEY = process.env.RETELL_AI_KEY;
2824

2925
/** @deprecated use `WEBAPP_URL` */
3026
export const BASE_URL = WEBAPP_URL;

0 commit comments

Comments
 (0)