-
Notifications
You must be signed in to change notification settings - Fork 220
Introduce --output-file flag, write bulk operation results to STDOUT or a file
#6656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import {downloadBulkOperationResults} from './download-bulk-operation-results.js' | ||
| import {fetch} from '@shopify/cli-kit/node/http' | ||
| import {describe, test, expect, vi} from 'vitest' | ||
|
|
||
| vi.mock('@shopify/cli-kit/node/http') | ||
|
|
||
| describe('downloadBulkOperationResults', () => { | ||
| test('returns text content when fetch is successful', async () => { | ||
| const mockUrl = 'https://example.com/results.jsonl' | ||
| const mockContent = '{"id":"gid://shopify/Product/123"}\n{"id":"gid://shopify/Product/456"}' | ||
|
|
||
| vi.mocked(fetch).mockResolvedValue({ | ||
| ok: true, | ||
| text: async () => mockContent, | ||
| } as Awaited<ReturnType<typeof fetch>>) | ||
|
|
||
| const result = await downloadBulkOperationResults(mockUrl) | ||
|
|
||
| expect(fetch).toHaveBeenCalledWith(mockUrl) | ||
| expect(result).toBe(mockContent) | ||
ericlee878 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }) | ||
|
|
||
| test('throws error when fetch fails', async () => { | ||
| const mockUrl = 'https://example.com/results.jsonl' | ||
|
|
||
| vi.mocked(fetch).mockResolvedValue({ | ||
| ok: false, | ||
| statusText: 'Not Found', | ||
| } as Awaited<ReturnType<typeof fetch>>) | ||
|
|
||
| await expect(downloadBulkOperationResults(mockUrl)).rejects.toThrow( | ||
| 'Failed to download bulk operation results: Not Found', | ||
| ) | ||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import {fetch} from '@shopify/cli-kit/node/http' | ||
| import {AbortError} from '@shopify/cli-kit/node/error' | ||
|
|
||
| export async function downloadBulkOperationResults(url: string): Promise<string> { | ||
| const response = await fetch(url) | ||
|
|
||
| if (!response.ok) { | ||
| throw new AbortError(`Failed to download bulk operation results: ${response.statusText}`) | ||
| } | ||
|
|
||
| return response.text() | ||
| } | ||
|
Comment on lines
+4
to
+12
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why have this function in a different file? is just wrapping a call to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah good question! It's really small and like you said, doesnt have any complexity to test. I waffled on whether it should be in its own file, and ultimately decided to, because we're going to want the same behaviour in the I'm happy to just duplicate the function in both |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory, if you add this it will throw an error when used without
watchThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I tried this and it didn't work for me:
but maybe I'm missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know and I'm happy to add this in a followup though :)