|
| 1 | +import StoreBulkExecute from './execute.js' |
| 2 | +import {storeExecuteBulkOperation} from '../../../services/store-bulk-execute-operation.js' |
| 3 | +import {loadQuery} from '../../../utilities/execute-command-helpers.js' |
| 4 | +import {describe, expect, test, vi} from 'vitest' |
| 5 | + |
| 6 | +vi.mock('../../../services/store-bulk-execute-operation.js') |
| 7 | +vi.mock('../../../utilities/execute-command-helpers.js') |
| 8 | + |
| 9 | +describe('store bulk execute command', () => { |
| 10 | + test('requires --store flag', async () => { |
| 11 | + vi.mocked(loadQuery).mockResolvedValue('query { shop { name } }') |
| 12 | + vi.mocked(storeExecuteBulkOperation).mockResolvedValue() |
| 13 | + |
| 14 | + await expect( |
| 15 | + StoreBulkExecute.run(['--query', 'query { shop { name } }'], import.meta.url), |
| 16 | + ).rejects.toThrow() |
| 17 | + |
| 18 | + expect(storeExecuteBulkOperation).not.toHaveBeenCalled() |
| 19 | + }) |
| 20 | + |
| 21 | + test('calls storeExecuteBulkOperation with correct arguments', async () => { |
| 22 | + vi.mocked(loadQuery).mockResolvedValue('query { shop { name } }') |
| 23 | + vi.mocked(storeExecuteBulkOperation).mockResolvedValue() |
| 24 | + |
| 25 | + await StoreBulkExecute.run( |
| 26 | + ['--store', 'test-store.myshopify.com', '--query', 'query { shop { name } }'], |
| 27 | + import.meta.url, |
| 28 | + ) |
| 29 | + |
| 30 | + expect(loadQuery).toHaveBeenCalledWith( |
| 31 | + expect.objectContaining({query: 'query { shop { name } }'}), |
| 32 | + ) |
| 33 | + expect(storeExecuteBulkOperation).toHaveBeenCalledWith( |
| 34 | + expect.objectContaining({ |
| 35 | + storeFqdn: 'test-store.myshopify.com', |
| 36 | + query: 'query { shop { name } }', |
| 37 | + watch: false, |
| 38 | + }), |
| 39 | + ) |
| 40 | + }) |
| 41 | + |
| 42 | + test('passes version flag when provided', async () => { |
| 43 | + vi.mocked(loadQuery).mockResolvedValue('query { shop { name } }') |
| 44 | + vi.mocked(storeExecuteBulkOperation).mockResolvedValue() |
| 45 | + |
| 46 | + await StoreBulkExecute.run( |
| 47 | + ['--store', 'test-store.myshopify.com', '--query', 'query { shop { name } }', '--version', '2024-01'], |
| 48 | + import.meta.url, |
| 49 | + ) |
| 50 | + |
| 51 | + expect(storeExecuteBulkOperation).toHaveBeenCalledWith( |
| 52 | + expect.objectContaining({ |
| 53 | + version: '2024-01', |
| 54 | + }), |
| 55 | + ) |
| 56 | + }) |
| 57 | + |
| 58 | + test('passes watch and output-file flags when provided', async () => { |
| 59 | + vi.mocked(loadQuery).mockResolvedValue('query { shop { name } }') |
| 60 | + vi.mocked(storeExecuteBulkOperation).mockResolvedValue() |
| 61 | + |
| 62 | + await StoreBulkExecute.run( |
| 63 | + [ |
| 64 | + '--store', 'test-store.myshopify.com', |
| 65 | + '--query', 'query { shop { name } }', |
| 66 | + '--watch', |
| 67 | + '--output-file', '/tmp/out.jsonl', |
| 68 | + ], |
| 69 | + import.meta.url, |
| 70 | + ) |
| 71 | + |
| 72 | + expect(storeExecuteBulkOperation).toHaveBeenCalledWith( |
| 73 | + expect.objectContaining({ |
| 74 | + watch: true, |
| 75 | + outputFile: '/tmp/out.jsonl', |
| 76 | + }), |
| 77 | + ) |
| 78 | + }) |
| 79 | + |
| 80 | + test('passes variables flag when provided', async () => { |
| 81 | + vi.mocked(loadQuery).mockResolvedValue('mutation { productCreate { product { id } } }') |
| 82 | + vi.mocked(storeExecuteBulkOperation).mockResolvedValue() |
| 83 | + |
| 84 | + await StoreBulkExecute.run( |
| 85 | + [ |
| 86 | + '--store', 'test-store.myshopify.com', |
| 87 | + '--query', 'mutation { productCreate { product { id } } }', |
| 88 | + '--variables', '{"input": {"title": "test"}}', |
| 89 | + ], |
| 90 | + import.meta.url, |
| 91 | + ) |
| 92 | + |
| 93 | + expect(storeExecuteBulkOperation).toHaveBeenCalledWith( |
| 94 | + expect.objectContaining({ |
| 95 | + variables: ['{"input": {"title": "test"}}'], |
| 96 | + }), |
| 97 | + ) |
| 98 | + }) |
| 99 | +}) |
0 commit comments