Skip to content

Commit d3aee31

Browse files
authored
fix(wrangler): skip banner when outputing json with queues subscription commands (#10838)
1 parent 4c06766 commit d3aee31

File tree

7 files changed

+385
-78
lines changed

7 files changed

+385
-78
lines changed

.changeset/dark-hairs-build.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
fix: skip banner when using `--json` flag in `wrangler queues subscription` commands

packages/wrangler/src/__tests__/queues/__snapshots__/queues.test.ts.snap

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

33
exports[`wrangler > queues > create > wrangler.json > should create a queue 1`] = `
4-
"🌀 Creating queue 'testQueue'
4+
"
5+
⛅️ wrangler x.x.x
6+
──────────────────
7+
🌀 Creating queue 'testQueue'
58
✅ Created queue 'testQueue'
69
710
Configure your Worker to send messages to this queue:
@@ -30,7 +33,10 @@ Configure your Worker to consume messages from this queue:
3033
`;
3134

3235
exports[`wrangler > queues > create > wrangler.json > should send queue settings with delivery delay 1`] = `
33-
"🌀 Creating queue 'testQueue'
36+
"
37+
⛅️ wrangler x.x.x
38+
──────────────────
39+
🌀 Creating queue 'testQueue'
3440
✅ Created queue 'testQueue'
3541
3642
Configure your Worker to send messages to this queue:
@@ -59,7 +65,10 @@ Configure your Worker to consume messages from this queue:
5965
`;
6066

6167
exports[`wrangler > queues > create > wrangler.toml > should create a queue 1`] = `
62-
"🌀 Creating queue 'testQueue'
68+
"
69+
⛅️ wrangler x.x.x
70+
──────────────────
71+
🌀 Creating queue 'testQueue'
6372
✅ Created queue 'testQueue'
6473
6574
Configure your Worker to send messages to this queue:
@@ -76,7 +85,10 @@ queue = \\"testQueue\\"
7685
`;
7786

7887
exports[`wrangler > queues > create > wrangler.toml > should send queue settings with delivery delay 1`] = `
79-
"🌀 Creating queue 'testQueue'
88+
"
89+
⛅️ wrangler x.x.x
90+
──────────────────
91+
🌀 Creating queue 'testQueue'
8092
✅ Created queue 'testQueue'
8193
8294
Configure your Worker to send messages to this queue:

packages/wrangler/src/__tests__/queues/queues-subscription.test.ts

Lines changed: 195 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type {
1919
} from "../../queues/subscription-types";
2020

2121
describe("queues subscription", () => {
22+
vi.unmock("../../wrangler-banner");
2223
mockAccountId();
2324
mockApiToken();
2425
runInTempDir();
@@ -129,7 +130,10 @@ describe("queues subscription", () => {
129130
expect(createRequest.count).toEqual(1);
130131
expect(std.err).toMatchInlineSnapshot(`""`);
131132
expect(std.out).toMatchInlineSnapshot(`
132-
"Creating event subscription for queue 'testQueue'...
133+
"
134+
⛅️ wrangler x.x.x
135+
──────────────────
136+
Creating event subscription for queue 'testQueue'...
133137
✨ Successfully created event subscription 'testQueue workersBuilds.worker' with id 'sub-123'."
134138
`);
135139
});
@@ -172,7 +176,10 @@ describe("queues subscription", () => {
172176
expect(createRequest.count).toEqual(1);
173177
expect(std.err).toMatchInlineSnapshot(`""`);
174178
expect(std.out).toMatchInlineSnapshot(`
175-
"Creating event subscription for queue 'testQueue'...
179+
"
180+
⛅️ wrangler x.x.x
181+
──────────────────
182+
Creating event subscription for queue 'testQueue'...
176183
✨ Successfully created event subscription 'Custom Subscription' with id 'sub-123'."
177184
`);
178185
});
@@ -276,7 +283,10 @@ describe("queues subscription", () => {
276283
expect(listRequest.count).toEqual(1);
277284
expect(std.err).toMatchInlineSnapshot(`""`);
278285
expect(std.out).toMatchInlineSnapshot(`
279-
"No event subscriptions found for queue 'testQueue'."
286+
"
287+
⛅️ wrangler x.x.x
288+
──────────────────
289+
No event subscriptions found for queue 'testQueue'."
280290
`);
281291
});
282292

@@ -306,7 +316,10 @@ describe("queues subscription", () => {
306316
expect(listRequest.count).toEqual(1);
307317
expect(std.err).toMatchInlineSnapshot(`""`);
308318
expect(std.out).toMatchInlineSnapshot(`
309-
"Event subscriptions for queue 'testQueue':
319+
"
320+
⛅️ wrangler x.x.x
321+
──────────────────
322+
Event subscriptions for queue 'testQueue':
310323
┌─┬─┬─┬─┬─┬─┐
311324
│ ID │ Name │ Source │ Events │ Resource │ Enabled │
312325
├─┼─┼─┼─┼─┼─┤
@@ -317,6 +330,67 @@ describe("queues subscription", () => {
317330
`);
318331
});
319332

333+
it('supports json output with "--json" flag', async () => {
334+
mockGetQueueByNameRequest(expectedQueueName, {
335+
queue_id: expectedQueueId,
336+
queue_name: expectedQueueName,
337+
created_on: "",
338+
producers: [],
339+
consumers: [],
340+
producers_total_count: 0,
341+
consumers_total_count: 0,
342+
modified_on: "",
343+
});
344+
mockListSubscriptionsRequest(expectedQueueId, [
345+
mockSubscription1,
346+
mockSubscription2,
347+
]);
348+
349+
await runWrangler("queues subscription list testQueue --json");
350+
351+
expect(std.err).toMatchInlineSnapshot(`""`);
352+
expect(std.out).toMatchInlineSnapshot(`
353+
"[
354+
{
355+
\\"id\\": \\"sub-123\\",
356+
\\"created_at\\": \\"2024-01-01T00:00:00Z\\",
357+
\\"modified_at\\": \\"2024-01-01T00:00:00Z\\",
358+
\\"name\\": \\"Test Subscription 1\\",
359+
\\"enabled\\": true,
360+
\\"source\\": {
361+
\\"type\\": \\"workersBuilds.worker\\",
362+
\\"worker_name\\": \\"my-worker\\"
363+
},
364+
\\"destination\\": {
365+
\\"type\\": \\"queues.queue\\",
366+
\\"queue_id\\": \\"queueId\\"
367+
},
368+
\\"events\\": [
369+
\\"build.completed\\",
370+
\\"build.failed\\"
371+
]
372+
},
373+
{
374+
\\"id\\": \\"sub-456\\",
375+
\\"created_at\\": \\"2024-01-02T00:00:00Z\\",
376+
\\"modified_at\\": \\"2024-01-02T00:00:00Z\\",
377+
\\"name\\": \\"Test Subscription 2\\",
378+
\\"enabled\\": false,
379+
\\"source\\": {
380+
\\"type\\": \\"kv\\"
381+
},
382+
\\"destination\\": {
383+
\\"type\\": \\"queues.queue\\",
384+
\\"queue_id\\": \\"queueId\\"
385+
},
386+
\\"events\\": [
387+
\\"namespace.created\\"
388+
]
389+
}
390+
]"
391+
`);
392+
});
393+
320394
it("should show error when queue does not exist", async () => {
321395
const queueNameResolveRequest = mockGetQueueByNameRequest(
322396
"nonexistent",
@@ -380,7 +454,10 @@ describe("queues subscription", () => {
380454
expect(getRequest.count).toEqual(1);
381455
expect(std.err).toMatchInlineSnapshot(`""`);
382456
expect(std.out).toMatchInlineSnapshot(`
383-
"ID: sub-123
457+
"
458+
⛅️ wrangler x.x.x
459+
──────────────────
460+
ID: sub-123
384461
Name: Test Subscription 1
385462
Source: workersBuilds.worker
386463
Resource: my-worker
@@ -392,6 +469,47 @@ describe("queues subscription", () => {
392469
`);
393470
});
394471

472+
it('supports json output with "--json" flag', async () => {
473+
mockGetQueueByNameRequest("testQueue", {
474+
queue_id: expectedQueueId,
475+
queue_name: "testQueue",
476+
created_on: "",
477+
modified_on: "",
478+
producers: [],
479+
consumers: [],
480+
producers_total_count: 0,
481+
consumers_total_count: 0,
482+
});
483+
mockGetSubscriptionRequest("sub-123", mockSubscription1);
484+
485+
await runWrangler(
486+
"queues subscription get testQueue --id sub-123 --json"
487+
);
488+
489+
expect(std.err).toMatchInlineSnapshot(`""`);
490+
expect(std.out).toMatchInlineSnapshot(`
491+
"{
492+
\\"id\\": \\"sub-123\\",
493+
\\"created_at\\": \\"2024-01-01T00:00:00Z\\",
494+
\\"modified_at\\": \\"2024-01-01T00:00:00Z\\",
495+
\\"name\\": \\"Test Subscription 1\\",
496+
\\"enabled\\": true,
497+
\\"source\\": {
498+
\\"type\\": \\"workersBuilds.worker\\",
499+
\\"worker_name\\": \\"my-worker\\"
500+
},
501+
\\"destination\\": {
502+
\\"type\\": \\"queues.queue\\",
503+
\\"queue_id\\": \\"queueId\\"
504+
},
505+
\\"events\\": [
506+
\\"build.completed\\",
507+
\\"build.failed\\"
508+
]
509+
}"
510+
`);
511+
});
512+
395513
it("should show error when subscription does not exist", async () => {
396514
const getRequest = mockGetSubscriptionRequest("nonexistent-id", null);
397515

@@ -462,7 +580,10 @@ describe("queues subscription", () => {
462580
expect(deleteRequest.count).toEqual(1);
463581
expect(std.err).toMatchInlineSnapshot(`""`);
464582
expect(std.out).toMatchInlineSnapshot(`
465-
"✨ Successfully deleted event subscription 'Test Subscription 1' with id 'sub-123'."
583+
"
584+
⛅️ wrangler x.x.x
585+
──────────────────
586+
✨ Successfully deleted event subscription 'Test Subscription 1' with id 'sub-123'."
466587
`);
467588
});
468589

@@ -491,7 +612,10 @@ describe("queues subscription", () => {
491612
expect(deleteRequest.count).toEqual(1);
492613
expect(std.err).toMatchInlineSnapshot(`""`);
493614
expect(std.out).toMatchInlineSnapshot(`
494-
"✨ Successfully deleted event subscription 'Test Subscription 1' with id 'sub-123'."
615+
"
616+
⛅️ wrangler x.x.x
617+
──────────────────
618+
✨ Successfully deleted event subscription 'Test Subscription 1' with id 'sub-123'."
495619
`);
496620
});
497621

@@ -551,11 +675,74 @@ describe("queues subscription", () => {
551675

552676
expect(requests.count).toBe(1);
553677
expect(std.out).toMatchInlineSnapshot(`
554-
"Updating event subscription...
678+
"
679+
⛅️ wrangler x.x.x
680+
──────────────────
681+
Updating event subscription...
555682
✨ Successfully updated event subscription 'updated-subscription' with id 'subscription-123'."
556683
`);
557684
});
558685

686+
it('supports json output with "--json" flag', async () => {
687+
const subscriptionId = "subscription-123";
688+
mockGetQueueByNameRequest("test-queue", {
689+
queue_id: "queue-id-1",
690+
queue_name: "test-queue",
691+
created_on: "",
692+
modified_on: "",
693+
producers: [],
694+
consumers: [],
695+
producers_total_count: 0,
696+
consumers_total_count: 0,
697+
});
698+
mockUpdateSubscriptionRequest(subscriptionId, {
699+
name: "new-name",
700+
events: ["build.completed", "build.failed"],
701+
enabled: false,
702+
});
703+
mockGetSubscriptionRequest(subscriptionId, {
704+
id: subscriptionId,
705+
name: "old-subscription",
706+
source: {
707+
type: EventSourceType.WORKERS_BUILDS_WORKER,
708+
worker_name: "my-worker",
709+
},
710+
destination: {
711+
type: "queues.queue",
712+
queue_id: "queue-id-1",
713+
},
714+
events: ["build.completed"],
715+
enabled: true,
716+
created_at: "2023-01-01T00:00:00.000Z",
717+
modified_at: "2023-01-01T00:00:00.000Z",
718+
});
719+
720+
await runWrangler(
721+
`queues subscription update test-queue --id ${subscriptionId} --name new-name --events "build.completed,build.failed" --enabled false --json`
722+
);
723+
724+
expect(std.out).toMatchInlineSnapshot(`
725+
"Updating event subscription...
726+
{
727+
\\"id\\": \\"subscription-123\\",
728+
\\"name\\": \\"updated-subscription\\",
729+
\\"source\\": {
730+
\\"type\\": \\"workersBuilds.worker\\",
731+
\\"worker_name\\": \\"my-worker\\"
732+
},
733+
\\"destination\\": {
734+
\\"queue_id\\": \\"queue-id-1\\"
735+
},
736+
\\"events\\": [
737+
\\"build.completed\\",
738+
\\"build.failed\\"
739+
],
740+
\\"enabled\\": false,
741+
\\"modified_at\\": \\"2023-01-01T00:00:00.000Z\\"
742+
}"
743+
`);
744+
});
745+
559746
it("should error when no fields provided", async () => {
560747
const subscriptionId = "subscription-123";
561748
mockGetQueueByNameRequest("test-queue", {

0 commit comments

Comments
 (0)