Skip to content

Commit 0f9de75

Browse files
chore: add connection specifier parse test
1 parent 8abcd6e commit 0f9de75

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tests/unit/common/config.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,15 @@ describe("config", () => {
174174
expect(actual.connectionString).toEqual("mongodb://user:password@host1,host2,host3/");
175175
});
176176

177+
it("positional connection specifier gets accounted for even without other connection sources", () => {
178+
// Note that neither connectionString argument nor env variable is
179+
// provided.
180+
const actual = createUserConfig({
181+
cliArguments: ["mongodb://host1:27017"],
182+
});
183+
expect(actual.connectionString).toEqual("mongodb://host1:27017/?directConnection=true");
184+
});
185+
177186
describe("string use cases", () => {
178187
const testCases = [
179188
{
@@ -487,6 +496,14 @@ describe("config", () => {
487496
clearVariables();
488497
});
489498

499+
it("positional argument takes precedence over all", () => {
500+
setVariable("MDB_MCP_CONNECTION_STRING", "mongodb://crazyhost1");
501+
const actual = createUserConfig({
502+
cliArguments: ["mongodb://crazyhost2", "--connectionString", "mongodb://localhost"],
503+
});
504+
expect(actual.connectionString).toBe("mongodb://crazyhost2/?directConnection=true");
505+
});
506+
490507
it("cli arguments take precedence over env vars", () => {
491508
setVariable("MDB_MCP_CONNECTION_STRING", "mongodb://crazyhost");
492509
const actual = createUserConfig({

0 commit comments

Comments
 (0)