Skip to content

Commit 04d70e5

Browse files
authored
Merge pull request #6273 from Shopify/08-18-fix_extension_matching_after_changing_the_handle_post-migration
Fix extension matching after changing the handle post-migration
2 parents a1e2928 + 3563122 commit 04d70e5

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

packages/app/src/cli/services/context/id-matching.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,56 +14,56 @@ const REGISTRATION_A: RemoteSource = {
1414
uuid: 'UUID_A',
1515
id: 'A',
1616
title: 'EXTENSION_A',
17-
type: 'CHECKOUT_POST_PURCHASE',
17+
type: 'checkout_post_purchase',
1818
}
1919

2020
const REGISTRATION_A_2: RemoteSource = {
2121
uuid: 'UUID_A_2',
2222
id: 'A_2',
2323
title: 'EXTENSION_A_2',
24-
type: 'CHECKOUT_POST_PURCHASE',
24+
type: 'checkout_post_purchase',
2525
}
2626

2727
const REGISTRATION_A_3: RemoteSource = {
2828
uuid: 'UUID_A_3',
2929
id: 'A_3',
3030
title: 'EXTENSION_A_3',
31-
type: 'CHECKOUT_POST_PURCHASE',
31+
type: 'checkout_post_purchase',
3232
}
3333

3434
const REGISTRATION_A_4: RemoteSource = {
3535
uuid: 'UUID_A_4',
3636
id: 'A_4',
3737
title: 'EXTENSION_A_4',
38-
type: 'CHECKOUT_POST_PURCHASE',
38+
type: 'checkout_post_purchase',
3939
}
4040

4141
const REGISTRATION_B: RemoteSource = {
4242
uuid: 'UUID_B',
4343
id: 'B',
4444
title: 'EXTENSION_B',
45-
type: 'SUBSCRIPTION_MANAGEMENT',
45+
type: 'subscription_management',
4646
}
4747

4848
const REGISTRATION_C: RemoteSource = {
4949
uuid: 'UUID_C',
5050
id: 'C',
5151
title: 'EXTENSION_C',
52-
type: 'THEME_APP_EXTENSION',
52+
type: 'theme_app_extension',
5353
}
5454

5555
const REGISTRATION_D: RemoteSource = {
5656
uuid: 'UUID_D',
5757
id: 'D',
5858
title: 'EXTENSION_D',
59-
type: 'WEB_PIXEL_EXTENSION',
59+
type: 'web_pixel_extension',
6060
}
6161

6262
const REGISTRATION_FUNCTION_A: RemoteSource = {
6363
uuid: 'FUNCTION_UUID_A',
6464
id: 'FUNCTION_A',
6565
title: 'FUNCTION A',
66-
type: 'FUNCTION',
66+
type: 'function',
6767
draftVersion: {
6868
config: JSON.stringify({
6969
legacy_function_id: 'LEGACY_FUNCTION_ULID_A',

packages/app/src/cli/services/context/id-matching.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ function matchByUniqueType(
153153
const localGroups = groupBy(localSources, 'graphQLType')
154154
const localUnique = Object.values(pickBy(localGroups, (group, _key) => group.length === 1)).flat()
155155

156-
const remoteGroups = groupBy(remoteSources, 'type')
156+
const remoteWithNormalizedType = remoteSources.map((remote) => ({...remote, type: remote.type.toLowerCase()}))
157+
const remoteGroups = groupBy(remoteWithNormalizedType, 'type')
157158
const remoteUniqueMap = pickBy(remoteGroups, (group, _key) => group.length === 1)
158159

159160
const toConfirm: {local: LocalSource; remote: RemoteSource}[] = []
@@ -163,7 +164,7 @@ function matchByUniqueType(
163164
// - find a corresponding unique remote source and ask the user to confirm
164165
// - create it from scratch
165166
for (const local of localUnique) {
166-
const remote = remoteUniqueMap[local.graphQLType]
167+
const remote = remoteUniqueMap[local.graphQLType.toLowerCase()]
167168
if (remote && remote[0]) {
168169
toConfirm.push({local, remote: remote[0]})
169170
} else {
@@ -176,11 +177,11 @@ function matchByUniqueType(
176177
// it means that we need to create them.
177178
const localDuplicated = difference(localSources, localUnique)
178179
const remotePending = difference(
179-
remoteSources,
180+
remoteWithNormalizedType,
180181
toConfirm.map((elem) => elem.remote),
181182
)
182183
const [localPending, localToCreate] = partition(localDuplicated, (local) =>
183-
remotePending.map((remote) => remote.type).includes(local.graphQLType),
184+
remotePending.map((remote) => remote.type.toLowerCase()).includes(local.graphQLType.toLowerCase()),
184185
)
185186
toCreate.push(...localToCreate)
186187

0 commit comments

Comments
 (0)