|
1 | | -import {testBulkOperation, testBulkOperationContext} from '../../../services/bulk-operations/bulk-operation.test-data.js' |
2 | 1 | import BulkStatus from './status.js' |
3 | 2 | import BulkCancel from './cancel.js' |
| 3 | +import { |
| 4 | + testBulkOperation, |
| 5 | + testBulkOperationContext, |
| 6 | +} from '../../../services/bulk-operations/bulk-operation.test-data.js' |
4 | 7 | import {prepareAppStoreContext} from '../../../utilities/execute-command-helpers.js' |
5 | 8 | import {createAdminSessionAsApp, resolveApiVersion} from '../../../services/graphql/common.js' |
6 | 9 | import { |
7 | 10 | bulkOperationStatusJsonOutputSchema, |
8 | 11 | cancelBulkOperationJsonOutputSchema, |
9 | | - |
10 | 12 | } from '../../../services/bulk-operations/types.js' |
11 | | -import {fetchBulkOperationById, fetchRecentBulkOperations, cancelBulkOperationRequest} from '@shopify/cli-kit/node/api/bulk-operations' |
| 13 | +import { |
| 14 | + fetchBulkOperationById, |
| 15 | + fetchRecentBulkOperations, |
| 16 | + cancelBulkOperationRequest, |
| 17 | +} from '@shopify/cli-kit/node/api/bulk-operations' |
12 | 18 | import {ensureAuthenticatedAdminAsApp} from '@shopify/cli-kit/node/session' |
13 | 19 | import {runWithCommandEventsForCommand} from '@shopify/cli-kit/node/command-events' |
14 | 20 | import {withCapturedStandardStreams} from '@shopify/cli-kit/node/testing/output' |
@@ -45,7 +51,11 @@ afterEach(() => { |
45 | 51 | }) |
46 | 52 |
|
47 | 53 | function bulkOperation(overrides: Partial<BulkOperation> = {}): BulkOperation { |
48 | | -return testBulkOperation({objectCount: '900719925474099312345', createdAt: '2026-09-01T02:00:00.789+02:00', ...overrides}) |
| 54 | + return testBulkOperation({ |
| 55 | + objectCount: '900719925474099312345', |
| 56 | + createdAt: '2026-09-01T02:00:00.789+02:00', |
| 57 | + ...overrides, |
| 58 | + }) |
49 | 59 | } |
50 | 60 |
|
51 | 61 | function expectedOperation() { |
@@ -146,47 +156,57 @@ test('cancellation emits one result through the real service, codec, presenter, |
146 | 156 | }) |
147 | 157 | }) |
148 | 158 |
|
149 | | -test.each([ |
150 | | - {name: 'cancel', Command: BulkCancel}, |
151 | | - ])('$name user errors reach the fatal envelope without a success document', async ({Command}) => { |
152 | | - const userErrors = [{field: ['id'], message: 'Operation rejected'}] |
153 | | - vi.mocked(cancelBulkOperationRequest).mockResolvedValue({bulkOperation: null, userErrors}) |
154 | | - |
155 | | - vi.stubEnv('SHOPIFY_FLAG_JSON', '1') |
156 | | - await withCapturedStandardStreams(async ({stdout, stderr}) => { |
157 | | - const argv = ['--id', '123'] |
158 | | - try { |
159 | | - await runCommand(Command, [...argv, '--json']) |
160 | | - expect.fail('The command must reject the operation.') |
161 | | - } catch (error) { |
162 | | - if (!(error instanceof AbortError)) throw error |
163 | | - expect(error).toMatchObject({details: {userErrors}}) |
164 | | - expect(stdout()).toBe('') |
165 | | - await handler(error) |
166 | | - } |
167 | | - expect(JSON.parse(stdout())).toMatchObject({error: {type: 'abort', details: {userErrors}}}) |
168 | | - assertDiagnosticEvents(stderr(), 'Canceling bulk operation.') |
169 | | - }) |
170 | | -}) |
| 159 | +test.each([{name: 'cancel', Command: BulkCancel}])( |
| 160 | + '$name user errors reach the fatal envelope without a success document', |
| 161 | + async ({Command}) => { |
| 162 | + const userErrors = [{field: ['id'], message: 'Operation rejected'}] |
| 163 | + vi.mocked(cancelBulkOperationRequest).mockResolvedValue({bulkOperation: null, userErrors}) |
| 164 | + |
| 165 | + vi.stubEnv('SHOPIFY_FLAG_JSON', '1') |
| 166 | + await withCapturedStandardStreams(async ({stdout, stderr}) => { |
| 167 | + const argv = ['--id', '123'] |
| 168 | + try { |
| 169 | + await runCommand(Command, [...argv, '--json']) |
| 170 | + expect.fail('The command must reject the operation.') |
| 171 | + } catch (error) { |
| 172 | + if (!(error instanceof AbortError)) throw error |
| 173 | + expect(error).toMatchObject({details: {userErrors}}) |
| 174 | + expect(stdout()).toBe('') |
| 175 | + await handler(error) |
| 176 | + } |
| 177 | + expect(JSON.parse(stdout())).toMatchObject({error: {type: 'abort', details: {userErrors}}}) |
| 178 | + assertDiagnosticEvents(stderr(), 'Canceling bulk operation.') |
| 179 | + }) |
| 180 | + }, |
| 181 | +) |
171 | 182 |
|
172 | 183 | test.each([ |
173 | 184 | {name: 'status', Command: BulkStatus, schema: bulkOperationStatusJsonOutputSchema}, |
174 | 185 | {name: 'cancel', Command: BulkCancel, schema: cancelBulkOperationJsonOutputSchema}, |
175 | | - |
176 | 186 | ] as const)('exposes the schema, JSON flag, and help for $name', ({Command, schema}) => { |
177 | 187 | expect(Command.jsonOutputSchema).toBe(schema) |
178 | 188 | expect(Command.flags.json).toBeDefined() |
179 | 189 | expect(Command.baseFlags).toHaveProperty('json-schema') |
180 | 190 | expect(Command.descriptionForHelp()).toContain(schema.name) |
181 | 191 | }) |
182 | | -test.each([{json: true, noInput: false}, {json: true, noInput: true}, {json: false, noInput: false}, {json: false, noInput: true}])('status keeps output mode $json independent from input policy $noInput', async ({json, noInput}) => { |
| 192 | +test.each([ |
| 193 | + {json: true, noInput: false}, |
| 194 | + {json: true, noInput: true}, |
| 195 | + {json: false, noInput: false}, |
| 196 | + {json: false, noInput: true}, |
| 197 | +])('status keeps output mode $json independent from input policy $noInput', async ({json, noInput}) => { |
183 | 198 | vi.mocked(fetchBulkOperationById).mockResolvedValue(bulkOperation()) |
184 | 199 | const argv = ['--id', '123', ...(json ? ['--json'] : []), ...(noInput ? ['--no-input'] : [])] |
185 | 200 | await withCapturedStandardStreams(async ({stdout, stderr}) => { |
186 | 201 | const result = await runCommand(BulkStatus, argv) |
187 | 202 | expect(result.app).toBeDefined() |
188 | 203 | if (json) { |
189 | | - expect(JSON.parse(stdout())).toEqual({storeDomain: 'shop.myshopify.com', apiVersion: '2026-01', operationGid: 'gid://shopify/BulkOperation/123', operation: expectedOperation()}) |
| 204 | + expect(JSON.parse(stdout())).toEqual({ |
| 205 | + storeDomain: 'shop.myshopify.com', |
| 206 | + apiVersion: '2026-01', |
| 207 | + operationGid: 'gid://shopify/BulkOperation/123', |
| 208 | + operation: expectedOperation(), |
| 209 | + }) |
190 | 210 | assertDiagnosticEvents(stderr(), 'Checking bulk operation status.') |
191 | 211 | } else { |
192 | 212 | expect(stdout()).toBe('') |
|
0 commit comments