11import { renderCopyResult } from './copy_result.js'
2+ import { renderOperationResult } from './operation_result.js'
23import { Shop } from '../apis/destinations/index.js'
34import { BulkDataOperationByIdResponse } from '../apis/organizations/types.js'
4- import { renderWarning , renderSuccess } from '@shopify/cli-kit/node/ui'
55import { describe , expect , vi , test } from 'vitest'
66
7- vi . mock ( '@shopify/cli-kit/node/ui ' )
7+ vi . mock ( './operation_result.js ' )
88
99describe ( 'renderCopyResult' , ( ) => {
1010 const sourceShop : Shop = {
@@ -31,167 +31,34 @@ describe('renderCopyResult', () => {
3131 organizationId : 'org2' ,
3232 }
3333
34- test ( 'renders success when no errors' , ( ) => {
35- const copyOperation : BulkDataOperationByIdResponse = {
36- organization : {
37- name : 'Test Organization' ,
38- bulkData : {
39- operation : {
40- id : 'bulk-op-1' ,
41- operationType : 'COPY' ,
42- status : 'COMPLETED' ,
43- sourceStore : {
44- id : '1' ,
45- name : 'Source Store' ,
46- } ,
47- targetStore : {
48- id : '2' ,
49- name : 'Target Store' ,
50- } ,
51- storeOperations : [
52- {
53- id : 'op1' ,
54- store : {
55- id : '1' ,
56- name : 'Store 1' ,
57- } ,
58- remoteOperationType : 'EXPORT' ,
59- remoteOperationStatus : 'COMPLETED' ,
60- totalObjectCount : 100 ,
61- completedObjectCount : 100 ,
62- url : 'https://example.com/results' ,
63- } ,
64- ] ,
34+ const mockOperation : BulkDataOperationByIdResponse = {
35+ organization : {
36+ name : 'Test Organization' ,
37+ bulkData : {
38+ operation : {
39+ id : 'bulk-op-1' ,
40+ operationType : 'COPY' ,
41+ status : 'COMPLETED' ,
42+ sourceStore : {
43+ id : '1' ,
44+ name : 'Source Store' ,
6545 } ,
66- } ,
67- } ,
68- }
69-
70- renderCopyResult ( sourceShop , targetShop , copyOperation )
71-
72- expect ( renderSuccess ) . toHaveBeenCalledWith ( {
73- body : [
74- 'Copy operation from' ,
75- { info : 'source-shop.myshopify.com' } ,
76- 'to' ,
77- { info : 'target-shop.myshopify.com' } ,
78- 'complete' ,
79- ] ,
80- } )
81- expect ( renderWarning ) . not . toHaveBeenCalled ( )
82- } )
83-
84- test ( 'renders warning when errors exist' , ( ) => {
85- const copyOperation : BulkDataOperationByIdResponse = {
86- organization : {
87- name : 'Test Organization' ,
88- bulkData : {
89- operation : {
90- id : 'bulk-op-1' ,
91- operationType : 'COPY' ,
92- status : 'COMPLETED' ,
93- sourceStore : {
94- id : '1' ,
95- name : 'Source Store' ,
96- } ,
97- targetStore : {
98- id : '2' ,
99- name : 'Target Store' ,
100- } ,
101- storeOperations : [
102- {
103- id : 'op1' ,
104- store : {
105- id : '1' ,
106- name : 'Store 1' ,
107- } ,
108- remoteOperationType : 'EXPORT' ,
109- remoteOperationStatus : 'FAILED' ,
110- totalObjectCount : 100 ,
111- completedObjectCount : 50 ,
112- url : 'https://example.com/results' ,
113- } ,
114- ] ,
115- } ,
116- } ,
117- } ,
118- }
119-
120- renderCopyResult ( sourceShop , targetShop , copyOperation )
121-
122- expect ( renderWarning ) . toHaveBeenCalledWith ( {
123- body : [
124- 'Copy operation from' ,
125- { info : 'source-shop.myshopify.com' } ,
126- 'to' ,
127- { info : 'target-shop.myshopify.com' } ,
128- 'completed with' ,
129- { error : 'errors' } ,
130- ] ,
131- } )
132- expect ( renderSuccess ) . not . toHaveBeenCalled ( )
133- } )
134-
135- test ( 'renders warning when some operations fail' , ( ) => {
136- const copyOperation : BulkDataOperationByIdResponse = {
137- organization : {
138- name : 'Test Organization' ,
139- bulkData : {
140- operation : {
141- id : 'bulk-op-1' ,
142- operationType : 'COPY' ,
143- status : 'COMPLETED' ,
144- sourceStore : {
145- id : '1' ,
146- name : 'Source Store' ,
147- } ,
148- targetStore : {
149- id : '2' ,
150- name : 'Target Store' ,
151- } ,
152- storeOperations : [
153- {
154- id : 'op1' ,
155- store : {
156- id : '1' ,
157- name : 'Store 1' ,
158- } ,
159- remoteOperationType : 'EXPORT' ,
160- remoteOperationStatus : 'COMPLETED' ,
161- totalObjectCount : 100 ,
162- completedObjectCount : 100 ,
163- url : 'https://example.com/results1' ,
164- } ,
165- {
166- id : 'op2' ,
167- store : {
168- id : '2' ,
169- name : 'Store 2' ,
170- } ,
171- remoteOperationType : 'IMPORT' ,
172- remoteOperationStatus : 'FAILED' ,
173- totalObjectCount : 100 ,
174- completedObjectCount : 50 ,
175- url : 'https://example.com/results2' ,
176- } ,
177- ] ,
46+ targetStore : {
47+ id : '2' ,
48+ name : 'Target Store' ,
17849 } ,
50+ storeOperations : [ ] ,
17951 } ,
18052 } ,
181- }
53+ } ,
54+ }
18255
183- renderCopyResult ( sourceShop , targetShop , copyOperation )
56+ test ( 'calls renderOperationResult with correct base message' , ( ) => {
57+ renderCopyResult ( sourceShop , targetShop , mockOperation )
18458
185- expect ( renderWarning ) . toHaveBeenCalledWith ( {
186- body : [
187- 'Copy operation from' ,
188- { info : 'source-shop.myshopify.com' } ,
189- 'to' ,
190- { info : 'target-shop.myshopify.com' } ,
191- 'completed with' ,
192- { error : 'errors' } ,
193- ] ,
194- } )
195- expect ( renderSuccess ) . not . toHaveBeenCalled ( )
59+ expect ( renderOperationResult ) . toHaveBeenCalledWith (
60+ [ 'Copy operation from' , { info : 'source-shop.myshopify.com' } , 'to' , { info : 'target-shop.myshopify.com' } ] ,
61+ mockOperation ,
62+ )
19663 } )
19764} )
0 commit comments