@@ -4,9 +4,30 @@ import { describeWithAtlas, withProject, randomId } from "./atlasHelpers.js";
4
4
import { expectDefined , getResponseElements } from "../../helpers.js" ;
5
5
6
6
describeWithAtlas ( "db users" , ( integration ) => {
7
- const userName = "testuser-" + randomId ;
8
7
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 ( ) => {
10
31
const projectId = getProjectId ( ) ;
11
32
12
33
const session : Session = integration . mcpServer ( ) . session ;
@@ -36,46 +57,21 @@ describeWithAtlas("db users", (integration) => {
36
57
} ) ;
37
58
38
59
it ( "should create a database user with supplied password" , async ( ) => {
39
- const projectId = getProjectId ( ) ;
60
+ const response = await createUserWithMCP ( "testpassword" ) ;
40
61
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
- } ) ;
55
62
const elements = getResponseElements ( response ) ;
56
63
expect ( elements ) . toHaveLength ( 1 ) ;
57
64
expect ( elements [ 0 ] . text ) . toContain ( "created successfully" ) ;
65
+ expect ( elements [ 0 ] . text ) . toContain ( userName ) ;
66
+ expect ( elements [ 0 ] . text ) . not . toContain ( "testpassword" ) ;
58
67
} ) ;
59
68
60
69
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 ( ) ;
76
71
const elements = getResponseElements ( response ) ;
77
72
expect ( elements ) . toHaveLength ( 1 ) ;
78
73
expect ( elements [ 0 ] . text ) . toContain ( "created successfully" ) ;
74
+ expect ( elements [ 0 ] . text ) . toContain ( userName ) ;
79
75
expect ( elements [ 0 ] . text ) . toContain ( "with password: `" ) ;
80
76
} ) ;
81
77
} ) ;
@@ -91,6 +87,8 @@ describeWithAtlas("db users", (integration) => {
91
87
it ( "returns database users by project" , async ( ) => {
92
88
const projectId = getProjectId ( ) ;
93
89
90
+ await createUserWithMCP ( ) ;
91
+
94
92
const response = ( await integration
95
93
. mcpClient ( )
96
94
. callTool ( { name : "atlas-list-db-users" , arguments : { projectId } } ) ) as CallToolResult ;
0 commit comments