@@ -6,7 +6,7 @@ const IMAGE = getImage(__dirname);
66
77describe ( "MongodbContainer" , { timeout : 240_000 } , ( ) => {
88 // connect4 {
9- it ( "should work using default version 4.0.1" , async ( ) => {
9+ it . skip ( "should work using default version 4.0.1" , async ( ) => {
1010 const mongodbContainer = await new MongoDBContainer ( IMAGE ) . start ( ) ;
1111
1212 // directConnection: true is required as the testcontainer is created as a MongoDB Replica Set.
@@ -36,7 +36,7 @@ describe("MongodbContainer", { timeout: 240_000 }, () => {
3636 // }
3737
3838 // connect6 {
39- it ( "should work using version 6.0.1" , async ( ) => {
39+ it . skip ( "should work using version 6.0.1" , async ( ) => {
4040 const mongodbContainer = await new MongoDBContainer ( "mongo:6.0.1" ) . start ( ) ;
4141
4242 // directConnection: true is required as the testcontainer is created as a MongoDB Replica Set.
@@ -65,7 +65,7 @@ describe("MongodbContainer", { timeout: 240_000 }, () => {
6565 } ) ;
6666 // }
6767 test . for ( [ [ "mongo:4.0.1" ] , [ "mongo:6.0.1" ] , [ "mongo:8.0" ] ] ) (
68- "should connect to %s with credentials and rs disabled" ,
68+ "should connect to %s with credentials and disabled replica set " ,
6969 async ( [ image ] ) => {
7070 const mongodbContainer = await new MongoDBContainer ( image )
7171 . withUsername ( "mongo_user" )
@@ -79,6 +79,30 @@ describe("MongodbContainer", { timeout: 240_000 }, () => {
7979 expect ( id ) . not . toBeNull ( ) ;
8080 expect ( id ) . not . toBe ( "" ) ;
8181
82+ await mongoose . disconnect ( ) ;
83+ await mongodbContainer . stop ( ) ;
84+ }
85+ ) ;
86+ it ( "should throw when using both credentials AND replica set" , async ( ) => {
87+ expect (
88+ new MongoDBContainer ( "mongo:8.0" )
89+ . withUsername ( "mongo_user" )
90+ . withPassword ( "mongo_password" )
91+ . withReplicaSetEnabled ( true )
92+ . start ( )
93+ ) . rejects . toThrow ( ) ;
94+ } ) ;
95+ test . for ( [ [ "mongo:4.0.1" ] , [ "mongo:6.0.1" ] , [ "mongo:8.0" ] ] ) (
96+ "should connect to %s without credentials and with disabled replica set" ,
97+ async ( [ image ] ) => {
98+ const mongodbContainer = await new MongoDBContainer ( image ) . withReplicaSetEnabled ( false ) . start ( ) ;
99+ const db = await mongoose . connect ( mongodbContainer . getConnectionString ( ) , { directConnection : true } ) ;
100+ expect ( db . connection . readyState ) . toBe ( 1 ) ;
101+ const result = await db . connection . collection ( "testcontainers" ) . insertOne ( { title : "testcontainers" } ) ;
102+ const id = result . insertedId . toString ( ) ;
103+ expect ( id ) . not . toBeNull ( ) ;
104+ expect ( id ) . not . toBe ( "" ) ;
105+
82106 await mongoose . disconnect ( ) ;
83107 await mongodbContainer . stop ( ) ;
84108 }
0 commit comments