@@ -82,6 +82,26 @@ describe('Error message generation', () => {
8282 'Network error' ,
8383 )
8484 expect ( new OperationError ( 'upload' , ErrorCodes . STAGED_UPLOAD_FAILED ) . message ) . toBe ( 'Failed to create staged upload' )
85+
86+ // Unauthorized errors
87+ expect (
88+ new OperationError ( 'export' , ErrorCodes . UNAUTHORIZED_EXPORT , { storeName : 'test-store.myshopify.com' } ) . message ,
89+ ) . toBe (
90+ "You are not authorized to export bulk data from store \"test-store.myshopify.com\"\n\nTo export you'll need the 'bulk data > export' permission" ,
91+ )
92+ expect (
93+ new OperationError ( 'import' , ErrorCodes . UNAUTHORIZED_IMPORT , { storeName : 'test-store.myshopify.com' } ) . message ,
94+ ) . toBe (
95+ "You are not authorized to import bulk data to store \"test-store.myshopify.com\"\n\nTo import you'll need the 'bulk data > import' permission" ,
96+ )
97+ expect (
98+ new OperationError ( 'copy' , ErrorCodes . UNAUTHORIZED_COPY , {
99+ sourceStoreName : 'source.myshopify.com' ,
100+ targetStoreName : 'target.myshopify.com' ,
101+ } ) . message ,
102+ ) . toBe (
103+ "You are not authorized to copy data between these stores\n\nTo export data from \"source.myshopify.com\"\n• You'll need the 'bulk data > export' permission\n\nTo import data to \"target.myshopify.com\"\n• You'll need the 'bulk data > import' permission" ,
104+ )
85105 } )
86106
87107 test ( 'should generate correct GRAPHQL_API_ERROR messages with request IDs' , ( ) => {
@@ -113,3 +133,96 @@ describe('OperationError with Request ID', () => {
113133 expect ( error . message ) . toContain ( 'Request Id: unknown' )
114134 } )
115135} )
136+
137+ describe ( 'Unauthorized Error Codes' , ( ) => {
138+ test ( 'should create UNAUTHORIZED_EXPORT error with store name' , ( ) => {
139+ const error = new OperationError ( 'startBulkDataStoreExport' , ErrorCodes . UNAUTHORIZED_EXPORT , {
140+ storeName : 'test-store.myshopify.com' ,
141+ } )
142+
143+ expect ( error ) . toBeInstanceOf ( OperationError )
144+ expect ( error . operation ) . toBe ( 'startBulkDataStoreExport' )
145+ expect ( error . code ) . toBe ( ErrorCodes . UNAUTHORIZED_EXPORT )
146+ expect ( error . params ) . toEqual ( { storeName : 'test-store.myshopify.com' } )
147+ expect ( error . message ) . toBe (
148+ "You are not authorized to export bulk data from store \"test-store.myshopify.com\"\n\nTo export you'll need the 'bulk data > export' permission" ,
149+ )
150+ } )
151+
152+ test ( 'should create UNAUTHORIZED_IMPORT error with store name' , ( ) => {
153+ const error = new OperationError ( 'startBulkDataStoreImport' , ErrorCodes . UNAUTHORIZED_IMPORT , {
154+ storeName : 'target-store.myshopify.com' ,
155+ } )
156+
157+ expect ( error ) . toBeInstanceOf ( OperationError )
158+ expect ( error . operation ) . toBe ( 'startBulkDataStoreImport' )
159+ expect ( error . code ) . toBe ( ErrorCodes . UNAUTHORIZED_IMPORT )
160+ expect ( error . params ) . toEqual ( { storeName : 'target-store.myshopify.com' } )
161+ expect ( error . message ) . toBe (
162+ "You are not authorized to import bulk data to store \"target-store.myshopify.com\"\n\nTo import you'll need the 'bulk data > import' permission" ,
163+ )
164+ } )
165+
166+ test ( 'should create UNAUTHORIZED_COPY error with source and target store names' , ( ) => {
167+ const error = new OperationError ( 'startBulkDataStoreCopy' , ErrorCodes . UNAUTHORIZED_COPY , {
168+ sourceStoreName : 'source.myshopify.com' ,
169+ targetStoreName : 'target.myshopify.com' ,
170+ } )
171+
172+ expect ( error ) . toBeInstanceOf ( OperationError )
173+ expect ( error . operation ) . toBe ( 'startBulkDataStoreCopy' )
174+ expect ( error . code ) . toBe ( ErrorCodes . UNAUTHORIZED_COPY )
175+ expect ( error . params ) . toEqual ( {
176+ sourceStoreName : 'source.myshopify.com' ,
177+ targetStoreName : 'target.myshopify.com' ,
178+ } )
179+ expect ( error . message ) . toBe (
180+ "You are not authorized to copy data between these stores\n\nTo export data from \"source.myshopify.com\"\n• You'll need the 'bulk data > export' permission\n\nTo import data to \"target.myshopify.com\"\n• You'll need the 'bulk data > import' permission" ,
181+ )
182+ } )
183+
184+ test ( 'should create unauthorized errors with request IDs' , ( ) => {
185+ const exportError = new OperationError (
186+ 'startBulkDataStoreExport' ,
187+ ErrorCodes . UNAUTHORIZED_EXPORT ,
188+ {
189+ storeName : 'test-store.myshopify.com' ,
190+ } ,
191+ 'export-request-123' ,
192+ )
193+
194+ expect ( exportError . requestId ) . toBe ( 'export-request-123' )
195+ expect ( exportError . message ) . toBe (
196+ "You are not authorized to export bulk data from store \"test-store.myshopify.com\"\n\nTo export you'll need the 'bulk data > export' permission" ,
197+ )
198+
199+ const importError = new OperationError (
200+ 'startBulkDataStoreImport' ,
201+ ErrorCodes . UNAUTHORIZED_IMPORT ,
202+ {
203+ storeName : 'test-store.myshopify.com' ,
204+ } ,
205+ 'import-request-456' ,
206+ )
207+
208+ expect ( importError . requestId ) . toBe ( 'import-request-456' )
209+ expect ( importError . message ) . toBe (
210+ "You are not authorized to import bulk data to store \"test-store.myshopify.com\"\n\nTo import you'll need the 'bulk data > import' permission" ,
211+ )
212+
213+ const copyError = new OperationError (
214+ 'startBulkDataStoreCopy' ,
215+ ErrorCodes . UNAUTHORIZED_COPY ,
216+ {
217+ sourceStoreName : 'source.myshopify.com' ,
218+ targetStoreName : 'target.myshopify.com' ,
219+ } ,
220+ 'copy-request-789' ,
221+ )
222+
223+ expect ( copyError . requestId ) . toBe ( 'copy-request-789' )
224+ expect ( copyError . message ) . toBe (
225+ "You are not authorized to copy data between these stores\n\nTo export data from \"source.myshopify.com\"\n• You'll need the 'bulk data > export' permission\n\nTo import data to \"target.myshopify.com\"\n• You'll need the 'bulk data > import' permission" ,
226+ )
227+ } )
228+ } )
0 commit comments