Skip to content

Commit 7971332

Browse files
committed
fix: don't execute cleanup code if setup failed
1 parent 7845035 commit 7971332

File tree

4 files changed

+34
-24
lines changed

4 files changed

+34
-24
lines changed

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,18 @@ describeWithAtlas("ip access lists", (integration) => {
2727
const apiClient = integration.mcpServer().session.apiClient;
2828

2929
const projectId = getProjectId();
30-
31-
for (const value of values) {
32-
await apiClient.deleteProjectIpAccessList({
33-
params: {
34-
path: {
35-
groupId: projectId,
36-
entryValue: value,
30+
if (projectId) {
31+
// projectId may be empty if beforeAll failed.
32+
for (const value of values) {
33+
await apiClient.deleteProjectIpAccessList({
34+
params: {
35+
path: {
36+
groupId: projectId,
37+
entryValue: value,
38+
},
3739
},
38-
},
39-
});
40+
});
41+
}
4042
}
4143
});
4244

tests/integration/tools/atlas/atlasHelpers.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function withProject(integration: IntegrationTest, fn: ProjectTestFunctio
4141

4242
try {
4343
const group = await createProject(apiClient);
44-
projectId = group.id || "";
44+
projectId = group.id;
4545
} catch (error) {
4646
console.error("Failed to create project:", error);
4747
throw error;
@@ -50,14 +50,16 @@ export function withProject(integration: IntegrationTest, fn: ProjectTestFunctio
5050

5151
afterAll(async () => {
5252
const apiClient = integration.mcpServer().session.apiClient;
53-
54-
await apiClient.deleteProject({
55-
params: {
56-
path: {
57-
groupId: projectId,
53+
if (projectId) {
54+
// projectId may be empty if beforeAll failed.
55+
await apiClient.deleteProject({
56+
params: {
57+
path: {
58+
groupId: projectId,
59+
},
5860
},
59-
},
60-
});
61+
});
62+
}
6163
});
6264

6365
const args = {
@@ -90,7 +92,7 @@ export function parseTable(text: string): Record<string, string>[] {
9092

9193
export const randomId = new ObjectId().toString();
9294

93-
async function createProject(apiClient: ApiClient): Promise<Group> {
95+
async function createProject(apiClient: ApiClient): Promise<Group & Required<Pick<Group, "id">>> {
9496
const projectName: string = `testProj-` + randomId;
9597

9698
const orgs = await apiClient.listOrganizations();
@@ -109,5 +111,5 @@ async function createProject(apiClient: ApiClient): Promise<Group> {
109111
throw new Error("Failed to create project");
110112
}
111113

112-
return group;
114+
return group as Group & Required<Pick<Group, "id">>;
113115
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ describeWithAtlas("clusters", (integration) => {
6262

6363
afterAll(async () => {
6464
const projectId = getProjectId();
65-
66-
const session: Session = integration.mcpServer().session;
67-
68-
await deleteAndWaitCluster(session, projectId, clusterName);
65+
if (projectId) {
66+
const session: Session = integration.mcpServer().session;
67+
await deleteAndWaitCluster(session, projectId, clusterName);
68+
}
6969
});
7070

7171
describe("atlas-create-free-cluster", () => {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,17 @@ describeWithAtlas("db users", (integration) => {
2828
};
2929

3030
afterEach(async () => {
31+
const projectId = getProjectId();
32+
if (!projectId) {
33+
// projectId may be empty if beforeAll failed
34+
return;
35+
}
36+
3137
try {
3238
await integration.mcpServer().session.apiClient.deleteDatabaseUser({
3339
params: {
3440
path: {
35-
groupId: getProjectId(),
41+
groupId: projectId,
3642
username: userName,
3743
databaseName: "admin",
3844
},

0 commit comments

Comments
 (0)