Skip to content

Commit eca8fce

Browse files
committed
Show updated modules when migrating them to the new dev platform
1 parent c4fcd91 commit eca8fce

File tree

7 files changed

+125
-20
lines changed

7 files changed

+125
-20
lines changed

packages/app/src/cli/prompts/deploy-release.test.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ describe('deployOrReleaseConfirmationPrompt', () => {
126126
header: 'Extensions:',
127127
items: [
128128
{bullet: '+', item: ['to create extension', {subdued: '(new)'}], color: 'green'},
129-
'to update extension',
129+
{item: ['to update extension', {subdued: '(updated)'}], color: '#FF8800'},
130+
'unchanged extension',
130131
['from dashboard extension', {subdued: '(from Partner Dashboard)'}],
131132
],
132133
},
@@ -186,7 +187,8 @@ describe('deployOrReleaseConfirmationPrompt', () => {
186187
item: ['to create dashboard', {subdued: '(new, from Partner Dashboard)'}],
187188
color: 'green',
188189
},
189-
'to update extension',
190+
{item: ['to update extension', {subdued: '(updated)'}], color: '#FF8800'},
191+
'unchanged extension',
190192
['from dashboard extension', {subdued: '(from Partner Dashboard)'}],
191193
{bullet: '-', item: ['remote extension', {subdued: '(removed)'}], color: 'red'},
192194
{bullet: '-', item: ['remote dashboard', {subdued: '(removed, from Partner Dashboard)'}], color: 'red'},
@@ -238,7 +240,8 @@ describe('deployOrReleaseConfirmationPrompt', () => {
238240
header: 'Extensions:',
239241
items: [
240242
{bullet: '+', item: ['to create extension', {subdued: '(new)'}], color: 'green'},
241-
'to update extension',
243+
{item: ['to update extension', {subdued: '(updated)'}], color: '#FF8800'},
244+
'unchanged extension',
242245
['from dashboard extension', {subdued: '(from Partner Dashboard)'}],
243246
{bullet: '-', item: ['remote extension', {subdued: '(removed)'}], color: 'red'},
244247
],
@@ -282,7 +285,8 @@ describe('deployOrReleaseConfirmationPrompt', () => {
282285
header: 'Extensions:',
283286
items: [
284287
{bullet: '+', item: ['to create extension', {subdued: '(new)'}], color: 'green'},
285-
'to update extension',
288+
{item: ['to update extension', {subdued: '(updated)'}], color: '#FF8800'},
289+
'unchanged extension',
286290
['from dashboard extension', {subdued: '(from Partner Dashboard)'}],
287291
{bullet: '-', item: ['remote extension', {subdued: '(removed)'}], color: 'red'},
288292
],
@@ -334,7 +338,8 @@ describe('deployOrReleaseConfirmationPrompt', () => {
334338
helperText: 'Removing extensions can permanently delete app user data',
335339
items: [
336340
{bullet: '+', item: ['to create extension', {subdued: '(new)'}], color: 'green'},
337-
'to update extension',
341+
{item: ['to update extension', {subdued: '(updated)'}], color: '#FF8800'},
342+
'unchanged extension',
338343
['from dashboard extension', {subdued: '(from Partner Dashboard)'}],
339344
{bullet: '-', item: ['remote extension', {subdued: '(removed)'}], color: 'red'},
340345
],
@@ -389,7 +394,8 @@ describe('deployOrReleaseConfirmationPrompt', () => {
389394
header: 'Extensions:',
390395
items: [
391396
{bullet: '+', item: ['to create extension', {subdued: '(new)'}], color: 'green'},
392-
'to update extension',
397+
{item: ['to update extension', {subdued: '(updated)'}], color: '#FF8800'},
398+
'unchanged extension',
393399
['from dashboard extension', {subdued: '(from Partner Dashboard)'}],
394400
],
395401
},
@@ -429,11 +435,13 @@ function buildCompleteBreakdownInfo() {
429435

430436
emptyBreakdownInfo.extensionIdentifiersBreakdown.onlyRemote.push(buildExtensionBreakdownInfo('remote extension'))
431437
emptyBreakdownInfo.extensionIdentifiersBreakdown.toCreate.push(buildExtensionBreakdownInfo('to create extension'))
432-
emptyBreakdownInfo.extensionIdentifiersBreakdown.toUpdate.push(
433-
buildExtensionBreakdownInfo('to update extension'),
438+
emptyBreakdownInfo.extensionIdentifiersBreakdown.unchanged.push(
439+
buildExtensionBreakdownInfo('unchanged extension'),
434440
buildDashboardBreakdownInfo('from dashboard extension'),
435441
)
436442

443+
emptyBreakdownInfo.extensionIdentifiersBreakdown.toUpdate.push(buildExtensionBreakdownInfo('to update extension'))
444+
437445
emptyBreakdownInfo.configExtensionIdentifiersBreakdown!.existingFieldNames.push('existing field name1')
438446
emptyBreakdownInfo.configExtensionIdentifiersBreakdown!.existingUpdatedFieldNames.push('updating field name1')
439447
emptyBreakdownInfo.configExtensionIdentifiersBreakdown!.newFieldNames.push('new field name1')
@@ -457,6 +465,7 @@ function buildEmptyExtensionsBreakdownInfo(): ExtensionIdentifiersBreakdown {
457465
onlyRemote: [],
458466
toCreate: [],
459467
toUpdate: [],
468+
unchanged: [],
460469
}
461470
}
462471

packages/app/src/cli/prompts/deploy-release.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ async function deployConfirmationPrompt({
103103
}
104104

105105
async function buildExtensionsContentPrompt(extensionsContentBreakdown: ExtensionIdentifiersBreakdown) {
106-
const {onlyRemote, toCreate: toCreateBreakdown, toUpdate} = extensionsContentBreakdown
106+
const {onlyRemote, toCreate: toCreateBreakdown, toUpdate, unchanged} = extensionsContentBreakdown
107107

108108
const mapExtensionToInfoTableItem = (extension: ExtensionIdentifierBreakdownInfo, preffix: string) => {
109109
switch (extension.experience) {
@@ -116,7 +116,8 @@ async function buildExtensionsContentPrompt(extensionsContentBreakdown: Extensio
116116
let extensionsInfoTable
117117
const section = {
118118
new: toCreateBreakdown.map((extension) => mapExtensionToInfoTableItem(extension, 'new, ')),
119-
unchanged: toUpdate.map((extension) => mapExtensionToInfoTableItem(extension, '')),
119+
unchanged: unchanged.map((extension) => mapExtensionToInfoTableItem(extension, '')),
120+
updated: toUpdate.map((extension) => mapExtensionToInfoTableItem(extension, 'updated, ')),
120121
removed: onlyRemote.map((extension) => mapExtensionToInfoTableItem(extension, 'removed, ')),
121122
}
122123
const extensionsInfo = buildDeployReleaseInfoTableSection(section)

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

Lines changed: 77 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,21 @@ const MODULE_CLI_A: AppModuleVersion = {
7575
},
7676
}
7777

78+
const MODULE_CLI_A_NO_UID: AppModuleVersion = {
79+
registrationId: '',
80+
registrationUuid: 'UUID_A',
81+
registrationTitle: 'Checkout post purchase',
82+
type: 'checkout_post_purchase',
83+
specification: {
84+
identifier: 'checkout_post_purchase',
85+
name: 'Post purchase UI extension',
86+
experience: 'extension',
87+
options: {
88+
managementExperience: 'cli',
89+
},
90+
},
91+
}
92+
7893
const MODULE_DASHBOARD_MIGRATED_CLI_A: AppModuleVersion = {
7994
registrationId: 'A',
8095
registrationUuid: 'UUID_A',
@@ -413,6 +428,7 @@ describe('extensionsIdentifiersDeployBreakdown', () => {
413428
onlyRemote: [],
414429
toCreate: [],
415430
toUpdate: [buildExtensionBreakdownInfo('EXTENSION_A'), buildExtensionBreakdownInfo('extension-a-2')],
431+
unchanged: [],
416432
},
417433
extensionsToConfirm,
418434
remoteExtensionsRegistrations: remoteExtensionRegistrations.app,
@@ -453,6 +469,7 @@ describe('extensionsIdentifiersDeployBreakdown', () => {
453469
buildDashboardBreakdownInfo('Dashboard A'),
454470
],
455471
toUpdate: [],
472+
unchanged: [],
456473
},
457474
extensionsToConfirm,
458475
remoteExtensionsRegistrations: remoteExtensionRegistrations.app,
@@ -489,13 +506,14 @@ describe('extensionsIdentifiersDeployBreakdown', () => {
489506
extensionIdentifiersBreakdown: {
490507
onlyRemote: [],
491508
toCreate: [buildExtensionBreakdownInfo('EXTENSION_A'), buildExtensionBreakdownInfo('extension-a-2')],
492-
toUpdate: [buildDashboardBreakdownInfo('Dashboard A')],
509+
toUpdate: [],
510+
unchanged: [buildDashboardBreakdownInfo('Dashboard A')],
493511
},
494512
extensionsToConfirm,
495513
remoteExtensionsRegistrations: remoteExtensionRegistrations.app,
496514
})
497515
})
498-
test('and there is an active version with matching cli app modules then cli extension should be updated, and no dashboard extension should be migrated', async () => {
516+
test('and there is an active version with matching cli app modules then cli extension should be updated as "unchanged", and no dashboard extension should be migrated', async () => {
499517
// Given
500518
const extensionsToConfirm = {
501519
validMatches: {EXTENSION_A: 'UUID_A'},
@@ -534,7 +552,8 @@ describe('extensionsIdentifiersDeployBreakdown', () => {
534552
extensionIdentifiersBreakdown: {
535553
onlyRemote: [],
536554
toCreate: [buildExtensionBreakdownInfo('extension-a-2')],
537-
toUpdate: [buildExtensionBreakdownInfo('EXTENSION_A'), buildDashboardBreakdownInfo('Dashboard A')],
555+
toUpdate: [],
556+
unchanged: [buildExtensionBreakdownInfo('EXTENSION_A'), buildDashboardBreakdownInfo('Dashboard A')],
538557
},
539558
extensionsToConfirm,
540559
remoteExtensionsRegistrations: remoteExtensionRegistrations.app,
@@ -582,7 +601,8 @@ describe('extensionsIdentifiersDeployBreakdown', () => {
582601
buildExtensionBreakdownInfo('DASH_MIGRATED_EXTENSION_A'),
583602
buildExtensionBreakdownInfo('extension-a-2'),
584603
],
585-
toUpdate: [buildExtensionBreakdownInfo('EXTENSION_A'), buildDashboardBreakdownInfo('Dashboard A')],
604+
toUpdate: [],
605+
unchanged: [buildExtensionBreakdownInfo('EXTENSION_A'), buildDashboardBreakdownInfo('Dashboard A')],
586606
},
587607
extensionsToConfirm,
588608
remoteExtensionsRegistrations: remoteExtensionRegistrations.app,
@@ -638,7 +658,55 @@ describe('extensionsIdentifiersDeployBreakdown', () => {
638658
buildExtensionBreakdownInfo('extension-a-2'),
639659
buildDashboardBreakdownInfo('Dashboard New'),
640660
],
641-
toUpdate: [buildExtensionBreakdownInfo('EXTENSION_A'), buildDashboardBreakdownInfo('Dashboard A')],
661+
toUpdate: [],
662+
unchanged: [buildExtensionBreakdownInfo('EXTENSION_A'), buildDashboardBreakdownInfo('Dashboard A')],
663+
},
664+
extensionsToConfirm,
665+
remoteExtensionsRegistrations: remoteExtensionRegistrations.app,
666+
})
667+
})
668+
669+
test('and there is an active version with modules without UID, those should be returned as toUpdate, the rest, unchanged', async () => {
670+
// Given
671+
const extensionsToConfirm = {
672+
validMatches: {EXTENSION_A: 'UUID_A'},
673+
dashboardOnlyExtensions: [REGISTRATION_DASHBOARD_A],
674+
extensionsToCreate: [EXTENSION_A_2],
675+
didMigrateDashboardExtensions: false,
676+
}
677+
vi.mocked(ensureExtensionsIds).mockResolvedValue(extensionsToConfirm)
678+
const remoteExtensionRegistrations = {
679+
app: {
680+
extensionRegistrations: [REGISTRATION_A],
681+
configurationRegistrations: [],
682+
dashboardManagedExtensionRegistrations: [REGISTRATION_DASHBOARD_A],
683+
},
684+
}
685+
const activeAppVersion = {
686+
appModuleVersions: [MODULE_CONFIG_A, MODULE_DASHBOARD_A, MODULE_CLI_A_NO_UID],
687+
}
688+
let fetchActiveAppVersionCalled = false
689+
const developerPlatformClient: DeveloperPlatformClient = testDeveloperPlatformClient({
690+
appExtensionRegistrations: (_app: MinimalAppIdentifiers) => Promise.resolve(remoteExtensionRegistrations),
691+
activeAppVersion: (_app: MinimalAppIdentifiers) => {
692+
fetchActiveAppVersionCalled = true
693+
return Promise.resolve(activeAppVersion)
694+
},
695+
})
696+
697+
// When
698+
const result = await extensionsIdentifiersDeployBreakdown(
699+
await options({uiExtensions, developerPlatformClient, activeAppVersion}),
700+
)
701+
702+
// Then
703+
expect(fetchActiveAppVersionCalled).toBe(false)
704+
expect(result).toEqual({
705+
extensionIdentifiersBreakdown: {
706+
onlyRemote: [],
707+
toCreate: [buildExtensionBreakdownInfo('extension-a-2')],
708+
toUpdate: [buildExtensionBreakdownInfo('EXTENSION_A')],
709+
unchanged: [buildDashboardBreakdownInfo('Dashboard A')],
642710
},
643711
extensionsToConfirm,
644712
remoteExtensionsRegistrations: remoteExtensionRegistrations.app,
@@ -676,6 +744,7 @@ describe('extensionsIdentifiersReleaseBreakdown', () => {
676744
onlyRemote: [],
677745
toCreate: [],
678746
toUpdate: [],
747+
unchanged: [],
679748
},
680749
versionDetails: versionDiff.versionDetails,
681750
})
@@ -708,7 +777,8 @@ describe('extensionsIdentifiersReleaseBreakdown', () => {
708777
extensionIdentifiersBreakdown: {
709778
onlyRemote: [buildExtensionBreakdownInfo('Checkout post purchase Deleted B')],
710779
toCreate: [buildExtensionBreakdownInfo('Checkout post purchase')],
711-
toUpdate: [buildDashboardBreakdownInfo('Dashboard A')],
780+
toUpdate: [],
781+
unchanged: [buildDashboardBreakdownInfo('Dashboard A')],
712782
},
713783
versionDetails: versionDiff.versionDetails,
714784
})
@@ -742,6 +812,7 @@ describe('extensionsIdentifiersReleaseBreakdown', () => {
742812
toCreate: [],
743813
toUpdate: [],
744814
onlyRemote: [buildExtensionBreakdownInfo('Checkout post purchase Deleted B')],
815+
unchanged: [],
745816
},
746817
versionDetails: versionDiff.versionDetails,
747818
})

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export interface ExtensionIdentifiersBreakdown {
4848
onlyRemote: ExtensionIdentifierBreakdownInfo[]
4949
toCreate: ExtensionIdentifierBreakdownInfo[]
5050
toUpdate: ExtensionIdentifierBreakdownInfo[]
51+
unchanged: ExtensionIdentifierBreakdownInfo[]
5152
}
5253

5354
export async function extensionsIdentifiersDeployBreakdown(options: EnsureDeploymentIdsPresenceOptions): Promise<{
@@ -116,7 +117,8 @@ export async function extensionsIdentifiersReleaseBreakdown(
116117
const extensionIdentifiersBreakdown = {
117118
onlyRemote: [...mapIsExtension(versionsDiff.removed), ...mapIsDashboard(versionsDiff.removed)],
118119
toCreate: [...mapIsExtension(versionsDiff.added), ...mapIsDashboard(versionsDiff.added)],
119-
toUpdate: [...mapIsExtension(versionsDiff.updated), ...mapIsDashboard(versionsDiff.updated)],
120+
toUpdate: [],
121+
unchanged: [...mapIsExtension(versionsDiff.updated), ...mapIsDashboard(versionsDiff.updated)],
120122
}
121123

122124
return {extensionIdentifiersBreakdown, versionDetails}
@@ -326,6 +328,7 @@ function loadLocalExtensionsIdentifiersBreakdown({
326328
return {
327329
onlyRemote: [] as ExtensionIdentifierBreakdownInfo[],
328330
toCreate: [] as ExtensionIdentifierBreakdownInfo[],
331+
unchanged: [] as ExtensionIdentifierBreakdownInfo[],
329332
toUpdate: [...identifiersToUpdate, ...identifiersToCreate, ...dashboardToUpdate],
330333
}
331334
}
@@ -355,6 +358,7 @@ async function resolveRemoteExtensionIdentifiersBreakdown(
355358
onlyRemote: [...extensionIdentifiersBreakdown.onlyRemote, ...dashboardIdentifiersBreakdown.onlyRemote],
356359
toCreate: [...extensionIdentifiersBreakdown.toCreate, ...dashboardIdentifiersBreakdown.toCreate],
357360
toUpdate: [...extensionIdentifiersBreakdown.toUpdate, ...dashboardIdentifiersBreakdown.toUpdate],
361+
unchanged: [...extensionIdentifiersBreakdown.unchanged, ...dashboardIdentifiersBreakdown.unchanged],
358362
}
359363
}
360364

@@ -372,10 +376,21 @@ function loadExtensionsIdentifiersBreakdown(
372376
return module.registrationUuid === identifier || module.registrationId === identifier
373377
}
374378

375-
const extensionsToUpdate = Object.entries(localRegistration)
379+
const allExistingExtensions = Object.entries(localRegistration)
376380
.filter(([_identifier, uuid]) => extensionModules.some((module) => moduleHasUUIDorUID(module, uuid)))
377381
.map(([identifier, _uuid]) => identifier)
378382

383+
// If registationId is empty, it means the extension doesn't have a UID yet, so this deploy will create one.
384+
const extensionsBeingMigratedToDevDash = extensionModules.filter((module) => module.registrationId === '')
385+
const extensionsToUpdate = allExistingExtensions.filter((identifier) =>
386+
extensionsBeingMigratedToDevDash.some((module) => module.registrationUuid === localRegistration[identifier]),
387+
)
388+
389+
const unchangedExtensions = allExistingExtensions.filter(
390+
(identifier) =>
391+
!extensionsBeingMigratedToDevDash.some((module) => module.registrationUuid === localRegistration[identifier]),
392+
)
393+
379394
let extensionsToCreate = Object.entries(localRegistration)
380395
.filter(([_identifier, uuid]) => !extensionModules.some((module) => moduleHasUUIDorUID(module, uuid)))
381396
.map(([identifier, _uuid]) => identifier)
@@ -393,6 +408,7 @@ function loadExtensionsIdentifiersBreakdown(
393408
onlyRemote: extensionsOnlyRemote.map(buildExtensionBreakdownInfo),
394409
toCreate: extensionsToCreate.map(buildExtensionBreakdownInfo),
395410
toUpdate: extensionsToUpdate.map(buildExtensionBreakdownInfo),
411+
unchanged: unchangedExtensions.map(buildExtensionBreakdownInfo),
396412
}
397413
}
398414

@@ -421,6 +437,7 @@ function loadDashboardIdentifiersBreakdown(currentRegistrations: RemoteSource[],
421437
return {
422438
onlyRemote,
423439
toCreate,
424-
toUpdate,
440+
toUpdate: [],
441+
unchanged: toUpdate,
425442
}
426443
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,12 @@ function matchByUIDandUUID(
114114

115115
outputAddedIDs(localMatchedWithoutUID)
116116

117-
return {matched: {...matchedByUID, ...totalMatchedWithoutUID}, toCreate, toConfirm, toManualMatch}
117+
return {
118+
matched: {...matchedByUID, ...totalMatchedWithoutUID},
119+
toCreate,
120+
toConfirm,
121+
toManualMatch,
122+
}
118123
}
119124

120125
function outputAddedIDs(localMatchedWithoutUID: LocalSource[]) {

packages/app/src/cli/services/context/identifiers.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ function buildExtensionsBreakdown() {
7979
toCreate: [],
8080
toUpdate: [],
8181
fromDashboard: [],
82+
unchanged: [],
8283
},
8384
extensionsToConfirm: {
8485
validMatches: {},

packages/app/src/cli/services/release.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ function buildExtensionsBreakdown() {
165165
toCreate: [],
166166
toUpdate: [],
167167
fromDashboard: [],
168+
unchanged: [],
168169
},
169170
versionDetails: {
170171
id: 1,

0 commit comments

Comments
 (0)