Skip to content

Commit 01c8a73

Browse files
committed
chore: make atlas create db user keychain tests more reliable
1 parent 87069d3 commit 01c8a73

File tree

1 file changed

+28
-27
lines changed

1 file changed

+28
-27
lines changed

tests/integration/tools/atlas/dbUsers.test.ts

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ describeWithAtlas("db users", (integration) => {
99
let userName: string;
1010
beforeEach(() => {
1111
userName = "testuser-" + randomId;
12-
Keychain.root.clearAllSecrets();
13-
});
14-
15-
afterEach(() => {
16-
Keychain.root.clearAllSecrets();
1712
});
1813

1914
const createUserWithMCP = async (password?: string): Promise<unknown> => {
@@ -44,7 +39,6 @@ describeWithAtlas("db users", (integration) => {
4439
await integration.mcpServer().session.apiClient.deleteDatabaseUser({
4540
params: {
4641
path: {
47-
groupId: projectId,
4842
username: userName,
4943
databaseName: "admin",
5044
},
@@ -59,6 +53,14 @@ describeWithAtlas("db users", (integration) => {
5953
});
6054

6155
describe("atlas-create-db-user", () => {
56+
beforeEach(() => {
57+
Keychain.root.clearAllSecrets();
58+
});
59+
60+
afterEach(() => {
61+
Keychain.root.clearAllSecrets();
62+
});
63+
6264
it("should have correct metadata", async () => {
6365
const { tools } = await integration.mcpClient().listTools();
6466
const createDbUser = tools.find((tool) => tool.name === "atlas-create-db-user");
@@ -80,16 +82,16 @@ describeWithAtlas("db users", (integration) => {
8082
expect(elements[0]?.text).toContain("created successfully");
8183
expect(elements[0]?.text).toContain(userName);
8284
expect(elements[0]?.text).not.toContain("testpassword");
83-
expect(integration.mcpServer().session.keychain.allSecrets).toEqual([
84-
{
85-
value: userName,
86-
kind: "user",
87-
},
88-
{
89-
value: "testpassword",
90-
kind: "password",
91-
},
92-
]);
85+
86+
expect(integration.mcpServer().session.keychain.allSecrets).toContainEqual({
87+
value: userName,
88+
kind: "user",
89+
});
90+
91+
expect(integration.mcpServer().session.keychain.allSecrets).toContainEqual({
92+
value: "testpassword",
93+
kind: "password",
94+
});
9395
});
9496

9597
it("should create a database user with generated password", async () => {
@@ -105,19 +107,18 @@ describeWithAtlas("db users", (integration) => {
105107

106108
const password = elements[0]?.text
107109
.substring(passwordStart + 1, passwordEnd - 1)
108-
.replace("`", "")
110+
.replace(/`/g, "")
109111
.trim();
110112

111-
expect(integration.mcpServer().session.keychain.allSecrets).toEqual([
112-
{
113-
value: userName,
114-
kind: "user",
115-
},
116-
{
117-
value: password,
118-
kind: "password",
119-
},
120-
]);
113+
expect(integration.mcpServer().session.keychain.allSecrets).toContainEqual({
114+
value: userName,
115+
kind: "user",
116+
});
117+
118+
expect(integration.mcpServer().session.keychain.allSecrets).toContainEqual({
119+
value: password,
120+
kind: "password",
121+
});
121122
});
122123

123124
it("should add current IP to access list when creating a database user", async () => {

0 commit comments

Comments
 (0)