1- import { beforeEach , describe , expect , it } from "vitest" ;
1+ import { beforeEach , describe , expect , it , vi } from "vitest" ;
22import { DebugResource } from "../../../../src/resources/common/debug.js" ;
33import { Session } from "../../../../src/common/session.js" ;
44import { Telemetry } from "../../../../src/telemetry/telemetry.js" ;
@@ -13,13 +13,15 @@ import { Keychain } from "../../../../src/common/keychain.js";
1313describe ( "debug resource" , ( ) => {
1414 const logger = new CompositeLogger ( ) ;
1515 const deviceId = DeviceId . create ( logger ) ;
16- const session = new Session ( {
17- apiBaseUrl : "" ,
18- logger,
19- exportsManager : ExportsManager . init ( config , logger ) ,
20- connectionManager : new MCPConnectionManager ( config , driverOptions , logger , deviceId ) ,
21- keychain : new Keychain ( ) ,
22- } ) ;
16+ const session = vi . mocked (
17+ new Session ( {
18+ apiBaseUrl : "" ,
19+ logger,
20+ exportsManager : ExportsManager . init ( config , logger ) ,
21+ connectionManager : new MCPConnectionManager ( config , driverOptions , logger , deviceId ) ,
22+ keychain : new Keychain ( ) ,
23+ } )
24+ ) ;
2325 const telemetry = Telemetry . create ( session , { ...config , telemetry : "disabled" } , deviceId ) ;
2426
2527 let debugResource : DebugResource = new DebugResource ( session , config , telemetry ) ;
@@ -28,54 +30,56 @@ describe("debug resource", () => {
2830 debugResource = new DebugResource ( session , config , telemetry ) ;
2931 } ) ;
3032
31- it ( "should be connected when a connected event happens" , ( ) => {
33+ it ( "should be connected when a connected event happens" , async ( ) => {
3234 debugResource . reduceApply ( "connect" , undefined ) ;
33- const output = debugResource . toOutput ( ) ;
35+ const output = await debugResource . toOutput ( ) ;
3436
35- expect ( output ) . toContain ( `The user is connected to the MongoDB cluster.` ) ;
37+ expect ( output ) . toContain (
38+ `The user is connected to the MongoDB cluster without any support for search indexes.`
39+ ) ;
3640 } ) ;
3741
38- it ( "should be disconnected when a disconnect event happens" , ( ) => {
42+ it ( "should be disconnected when a disconnect event happens" , async ( ) => {
3943 debugResource . reduceApply ( "disconnect" , undefined ) ;
40- const output = debugResource . toOutput ( ) ;
44+ const output = await debugResource . toOutput ( ) ;
4145
4246 expect ( output ) . toContain ( `The user is not connected to a MongoDB cluster.` ) ;
4347 } ) ;
4448
45- it ( "should be disconnected when a close event happens" , ( ) => {
49+ it ( "should be disconnected when a close event happens" , async ( ) => {
4650 debugResource . reduceApply ( "close" , undefined ) ;
47- const output = debugResource . toOutput ( ) ;
51+ const output = await debugResource . toOutput ( ) ;
4852
4953 expect ( output ) . toContain ( `The user is not connected to a MongoDB cluster.` ) ;
5054 } ) ;
5155
52- it ( "should be disconnected and contain an error when an error event occurred" , ( ) => {
56+ it ( "should be disconnected and contain an error when an error event occurred" , async ( ) => {
5357 debugResource . reduceApply ( "connection-error" , {
5458 tag : "errored" ,
5559 errorReason : "Error message from the server" ,
5660 } ) ;
5761
58- const output = debugResource . toOutput ( ) ;
62+ const output = await debugResource . toOutput ( ) ;
5963
6064 expect ( output ) . toContain ( `The user is not connected to a MongoDB cluster because of an error.` ) ;
6165 expect ( output ) . toContain ( `<error>Error message from the server</error>` ) ;
6266 } ) ;
6367
64- it ( "should show the inferred authentication type" , ( ) => {
68+ it ( "should show the inferred authentication type" , async ( ) => {
6569 debugResource . reduceApply ( "connection-error" , {
6670 tag : "errored" ,
6771 connectionStringAuthType : "scram" ,
6872 errorReason : "Error message from the server" ,
6973 } ) ;
7074
71- const output = debugResource . toOutput ( ) ;
75+ const output = await debugResource . toOutput ( ) ;
7276
7377 expect ( output ) . toContain ( `The user is not connected to a MongoDB cluster because of an error.` ) ;
7478 expect ( output ) . toContain ( `The inferred authentication mechanism is "scram".` ) ;
7579 expect ( output ) . toContain ( `<error>Error message from the server</error>` ) ;
7680 } ) ;
7781
78- it ( "should show the atlas cluster information when provided" , ( ) => {
82+ it ( "should show the atlas cluster information when provided" , async ( ) => {
7983 debugResource . reduceApply ( "connection-error" , {
8084 tag : "errored" ,
8185 connectionStringAuthType : "scram" ,
@@ -88,7 +92,7 @@ describe("debug resource", () => {
8892 } ,
8993 } ) ;
9094
91- const output = debugResource . toOutput ( ) ;
95+ const output = await debugResource . toOutput ( ) ;
9296
9397 expect ( output ) . toContain ( `The user is not connected to a MongoDB cluster because of an error.` ) ;
9498 expect ( output ) . toContain (
@@ -97,4 +101,12 @@ describe("debug resource", () => {
97101 expect ( output ) . toContain ( `The inferred authentication mechanism is "scram".` ) ;
98102 expect ( output ) . toContain ( `<error>Error message from the server</error>` ) ;
99103 } ) ;
104+
105+ it ( "should notify if a cluster supports search indexes" , async ( ) => {
106+ session . isSearchIndexSupported = vi . fn ( ) . mockResolvedValue ( true ) ;
107+ debugResource . reduceApply ( "connect" , undefined ) ;
108+ const output = await debugResource . toOutput ( ) ;
109+
110+ expect ( output ) . toContain ( `The user is connected to the MongoDB cluster with support for search indexes.` ) ;
111+ } ) ;
100112} ) ;
0 commit comments