@@ -99,7 +99,7 @@ describe('executeBulkOperation', () => {
9999 expect ( runBulkOperationQuery ) . not . toHaveBeenCalled ( )
100100 } )
101101
102- test ( 'passes variables to mutation when provided with `-- variables` flag ' , async ( ) => {
102+ test ( 'passes variables parameter to runBulkOperationMutation when variables are provided ' , async ( ) => {
103103 const mutation = 'mutation productUpdate($input: ProductInput!) { productUpdate(input: $input) { product { id } } }'
104104 const variables = '[{"input":{"id":"gid://shopify/Product/123","tags":["test"]}}]'
105105 const mockResponse = {
@@ -122,7 +122,7 @@ describe('executeBulkOperation', () => {
122122 } )
123123 } )
124124
125- test ( 'renders success message when bulk operation is created ' , async ( ) => {
125+ test ( 'renders success message when bulk operation returns without user errors ' , async ( ) => {
126126 const query = '{ products { edges { node { id } } } }'
127127 const mockResponse = {
128128 bulkOperation : successfulBulkOperation ,
@@ -141,7 +141,7 @@ describe('executeBulkOperation', () => {
141141 } )
142142 } )
143143
144- test ( 'renders warning when user errors are present ' , async ( ) => {
144+ test ( 'renders warning with formatted field errors when bulk operation returns user errors ' , async ( ) => {
145145 const query = '{ products { edges { node { id } } } }'
146146 const mockResponse = {
147147 bulkOperation : null ,
@@ -165,4 +165,55 @@ describe('executeBulkOperation', () => {
165165
166166 expect ( renderSuccess ) . not . toHaveBeenCalled ( )
167167 } )
168+
169+ test ( 'throws GraphQL syntax error when given malformed GraphQL document' , async ( ) => {
170+ const malformedQuery = '{ products { edges { node { id } }'
171+
172+ await expect (
173+ executeBulkOperation ( {
174+ app : mockApp ,
175+ storeFqdn,
176+ query : malformedQuery ,
177+ } ) ,
178+ ) . rejects . toThrow ( 'Syntax Error' )
179+
180+ expect ( runBulkOperationQuery ) . not . toHaveBeenCalled ( )
181+ expect ( runBulkOperationMutation ) . not . toHaveBeenCalled ( )
182+ } )
183+
184+ test ( 'throws error when GraphQL document contains multiple operation definitions' , async ( ) => {
185+ const multipleOperations =
186+ 'mutation { productUpdate(input: {}) { product { id } } } mutation { productDelete(input: {}) { deletedProductId } }'
187+
188+ await expect (
189+ executeBulkOperation ( {
190+ app : mockApp ,
191+ storeFqdn,
192+ query : multipleOperations ,
193+ } ) ,
194+ ) . rejects . toThrow ( 'Multiple operations are not supported' )
195+
196+ expect ( runBulkOperationQuery ) . not . toHaveBeenCalled ( )
197+ expect ( runBulkOperationMutation ) . not . toHaveBeenCalled ( )
198+ } )
199+
200+ test ( 'throws error when GraphQL document contains no operation definitions' , async ( ) => {
201+ const noOperations = `
202+ fragment ProductFields on Product {
203+ id
204+ title
205+ }
206+ `
207+
208+ await expect (
209+ executeBulkOperation ( {
210+ app : mockApp ,
211+ storeFqdn,
212+ query : noOperations ,
213+ } ) ,
214+ ) . rejects . toThrow ( 'must contain exactly one operation definition' )
215+
216+ expect ( runBulkOperationQuery ) . not . toHaveBeenCalled ( )
217+ expect ( runBulkOperationMutation ) . not . toHaveBeenCalled ( )
218+ } )
168219} )
0 commit comments