Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ describe('executeBulkOperation', () => {
})
})

test('renders success message when bulk operation returns without user errors', async () => {
test('renders running message when bulk operation returns without user errors', async () => {
const query = '{ products { edges { node { id } } } }'
const mockResponse: BulkOperationRunQueryMutation['bulkOperationRunQuery'] = {
bulkOperation: createdBulkOperation,
Expand All @@ -197,7 +197,8 @@ describe('executeBulkOperation', () => {

expect(renderSuccess).toHaveBeenCalledWith(
expect.objectContaining({
headline: 'Bulk operation started.',
headline: 'Bulk operation is running.',
body: ['Monitor its progress with:\n', {command: expect.stringContaining('shopify app bulk status')}],
}),
)
})
Expand Down Expand Up @@ -453,6 +454,73 @@ describe('executeBulkOperation', () => {
)
})

test('renders running message when quickWatchBulkOperation returns COMPLETED status (does not download results)', async () => {
const query = '{ products { edges { node { id } } } }'
const completedOperation = {
...createdBulkOperation,
status: 'COMPLETED' as const,
url: 'https://example.com/download',
objectCount: '100',
}
const mockResponse: BulkOperationRunQueryMutation['bulkOperationRunQuery'] = {
bulkOperation: createdBulkOperation,
userErrors: [],
}

vi.mocked(runBulkOperationQuery).mockResolvedValue(mockResponse)
vi.mocked(shortBulkOperationPoll).mockResolvedValue(completedOperation)

await executeBulkOperation({
organization: mockOrganization,
remoteApp: mockRemoteApp,
store: mockStore,
query,
watch: false,
})

expect(renderSuccess).toHaveBeenCalledWith(
expect.objectContaining({
headline: 'Bulk operation is running.',
body: ['Monitor its progress with:\n', {command: expect.stringContaining('shopify app bulk status')}],
}),
)
expect(downloadBulkOperationResults).not.toHaveBeenCalled()
})

test.each(['FAILED', 'CANCELED', 'EXPIRED'] as const)(
'renders error when quickWatchBulkOperation returns %s status',
async (status) => {
const query = '{ products { edges { node { id } } } }'
const errorOperation = {
...createdBulkOperation,
status,
objectCount: '0',
}
const mockResponse: BulkOperationRunQueryMutation['bulkOperationRunQuery'] = {
bulkOperation: createdBulkOperation,
userErrors: [],
}

vi.mocked(runBulkOperationQuery).mockResolvedValue(mockResponse)
vi.mocked(shortBulkOperationPoll).mockResolvedValue(errorOperation)

await executeBulkOperation({
organization: mockOrganization,
remoteApp: mockRemoteApp,
store: mockStore,
query,
watch: false,
})

expect(renderError).toHaveBeenCalledWith(
expect.objectContaining({
headline: expect.any(String),
customSections: expect.any(Array),
}),
)
},
)

test('writes results to file when --output-file flag is provided', async () => {
const query = '{ products { edges { node { id } } } }'
const outputFile = '/tmp/results.jsonl'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,16 @@ export async function executeBulkOperation(input: ExecuteBulkOperationInput): Pr
}
} else {
const operation = await shortBulkOperationPoll(adminSession, createdOperation.id)
await renderBulkOperationResult(operation, outputFile)
const errorStatuses = ['FAILED', 'CANCELED', 'EXPIRED']
if (errorStatuses.includes(operation.status)) {
await renderBulkOperationResult(operation, outputFile)
} else {
renderSuccess({
headline: 'Bulk operation is running.',
body: statusCommandHelpMessage(operation.id),
customSections: [{body: [{list: {items: [outputContent`ID: ${outputToken.cyan(operation.id)}`.value]}}]}],
})
}
}
} else {
renderWarning({
Expand Down
11 changes: 1 addition & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading