Skip to content

Commit fb15f26

Browse files
authored
Merge pull request #6076 from Shopify/download-result-file-from-copy
Add download link to copy operation results
2 parents 76871da + 05b8f3b commit fb15f26

File tree

7 files changed

+279
-445
lines changed

7 files changed

+279
-445
lines changed

packages/store/src/apis/organizations/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export interface BulkDataOperationByIdResponse {
105105
remoteOperationStatus: string
106106
totalObjectCount: number
107107
completedObjectCount: number
108-
url: string
108+
url?: string
109109
}[]
110110
}
111111
}
Lines changed: 25 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {renderCopyResult} from './copy_result.js'
2+
import {renderOperationResult} from './operation_result.js'
23
import {Shop} from '../apis/destinations/index.js'
34
import {BulkDataOperationByIdResponse} from '../apis/organizations/types.js'
4-
import {renderWarning, renderSuccess} from '@shopify/cli-kit/node/ui'
55
import {describe, expect, vi, test} from 'vitest'
66

7-
vi.mock('@shopify/cli-kit/node/ui')
7+
vi.mock('./operation_result.js')
88

99
describe('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
})
Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,13 @@
1+
import {renderOperationResult} from './operation_result.js'
12
import {Shop} from '../apis/destinations/index.js'
23
import {BulkDataOperationByIdResponse} from '../apis/organizations/types.js'
3-
import {Token, renderWarning, renderSuccess} from '@shopify/cli-kit/node/ui'
4+
import {Token} from '@shopify/cli-kit/node/ui'
45

56
export function renderCopyResult(
67
sourceShop: Shop,
78
targetShop: Shop,
89
copyOperation: BulkDataOperationByIdResponse,
910
): void {
1011
const msg: Token[] = [`Copy operation from`, {info: sourceShop.domain}, `to`, {info: targetShop.domain}]
11-
12-
const storeOperations = copyOperation.organization.bulkData.operation.storeOperations
13-
const hasErrors = storeOperations.some((op) => op.remoteOperationStatus === 'FAILED')
14-
15-
if (hasErrors) {
16-
msg.push(`completed with`)
17-
msg.push({error: `errors`})
18-
renderWarning({
19-
body: msg,
20-
})
21-
} else {
22-
msg.push('complete')
23-
renderSuccess({
24-
body: msg,
25-
})
26-
}
12+
renderOperationResult(msg, copyOperation)
2713
}

0 commit comments

Comments
 (0)