Skip to content

Commit 8a90fd6

Browse files
committed
address comment: move objectId to common args
1 parent 9526a4d commit 8a90fd6

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/tools/args.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ export const ALLOWED_PROJECT_NAME_CHARACTERS_ERROR =
1818
"Project names can't be longer than 64 characters and can only contain letters, numbers, spaces, and the following symbols: ( ) @ & + : . _ - ' ,";
1919
export const CommonArgs = {
2020
string: (): ZodString => z.string().regex(NO_UNICODE_REGEX, NO_UNICODE_ERROR),
21-
};
2221

23-
export const AtlasArgs = {
2422
objectId: (fieldName: string): z.ZodString =>
2523
z
2624
.string()
2725
.min(1, `${fieldName} is required`)
2826
.length(24, `${fieldName} must be exactly 24 characters`)
2927
.regex(/^[0-9a-fA-F]+$/, `${fieldName} must contain only hexadecimal characters`),
28+
};
3029

31-
projectId: (): z.ZodString => AtlasArgs.objectId("projectId"),
30+
export const AtlasArgs = {
31+
projectId: (): z.ZodString => CommonArgs.objectId("projectId"),
3232

33-
organizationId: (): z.ZodString => AtlasArgs.objectId("organizationId"),
33+
organizationId: (): z.ZodString => CommonArgs.objectId("organizationId"),
3434

3535
clusterName: (): z.ZodString =>
3636
z

tests/unit/args.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,16 @@ describe("Tool args", () => {
5454
expect(() => schema.parse({})).toThrow();
5555
});
5656
});
57-
});
5857

59-
describe("AtlasArgs", () => {
6058
describe("objectId", () => {
6159
it("should validate 24-character hexadecimal strings", () => {
62-
const schema = AtlasArgs.objectId("Test ID");
60+
const schema = CommonArgs.objectId("Test ID");
6361
const validId = "507f1f77bcf86cd799439011";
6462
expect(schema.parse(validId)).toBe(validId);
6563
});
6664

6765
it("should reject invalid ObjectId formats", () => {
68-
const schema = AtlasArgs.objectId("Test ID");
66+
const schema = CommonArgs.objectId("Test ID");
6967

7068
// Too short
7169
expect(() => schema.parse("507f1f77bcf86cd79943901")).toThrow();
@@ -82,21 +80,23 @@ describe("Tool args", () => {
8280
});
8381

8482
it("should provide custom field name in error messages", () => {
85-
const schema = AtlasArgs.objectId("Custom Field");
83+
const schema = CommonArgs.objectId("Custom Field");
8684
expect(() => schema.parse("invalid")).toThrow("Custom Field must be exactly 24 characters");
8785
});
8886

8987
it("should not fail if the value is optional", () => {
90-
const schema = AtlasArgs.objectId("Custom Field").optional();
88+
const schema = CommonArgs.objectId("Custom Field").optional();
9189
expect(schema.parse(undefined)).toBeUndefined();
9290
});
9391

9492
it("should not fail if the value is empty", () => {
95-
const schema = AtlasArgs.objectId("Custom Field");
93+
const schema = CommonArgs.objectId("Custom Field");
9694
expect(() => schema.parse(undefined)).toThrow("Required");
9795
});
9896
});
97+
});
9998

99+
describe("AtlasArgs", () => {
100100
describe("projectId", () => {
101101
it("should validate project IDs", () => {
102102
const schema = AtlasArgs.projectId();

0 commit comments

Comments
 (0)