Skip to content

Commit 5097444

Browse files
authored
Merge pull request #7160 from Shopify/isaac/refactor-extension-module-spec-matching
Fix extension matching to support external identifiers
2 parents a767741 + d562fdc commit 5097444

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

packages/app/src/cli/services/context/breakdown-extensions.test.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,21 @@ const MODULE_CLI_A_NO_UID: AppModuleVersion = {
9090
},
9191
}
9292

93+
const MODULE_CLI_A_EXTERNAL_IDENTIFIER: AppModuleVersion = {
94+
registrationId: 'A',
95+
registrationUuid: 'UUID_A',
96+
registrationTitle: 'Checkout post purchase',
97+
type: 'checkout_post_purchase_external',
98+
specification: {
99+
identifier: 'checkout_post_purchase_external',
100+
name: 'Post purchase UI extension',
101+
experience: 'extension',
102+
options: {
103+
managementExperience: 'cli',
104+
},
105+
},
106+
}
107+
93108
const MODULE_DASHBOARD_MIGRATED_CLI_A: AppModuleVersion = {
94109
registrationId: 'A',
95110
registrationUuid: 'UUID_A',
@@ -567,6 +582,49 @@ describe('extensionsIdentifiersDeployBreakdown', () => {
567582
remoteExtensionsRegistrations: remoteExtensionRegistrations.app,
568583
})
569584
})
585+
586+
test('and there is an active version with a module matching a local spec external identifier then cli extension should be unchanged', async () => {
587+
// Given
588+
const extensionsToConfirm = {
589+
validMatches: {EXTENSION_A: 'UUID_A'},
590+
dashboardOnlyExtensions: [],
591+
extensionsToCreate: [],
592+
didMigrateDashboardExtensions: false,
593+
}
594+
vi.mocked(ensureExtensionsIds).mockResolvedValue(extensionsToConfirm)
595+
const remoteExtensionRegistrations = {
596+
app: {
597+
extensionRegistrations: [REGISTRATION_A],
598+
configurationRegistrations: [],
599+
dashboardManagedExtensionRegistrations: [],
600+
},
601+
}
602+
const activeAppVersion = {
603+
appModuleVersions: [MODULE_CLI_A_EXTERNAL_IDENTIFIER],
604+
}
605+
606+
const developerPlatformClient: DeveloperPlatformClient = testDeveloperPlatformClient({
607+
appExtensionRegistrations: (_app: MinimalAppIdentifiers) => Promise.resolve(remoteExtensionRegistrations),
608+
})
609+
610+
// When
611+
const result = await extensionsIdentifiersDeployBreakdown(
612+
await options({uiExtensions: [EXTENSION_A], developerPlatformClient, activeAppVersion}),
613+
)
614+
615+
// Then
616+
expect(result).toEqual({
617+
extensionIdentifiersBreakdown: {
618+
onlyRemote: [],
619+
toCreate: [],
620+
toUpdate: [],
621+
unchanged: [buildExtensionBreakdownInfo('EXTENSION_A', undefined)],
622+
},
623+
extensionsToConfirm,
624+
remoteExtensionsRegistrations: remoteExtensionRegistrations.app,
625+
})
626+
})
627+
570628
test('and there is an active version with matching dashboard migrated cli app modules then migrated extension should be returned in the to create', async () => {
571629
// Given
572630
const remoteExtensionRegistrations = {

packages/app/src/cli/services/context/breakdown-extensions.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,10 @@ function loadExtensionsIdentifiersBreakdown(
348348
developerPlatformClient: DeveloperPlatformClient,
349349
) {
350350
const extensionModules = activeAppVersion?.appModuleVersions.filter((ext) => {
351-
const spec = specs.find((spec) => spec.identifier === ext.specification?.identifier)
351+
const spec = specs.find(
352+
(spec) =>
353+
spec.identifier === ext.specification?.identifier || spec.externalIdentifier === ext.specification?.identifier,
354+
)
352355
return spec && !isAppConfigSpecification(spec)
353356
})
354357

0 commit comments

Comments
 (0)