|
1 |
| -import { describe, it, expect } from "vitest"; |
| 1 | +import { describe, it, expect, vi, beforeEach } from "vitest"; |
2 | 2 | import type { UserConfig } from "../../../src/common/config.js";
|
3 |
| -import { setupUserConfig, defaultUserConfig } from "../../../src/common/config.js"; |
| 3 | +import { setupUserConfig, defaultUserConfig, warnAboutDeprecatedCliArgs } from "../../../src/common/config.js"; |
| 4 | +import type { CliOptions } from "@mongosh/arg-parser"; |
4 | 5 |
|
5 | 6 | describe("config", () => {
|
6 | 7 | describe("env var parsing", () => {
|
@@ -605,3 +606,39 @@ describe("config", () => {
|
605 | 606 | });
|
606 | 607 | });
|
607 | 608 | });
|
| 609 | + |
| 610 | +describe("Deprecated CLI arguments", () => { |
| 611 | + const referDocMessage = |
| 612 | + "Refer to https://www.mongodb.com/docs/mcp-server/get-started/ for setting up the MCP Server."; |
| 613 | + |
| 614 | + type TestCase = { readonly cliArg: keyof (CliOptions & UserConfig); readonly warning: string }; |
| 615 | + const testCases = [ |
| 616 | + { |
| 617 | + cliArg: "connectionString", |
| 618 | + warning: |
| 619 | + "The --connectionString argument is deprecated. Prefer using the first positional argument for the connection string or the MDB_MCP_CONNECTION_STRING environment variable.", |
| 620 | + }, |
| 621 | + ] as TestCase[]; |
| 622 | + |
| 623 | + for (const { cliArg, warning } of testCases) { |
| 624 | + describe(`deprecation behaviour of ${cliArg}`, () => { |
| 625 | + let cliArgs: CliOptions & UserConfig & { _?: string[] }; |
| 626 | + let warn: (msg: string) => void; |
| 627 | + |
| 628 | + beforeEach(() => { |
| 629 | + cliArgs = { [cliArg]: "RandomString" } as unknown as CliOptions & UserConfig & { _?: string[] }; |
| 630 | + warn = vi.fn(); |
| 631 | + |
| 632 | + warnAboutDeprecatedCliArgs(cliArgs, warn); |
| 633 | + }); |
| 634 | + |
| 635 | + it(`warns the usage of ${cliArg} as it is deprecated`, () => { |
| 636 | + expect(warn).toHaveBeenCalledWith(warning); |
| 637 | + }); |
| 638 | + |
| 639 | + it(`shows the reference message when ${cliArg} was passed`, () => { |
| 640 | + expect(warn).toHaveBeenCalledWith(referDocMessage); |
| 641 | + }); |
| 642 | + }); |
| 643 | + } |
| 644 | +}); |
0 commit comments