@@ -4,9 +4,30 @@ import { describeWithAtlas, withProject, randomId } from "./atlasHelpers.js";
44import { expectDefined , getResponseElements } from "../../helpers.js" ;
55
66describeWithAtlas ( "db users" , ( integration ) => {
7- const userName = "testuser-" + randomId ;
87 withProject ( integration , ( { getProjectId } ) => {
9- afterAll ( async ( ) => {
8+ let userName : string ;
9+ beforeEach ( ( ) => {
10+ userName = "testuser-" + randomId ;
11+ } ) ;
12+
13+ const createUserWithMCP = async ( password ?: string ) : Promise < unknown > => {
14+ return await integration . mcpClient ( ) . callTool ( {
15+ name : "atlas-create-db-user" ,
16+ arguments : {
17+ projectId : getProjectId ( ) ,
18+ username : userName ,
19+ password,
20+ roles : [
21+ {
22+ roleName : "readWrite" ,
23+ databaseName : "admin" ,
24+ } ,
25+ ] ,
26+ } ,
27+ } ) ;
28+ } ;
29+
30+ afterEach ( async ( ) => {
1031 const projectId = getProjectId ( ) ;
1132
1233 const session : Session = integration . mcpServer ( ) . session ;
@@ -36,46 +57,21 @@ describeWithAtlas("db users", (integration) => {
3657 } ) ;
3758
3859 it ( "should create a database user with supplied password" , async ( ) => {
39- const projectId = getProjectId ( ) ;
60+ const response = await createUserWithMCP ( "testpassword" ) ;
4061
41- const response = await integration . mcpClient ( ) . callTool ( {
42- name : "atlas-create-db-user" ,
43- arguments : {
44- projectId,
45- username : userName ,
46- password : "testpassword" ,
47- roles : [
48- {
49- roleName : "readWrite" ,
50- databaseName : "admin" ,
51- } ,
52- ] ,
53- } ,
54- } ) ;
5562 const elements = getResponseElements ( response ) ;
5663 expect ( elements ) . toHaveLength ( 1 ) ;
5764 expect ( elements [ 0 ] . text ) . toContain ( "created successfully" ) ;
65+ expect ( elements [ 0 ] . text ) . toContain ( userName ) ;
66+ expect ( elements [ 0 ] . text ) . not . toContain ( "testpassword" ) ;
5867 } ) ;
5968
6069 it ( "should create a database user with generated password" , async ( ) => {
61- const projectId = getProjectId ( ) ;
62-
63- const response = await integration . mcpClient ( ) . callTool ( {
64- name : "atlas-create-db-user" ,
65- arguments : {
66- projectId,
67- username : userName ,
68- roles : [
69- {
70- roleName : "readWrite" ,
71- databaseName : "admin" ,
72- } ,
73- ] ,
74- } ,
75- } ) ;
70+ const response = await createUserWithMCP ( ) ;
7671 const elements = getResponseElements ( response ) ;
7772 expect ( elements ) . toHaveLength ( 1 ) ;
7873 expect ( elements [ 0 ] . text ) . toContain ( "created successfully" ) ;
74+ expect ( elements [ 0 ] . text ) . toContain ( userName ) ;
7975 expect ( elements [ 0 ] . text ) . toContain ( "with password: `" ) ;
8076 } ) ;
8177 } ) ;
@@ -91,6 +87,8 @@ describeWithAtlas("db users", (integration) => {
9187 it ( "returns database users by project" , async ( ) => {
9288 const projectId = getProjectId ( ) ;
9389
90+ await createUserWithMCP ( ) ;
91+
9492 const response = ( await integration
9593 . mcpClient ( )
9694 . callTool ( { name : "atlas-list-db-users" , arguments : { projectId } } ) ) as CallToolResult ;
0 commit comments