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,54 @@ 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
3537 expect ( output ) . toContain ( `The user is connected to the MongoDB cluster.` ) ;
3638 } ) ;
3739
38- it ( "should be disconnected when a disconnect event happens" , ( ) => {
40+ it ( "should be disconnected when a disconnect event happens" , async ( ) => {
3941 debugResource . reduceApply ( "disconnect" , undefined ) ;
40- const output = debugResource . toOutput ( ) ;
42+ const output = await debugResource . toOutput ( ) ;
4143
4244 expect ( output ) . toContain ( `The user is not connected to a MongoDB cluster.` ) ;
4345 } ) ;
4446
45- it ( "should be disconnected when a close event happens" , ( ) => {
47+ it ( "should be disconnected when a close event happens" , async ( ) => {
4648 debugResource . reduceApply ( "close" , undefined ) ;
47- const output = debugResource . toOutput ( ) ;
49+ const output = await debugResource . toOutput ( ) ;
4850
4951 expect ( output ) . toContain ( `The user is not connected to a MongoDB cluster.` ) ;
5052 } ) ;
5153
52- it ( "should be disconnected and contain an error when an error event occurred" , ( ) => {
54+ it ( "should be disconnected and contain an error when an error event occurred" , async ( ) => {
5355 debugResource . reduceApply ( "connection-error" , {
5456 tag : "errored" ,
5557 errorReason : "Error message from the server" ,
5658 } ) ;
5759
58- const output = debugResource . toOutput ( ) ;
60+ const output = await debugResource . toOutput ( ) ;
5961
6062 expect ( output ) . toContain ( `The user is not connected to a MongoDB cluster because of an error.` ) ;
6163 expect ( output ) . toContain ( `<error>Error message from the server</error>` ) ;
6264 } ) ;
6365
64- it ( "should show the inferred authentication type" , ( ) => {
66+ it ( "should show the inferred authentication type" , async ( ) => {
6567 debugResource . reduceApply ( "connection-error" , {
6668 tag : "errored" ,
6769 connectionStringAuthType : "scram" ,
6870 errorReason : "Error message from the server" ,
6971 } ) ;
7072
71- const output = debugResource . toOutput ( ) ;
73+ const output = await debugResource . toOutput ( ) ;
7274
7375 expect ( output ) . toContain ( `The user is not connected to a MongoDB cluster because of an error.` ) ;
7476 expect ( output ) . toContain ( `The inferred authentication mechanism is "scram".` ) ;
7577 expect ( output ) . toContain ( `<error>Error message from the server</error>` ) ;
7678 } ) ;
7779
78- it ( "should show the atlas cluster information when provided" , ( ) => {
80+ it ( "should show the atlas cluster information when provided" , async ( ) => {
7981 debugResource . reduceApply ( "connection-error" , {
8082 tag : "errored" ,
8183 connectionStringAuthType : "scram" ,
@@ -88,7 +90,7 @@ describe("debug resource", () => {
8890 } ,
8991 } ) ;
9092
91- const output = debugResource . toOutput ( ) ;
93+ const output = await debugResource . toOutput ( ) ;
9294
9395 expect ( output ) . toContain ( `The user is not connected to a MongoDB cluster because of an error.` ) ;
9496 expect ( output ) . toContain (
@@ -97,4 +99,12 @@ describe("debug resource", () => {
9799 expect ( output ) . toContain ( `The inferred authentication mechanism is "scram".` ) ;
98100 expect ( output ) . toContain ( `<error>Error message from the server</error>` ) ;
99101 } ) ;
102+
103+ it ( "should notify if a cluster supports search indexes" , async ( ) => {
104+ session . isSearchIndexSupported = vi . fn ( ) . mockResolvedValue ( true ) ;
105+ debugResource . reduceApply ( "connect" , undefined ) ;
106+ const output = await debugResource . toOutput ( ) ;
107+
108+ expect ( output ) . toContain ( `The user is connected to the MongoDB cluster with support for search indexes.` ) ;
109+ } ) ;
100110} ) ;
0 commit comments