Skip to content

Commit 527998d

Browse files
committed
chore: add env tests
1 parent 01c3f47 commit 527998d

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

tests/unit/common/config.test.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ describe("config", () => {
127127
{ envVar: "MDB_MCP_LOG_PATH", property: "logPath", value: "/var/log" },
128128
{ envVar: "MDB_MCP_CONNECTION_STRING", property: "connectionString", value: "mongodb://localhost" },
129129
{ envVar: "MDB_MCP_READ_ONLY", property: "readOnly", value: true },
130+
{ envVar: "MDB_MCP_READ_ONLY", property: "readOnly", value: false },
131+
{ envVar: "MDB_MCP_READ_ONLY", property: "readOnly", value: "", expectedValue: false },
132+
{ envVar: "MDB_MCP_READ_ONLY", property: "readOnly", value: "false", expectedValue: false },
133+
{ envVar: "MDB_MCP_READ_ONLY", property: "readOnly", value: "true", expectedValue: true },
134+
{ envVar: "MDB_MCP_READ_ONLY", property: "readOnly", value: "apple", expectedValue: false },
135+
{ envVar: "MDB_MCP_READ_ONLY", property: "readOnly", value: "FALSE", expectedValue: false },
136+
{ envVar: "MDB_MCP_READ_ONLY", property: "readOnly", value: 0, expectedValue: false },
137+
{ envVar: "MDB_MCP_READ_ONLY", property: "readOnly", value: 1, expectedValue: false },
138+
{ envVar: "MDB_MCP_READ_ONLY", property: "readOnly", value: 100, expectedValue: false },
130139
{ envVar: "MDB_MCP_INDEX_CHECK", property: "indexCheck", value: true },
131140
{ envVar: "MDB_MCP_TRANSPORT", property: "transport", value: "http" },
132141
{ envVar: "MDB_MCP_HTTP_PORT", property: "httpPort", value: 8080 },
@@ -138,13 +147,18 @@ describe("config", () => {
138147
property: "atlasTemporaryDatabaseUserLifetimeMs",
139148
value: 12345,
140149
},
141-
] as const;
150+
] as {
151+
envVar: string;
152+
property: keyof UserConfig;
153+
value: unknown;
154+
expectedValue?: unknown;
155+
}[];
142156

143-
for (const { envVar, property, value } of testCases) {
144-
it(`should map ${envVar} to ${property} with value "${value}"`, () => {
157+
for (const { envVar, property, value, expectedValue } of testCases) {
158+
it(`should map ${envVar} to ${property} with value "${String(value)}" to "${String(expectedValue ?? value)}"`, () => {
145159
setVariable(envVar, value);
146160
const actual = createUserConfig();
147-
expect(actual[property]).toBe(value);
161+
expect(actual[property]).toBe(expectedValue ?? value);
148162
});
149163
}
150164
});

0 commit comments

Comments
 (0)