Skip to content

Commit d9c3526

Browse files
authored
fix: rename --json to --json-data on members update command (#8)
The --json option on members update shadowed the global --json output flag, preventing users from getting JSON output on this command. Renamed to --json-data to resolve the conflict. Co-authored-by: Ben Sabic <bensabic@users.noreply.github.com>
1 parent acf14c6 commit d9c3526

3 files changed

Lines changed: 49 additions & 4 deletions

File tree

src/commands/members.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ membersCommand
377377
[]
378378
)
379379
.option("--meta-data <key=value>", "Metadata field (repeatable)", collect, [])
380-
.option("--json <json>", "JSON data (as JSON string)")
380+
.option("--json-data <json>", "JSON data (as JSON string)")
381381
.option("--login-redirect <url>", "Login redirect URL")
382382
.action(async (id: string, options: MembersUpdateOptions) => {
383383
const spinner = yoctoSpinner({ text: "Updating member..." }).start();
@@ -399,8 +399,8 @@ membersCommand
399399
if (options.metaData?.length) {
400400
input.metaData = parseKeyValuePairs(options.metaData);
401401
}
402-
if (options.json) {
403-
input.json = parseJsonString(options.json);
402+
if (options.jsonData) {
403+
input.json = parseJsonString(options.jsonData);
404404
}
405405
if (options.loginRedirect) {
406406
input.loginRedirect = options.loginRedirect;

src/lib/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export interface MembersCreateOptions {
152152
export interface MembersUpdateOptions {
153153
customFields?: string[];
154154
email?: string;
155-
json?: string;
155+
jsonData?: string;
156156
loginRedirect?: string;
157157
metaData?: string[];
158158
}

tests/commands/members.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,51 @@ describe("members", () => {
160160
);
161161
});
162162

163+
it("update sends custom fields and meta data", async () => {
164+
graphqlRequest.mockResolvedValueOnce({ updateMember: mockMember });
165+
166+
await runCommand(membersCommand, [
167+
"update",
168+
"mem_1",
169+
"--meta-data",
170+
"source=cli",
171+
]);
172+
173+
const call = graphqlRequest.mock.calls[0][0];
174+
expect(call.variables.input.memberId).toBe("mem_1");
175+
expect(call.variables.input.metaData).toEqual({ source: "cli" });
176+
});
177+
178+
it("update sends --json-data as parsed JSON", async () => {
179+
graphqlRequest.mockResolvedValueOnce({ updateMember: mockMember });
180+
181+
await runCommand(membersCommand, [
182+
"update",
183+
"mem_1",
184+
"--json-data",
185+
'{"key":"value"}',
186+
]);
187+
188+
const call = graphqlRequest.mock.calls[0][0];
189+
expect(call.variables.input.memberId).toBe("mem_1");
190+
expect(call.variables.input.json).toEqual({ key: "value" });
191+
});
192+
193+
it("update accepts --json-data alongside global --json without conflict", async () => {
194+
graphqlRequest.mockResolvedValueOnce({ updateMember: mockMember });
195+
196+
await runCommand(membersCommand, [
197+
"update",
198+
"mem_1",
199+
"--json-data",
200+
'{"key":"value"}',
201+
"--json",
202+
]);
203+
204+
const call = graphqlRequest.mock.calls[0][0];
205+
expect(call.variables.input.json).toEqual({ key: "value" });
206+
});
207+
163208
it("handles errors gracefully", async () => {
164209
graphqlRequest.mockRejectedValueOnce(new Error("Unauthorized"));
165210

0 commit comments

Comments
 (0)