Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App migration #4571

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions packages/app/src/cli/services/dev/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ const ORG2: Organization = {
businessName: 'org2',
source: OrganizationSource.Partners,
}
const MIGRATED_ORG1: Organization = {
id: '1',
businessName: 'org1',
source: OrganizationSource.BusinessPlatform,
}
const ORG3: Organization = {
id: '3',
businessName: 'org3',
source: OrganizationSource.BusinessPlatform,
}

const STORE1: OrganizationStore = {
shopId: '1',
link: 'link1',
Expand Down Expand Up @@ -55,11 +66,12 @@ afterEach(() => {
describe('fetchOrganizations', async () => {
test('returns fetched organizations from Partners without USE_APP_MANAGEMENT_API', async () => {
// Given

const partnersClient: PartnersClient = testDeveloperPlatformClient({
organizations: () => Promise.resolve([ORG1]),
organizations: () => Promise.resolve([ORG1, ORG2]),
}) as PartnersClient
const appManagementClient: AppManagementClient = testDeveloperPlatformClient({
organizations: () => Promise.resolve([ORG2]),
organizations: () => Promise.resolve([MIGRATED_ORG1, ORG3]),
}) as AppManagementClient
vi.mocked(PartnersClient).mockReturnValue(partnersClient)
vi.mocked(AppManagementClient).mockReturnValue(appManagementClient)
Expand All @@ -68,19 +80,19 @@ describe('fetchOrganizations', async () => {
const got = await fetchOrganizations()

// Then
expect(got).toEqual([ORG1])
expect(got).toEqual([ORG1, ORG2])
expect(partnersClient.organizations).toHaveBeenCalled()
expect(appManagementClient.organizations).not.toHaveBeenCalled()
})

test('returns fetched organizations from Partners and App Management with USE_APP_MANAGEMENT_API', async () => {
test('returns unique organizations from App Management and Partners with USE_APP_MANAGEMENT_API', async () => {
// Given
vi.stubEnv('USE_APP_MANAGEMENT_API', '1')
const partnersClient: PartnersClient = testDeveloperPlatformClient({
organizations: () => Promise.resolve([ORG1]),
organizations: () => Promise.resolve([ORG1, ORG2]),
}) as PartnersClient
const appManagementClient: AppManagementClient = testDeveloperPlatformClient({
organizations: () => Promise.resolve([ORG2]),
organizations: () => Promise.resolve([MIGRATED_ORG1, ORG3]),
}) as AppManagementClient
vi.mocked(PartnersClient).mockReturnValue(partnersClient)
vi.mocked(AppManagementClient).mockReturnValue(appManagementClient)
Expand All @@ -89,7 +101,7 @@ describe('fetchOrganizations', async () => {
const got = await fetchOrganizations()

// Then
expect(got).toEqual([ORG1, ORG2])
expect(got).toEqual([MIGRATED_ORG1, ORG3, ORG2])
expect(partnersClient.organizations).toHaveBeenCalled()
expect(appManagementClient.organizations).toHaveBeenCalled()
})
Expand Down
7 changes: 6 additions & 1 deletion packages/app/src/cli/services/dev/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ export async function fetchOrganizations(): Promise<Organization[]> {
// We don't want to run this in parallel because there could be port conflicts
// eslint-disable-next-line no-await-in-loop
const clientOrganizations = await client.organizations()
organizations.push(...clientOrganizations)
clientOrganizations.forEach((newOrg) => {
// Add organizations that are not already in the list
if (!organizations.some((org) => org.businessName === newOrg.businessName)) {
organizations.push(newOrg)
}
})
}

if (organizations.length === 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export interface AppVersionIdentifiers {

export function allDeveloperPlatformClients(): DeveloperPlatformClient[] {
const clients: DeveloperPlatformClient[] = [new PartnersClient()]
if (isTruthy(process.env.USE_APP_MANAGEMENT_API)) clients.push(new AppManagementClient())
if (isTruthy(process.env.USE_APP_MANAGEMENT_API)) clients.unshift(new AppManagementClient())
return clients
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,9 +580,9 @@ export class AppManagementClient implements DeveloperPlatformClient {
return {
appModuleVersions: result.app.activeRelease.version.appModules.map((mod) => {
return {
registrationId: mod.uuid,
registrationUid: mod.uuid,
registrationUuid: mod.uuid,
registrationId: mod.userIdentifier,
registrationUid: mod.userIdentifier,
registrationUuid: mod.userIdentifier,
registrationTitle: mod.handle,
type: mod.specification.externalIdentifier,
config: mod.config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const ActiveAppReleaseQuery = gql`
name
appModules {
uuid
userIdentifier
handle
config
specification {
Expand All @@ -45,6 +46,7 @@ interface AppModuleSpecification {

interface AppModule {
uuid: string
userIdentifier: string
handle: string
config: JsonMapType
specification: AppModuleSpecification
Expand Down
Loading