-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdropDatabase.test.ts
79 lines (64 loc) · 3.07 KB
/
dropDatabase.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { describeWithMongoDB, validateAutoConnectBehavior } from "../mongodbHelpers.js";
import {
getResponseContent,
validateToolMetadata,
validateThrowsForInvalidArguments,
databaseParameters,
databaseInvalidArgs,
} from "../../../helpers.js";
describeWithMongoDB("dropDatabase tool", (integration) => {
validateToolMetadata(
integration,
"drop-database",
"Removes the specified database, deleting the associated data files",
databaseParameters
);
validateThrowsForInvalidArguments(integration, "drop-database", databaseInvalidArgs);
it("can drop non-existing database", async () => {
let { databases } = await integration.mongoClient().db("").admin().listDatabases();
expect(databases.find((db) => db.name === integration.randomDbName())).toBeUndefined();
await integration.connectMcpClient();
const response = await integration.mcpClient().callTool({
name: "drop-database",
arguments: {
database: integration.randomDbName(),
},
});
const content = getResponseContent(response.content);
expect(content).toContain(`Successfully dropped database "${integration.randomDbName()}"`);
({ databases } = await integration.mongoClient().db("").admin().listDatabases());
expect(databases.find((db) => db.name === integration.randomDbName())).toBeUndefined();
});
it("removes the database along with its collections", async () => {
await integration.connectMcpClient();
await integration.mongoClient().db(integration.randomDbName()).createCollection("coll1");
await integration.mongoClient().db(integration.randomDbName()).createCollection("coll2");
let { databases } = await integration.mongoClient().db("").admin().listDatabases();
expect(databases.find((db) => db.name === integration.randomDbName())).toBeDefined();
const response = await integration.mcpClient().callTool({
name: "drop-database",
arguments: {
database: integration.randomDbName(),
},
});
const content = getResponseContent(response.content);
expect(content).toContain(`Successfully dropped database "${integration.randomDbName()}"`);
({ databases } = await integration.mongoClient().db("").admin().listDatabases());
expect(databases.find((db) => db.name === integration.randomDbName())).toBeUndefined();
const collections = await integration.mongoClient().db(integration.randomDbName()).listCollections().toArray();
expect(collections).toHaveLength(0);
});
validateAutoConnectBehavior(
integration,
"drop-database",
() => {
return {
args: { database: integration.randomDbName() },
expectedResponse: `Successfully dropped database "${integration.randomDbName()}"`,
};
},
async () => {
await integration.mongoClient().db(integration.randomDbName()).createCollection("coll1");
}
);
});