-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4197 from Shopify/bc/add-migrate-on-deploy
add deploy marketing activity extension logic
- Loading branch information
Showing
10 changed files
with
189 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 10 additions & 4 deletions
14
...fications/marketing_activity_extension.ts → ...ions/specifications/marketing_activity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
packages/app/src/cli/services/dev/migrate-marketing-activity-extension.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import {getMarketingActivtyExtensionsToMigrate} from './migrate-marketing-activity-extension.js' | ||
import {LocalSource, RemoteSource} from '../context/identifiers.js' | ||
import {describe, expect, test} from 'vitest' | ||
|
||
function getLocalExtension(attributes: Partial<LocalSource> = {}) { | ||
return { | ||
type: 'marketing_activity', | ||
localIdentifier: 'test-marketing', | ||
configuration: { | ||
name: 'test-marketing', | ||
}, | ||
...attributes, | ||
} as unknown as LocalSource | ||
} | ||
|
||
function getRemoteExtension(attributes: Partial<RemoteSource> = {}) { | ||
return { | ||
uuid: '1234', | ||
type: 'marketing_activity_extension', | ||
title: 'test-marketing-2', | ||
...attributes, | ||
} as unknown as RemoteSource | ||
} | ||
|
||
describe('getExtensionsToMigrate()', () => { | ||
const defaultIds = { | ||
'test-marketing': '1234', | ||
} | ||
|
||
test('matching my remote title and localIdentifier', () => { | ||
// Given | ||
const title = 'test123' | ||
const localExtension = getLocalExtension({ | ||
type: 'marketing_activity', | ||
localIdentifier: title, | ||
}) | ||
const remoteExtension = getRemoteExtension({ | ||
type: 'marketing_activity_extension', | ||
title, | ||
uuid: 'yy', | ||
}) | ||
|
||
// When | ||
const toMigrate = getMarketingActivtyExtensionsToMigrate([localExtension], [remoteExtension], defaultIds) | ||
|
||
// Then | ||
expect(toMigrate).toStrictEqual([{local: localExtension, remote: remoteExtension}]) | ||
}) | ||
|
||
test('matching my local and remote IDs', () => { | ||
// Given | ||
const localExtension = getLocalExtension({ | ||
type: 'marketing_activity', | ||
localIdentifier: 'test-marketing', | ||
}) | ||
const remoteExtension = getRemoteExtension({type: 'marketing_activity_extension', title: 'remote', uuid: '1234'}) | ||
|
||
// When | ||
const toMigrate = getMarketingActivtyExtensionsToMigrate([localExtension], [remoteExtension], defaultIds) | ||
|
||
// Then | ||
expect(toMigrate).toStrictEqual([{local: localExtension, remote: remoteExtension}]) | ||
}) | ||
|
||
test('does not return extensions where local.type is not marketing_activity', () => { | ||
// Given | ||
const localExtension = getLocalExtension({type: 'checkout_ui_extension'}) | ||
const remoteExtension = getRemoteExtension({type: 'flow_action_definition'}) | ||
|
||
// When | ||
const toMigrate = getMarketingActivtyExtensionsToMigrate([localExtension], [remoteExtension], defaultIds) | ||
|
||
// Then | ||
expect(toMigrate).toStrictEqual([]) | ||
}) | ||
|
||
test('does not return extensions where remote.type is not marketing_activity_extension', () => { | ||
// Given | ||
const localExtension = getLocalExtension({type: 'PRODUCT_SUBSCRIPTION_UI_EXTENSION'}) | ||
const remoteExtension = getRemoteExtension({type: 'PRODUCT_SUBSCRIPTION_UI_EXTENSION'}) | ||
|
||
// When | ||
const toMigrate = getMarketingActivtyExtensionsToMigrate([localExtension], [remoteExtension], defaultIds) | ||
|
||
// Then | ||
expect(toMigrate).toStrictEqual([]) | ||
}) | ||
|
||
test('if neither title/name or ids match, does not return any extensions', () => { | ||
// Given | ||
const localExtension = getLocalExtension({type: 'flow_action'}) | ||
const remoteExtension = getRemoteExtension({ | ||
type: 'flow_action_definition', | ||
uuid: '5678', | ||
}) | ||
|
||
// When | ||
const toMigrate = getMarketingActivtyExtensionsToMigrate([localExtension], [remoteExtension], defaultIds) | ||
|
||
// Then | ||
expect(toMigrate).toStrictEqual([]) | ||
}) | ||
}) |
36 changes: 36 additions & 0 deletions
36
packages/app/src/cli/services/dev/migrate-marketing-activity-extension.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import {LocalSource, RemoteSource} from '../context/identifiers.js' | ||
import {IdentifiersExtensions} from '../../models/app/identifiers.js' | ||
import {getExtensionIds, LocalRemoteSource} from '../context/id-matching.js' | ||
import {slugify} from '@shopify/cli-kit/common/string' | ||
|
||
export function getMarketingActivtyExtensionsToMigrate( | ||
localSources: LocalSource[], | ||
remoteSources: RemoteSource[], | ||
identifiers: IdentifiersExtensions, | ||
) { | ||
const ids = getExtensionIds(localSources, identifiers) | ||
const localExtensionTypesToMigrate = ['marketing_activity'] | ||
const remoteExtensionTypesToMigrate = ['marketing_activity_extension'] | ||
const typesMap = new Map<string, string>([['marketing_activity', 'marketing_activity_extension']]) | ||
|
||
const local = localSources.filter((source) => localExtensionTypesToMigrate.includes(source.type)) | ||
const remote = remoteSources.filter((source) => remoteExtensionTypesToMigrate.includes(source.type)) | ||
|
||
// Map remote sources by uuid and slugified title (the slugified title is used for matching with local folder) | ||
const remoteSourcesMap = new Map<string, RemoteSource>() | ||
remote.forEach((remoteSource) => { | ||
remoteSourcesMap.set(remoteSource.uuid, remoteSource) | ||
remoteSourcesMap.set(slugify(remoteSource.title), remoteSource) | ||
}) | ||
|
||
return local.reduce<LocalRemoteSource[]>((accumulator, localSource) => { | ||
const localSourceId = ids[localSource.localIdentifier] ?? 'unknown' | ||
const remoteSource = remoteSourcesMap.get(localSourceId) || remoteSourcesMap.get(localSource.localIdentifier) | ||
const typeMatch = typesMap.get(localSource.type) === remoteSource?.type | ||
|
||
if (remoteSource && typeMatch) { | ||
accumulator.push({local: localSource, remote: remoteSource}) | ||
} | ||
return accumulator | ||
}, []) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.