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

Make organization source required #5137

Open
wants to merge 1 commit into
base: report-BP-id-to-bugsnag
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion packages/app/src/cli/models/organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export enum OrganizationSource {
export interface Organization {
id: string
businessName: string
source?: OrganizationSource
source: OrganizationSource
}

export interface AppApiKeyAndOrgId {
Expand Down
4 changes: 3 additions & 1 deletion packages/app/src/cli/prompts/dev.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
selectStorePrompt,
updateURLsPrompt,
} from './dev.js'
import {Organization, OrganizationStore} from '../models/organization.js'
import {Organization, OrganizationSource, OrganizationStore} from '../models/organization.js'
import {testDeveloperPlatformClient, testOrganizationApp} from '../models/app/app.test-data.js'
import {getTomls} from '../utilities/app/config/getTomls.js'
import {searchForAppsByNameFactory} from '../services/dev/prompt-helpers.js'
Expand All @@ -21,10 +21,12 @@ vi.mock('../utilities/app/config/getTomls')
const ORG1: Organization = {
id: '1',
businessName: 'org1',
source: OrganizationSource.BusinessPlatform,
}
const ORG2: Organization = {
id: '2',
businessName: 'org2',
source: OrganizationSource.BusinessPlatform,
}
const APP1 = testOrganizationApp({apiKey: 'key1'})
const APP2 = testOrganizationApp({
Expand Down
14 changes: 11 additions & 3 deletions packages/app/src/cli/services/app/config/link-service.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import link from './link.js'
import {testOrganizationApp, testDeveloperPlatformClient} from '../../../models/app/app.test-data.js'
import {DeveloperPlatformClient, selectDeveloperPlatformClient} from '../../../utilities/developer-platform-client.js'
import {AppApiKeyAndOrgId, OrganizationApp} from '../../../models/organization.js'
import {AppApiKeyAndOrgId, OrganizationApp, OrganizationSource} from '../../../models/organization.js'
import {appNamePrompt, createAsNewAppPrompt, selectOrganizationPrompt} from '../../../prompts/dev.js'
import {beforeEach, describe, expect, test, vi} from 'vitest'
import {inTemporaryDirectory, readFile, writeFileSync} from '@shopify/cli-kit/node/fs'
Expand All @@ -27,7 +27,11 @@ function buildDeveloperPlatformClient(): DeveloperPlatformClient {
}
},
async orgAndApps(orgId) {
return {organization: {id: orgId, businessName: 'test'}, apps: [mockRemoteApp()], hasMorePages: false}
return {
organization: {id: orgId, businessName: 'test', source: OrganizationSource.BusinessPlatform},
apps: [mockRemoteApp()],
hasMorePages: false,
}
},
async createApp(org, name, options) {
return testOrganizationApp({
Expand Down Expand Up @@ -58,7 +62,11 @@ describe('link, with minimal mocking', () => {
vi.mocked(selectDeveloperPlatformClient).mockReturnValue(developerPlatformClient)
vi.mocked(createAsNewAppPrompt).mockResolvedValue(true)
vi.mocked(appNamePrompt).mockResolvedValue('A user provided name')
vi.mocked(selectOrganizationPrompt).mockResolvedValue({id: '12345', businessName: 'test'})
vi.mocked(selectOrganizationPrompt).mockResolvedValue({
id: '12345',
businessName: 'test',
source: OrganizationSource.BusinessPlatform,
})

const options = {
directory: tmp,
Expand Down
2 changes: 2 additions & 0 deletions packages/app/src/cli/services/app/env/show.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {fetchOrganizations} from '../../dev/fetch.js'
import {AppInterface} from '../../../models/app/app.js'
import {selectOrganizationPrompt} from '../../../prompts/dev.js'
import {testApp, testOrganizationApp} from '../../../models/app/app.test-data.js'
import {OrganizationSource} from '../../../models/organization.js'
import {describe, expect, vi, test} from 'vitest'
import * as file from '@shopify/cli-kit/node/fs'
import {stringifyMessage, unstyled} from '@shopify/cli-kit/node/output'
Expand All @@ -23,6 +24,7 @@ describe('env show', () => {
id: '123',
flags: {},
businessName: 'test',
source: OrganizationSource.BusinessPlatform,
apps: {nodes: []},
}
const organizationApp = testOrganizationApp()
Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/cli/services/dev/select-app.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {selectOrCreateApp} from './select-app.js'
import {AppInterface, WebType} from '../../models/app/app.js'
import {AppApiKeyAndOrgId, Organization} from '../../models/organization.js'
import {AppApiKeyAndOrgId, Organization, OrganizationSource} from '../../models/organization.js'
import {appNamePrompt, createAsNewAppPrompt, selectAppPrompt} from '../../prompts/dev.js'
import {testApp, testOrganizationApp, testDeveloperPlatformClient} from '../../models/app/app.test-data.js'
import {describe, expect, vi, test} from 'vitest'
Expand All @@ -25,6 +25,7 @@ const LOCAL_APP: AppInterface = testApp({
const ORG1: Organization = {
id: '1',
businessName: 'org1',
source: OrganizationSource.BusinessPlatform,
}
const APP1 = testOrganizationApp({apiKey: 'key1'})
const APP2 = testOrganizationApp({
Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/cli/services/dev/select-store.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {selectStore} from './select-store.js'
import {Organization, OrganizationStore} from '../../models/organization.js'
import {Organization, OrganizationSource, OrganizationStore} from '../../models/organization.js'
import {
reloadStoreListPrompt,
selectStorePrompt,
Expand All @@ -20,6 +20,7 @@ vi.mock('@shopify/cli-kit/node/context/spin')
const ORG1: Organization = {
id: '1',
businessName: 'org1',
source: OrganizationSource.BusinessPlatform,
}
const STORE1: OrganizationStore = {
shopId: '1',
Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/cli/services/info.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {InfoOptions, info} from './info.js'
import {AppInterface, AppLinkedInterface} from '../models/app/app.js'
import {AppApiKeyAndOrgId, OrganizationApp} from '../models/organization.js'
import {AppApiKeyAndOrgId, OrganizationApp, OrganizationSource} from '../models/organization.js'
import {selectOrganizationPrompt} from '../prompts/dev.js'
import {
testDeveloperPlatformClient,
Expand Down Expand Up @@ -30,6 +30,7 @@ const ORG1 = {
flags: {},
businessName: 'test',
apps: {nodes: []},
source: OrganizationSource.BusinessPlatform,
}

function buildDeveloperPlatformClient(): DeveloperPlatformClient {
Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/cli/services/versions-list.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import versionList from './versions-list.js'
import {renderCurrentlyUsedConfigInfo} from './context.js'
import {testAppLinked, testDeveloperPlatformClient, testOrganizationApp} from '../models/app/app.test-data.js'
import {Organization} from '../models/organization.js'
import {Organization, OrganizationSource} from '../models/organization.js'
import {DeveloperPlatformClient} from '../utilities/developer-platform-client.js'
import {AppVersionsQuerySchema} from '../api/graphql/get_versions_list.js'
import {afterEach, describe, expect, test, vi} from 'vitest'
Expand All @@ -17,6 +17,7 @@ afterEach(() => {
const ORG1: Organization = {
id: 'org-id',
businessName: 'name of org 1',
source: OrganizationSource.BusinessPlatform,
}

const remoteApp = testOrganizationApp({organizationId: ORG1.id, apiKey: 'api-key', title: 'app-title', id: 'app-id'})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {PartnersClient} from './partners-client.js'
import {CreateAppQuery} from '../../api/graphql/create_app.js'
import {AppInterface, WebType} from '../../models/app/app.js'
import {Organization, OrganizationStore} from '../../models/organization.js'
import {Organization, OrganizationSource, OrganizationStore} from '../../models/organization.js'
import {
testPartnersUserSession,
testApp,
Expand Down Expand Up @@ -32,11 +32,13 @@ const LOCAL_APP: AppInterface = testApp({
name: 'my-app',
})

const ORG1: Organization = {
type OrganizationInPartnersResponse = Omit<Organization, 'source'>

const ORG1: OrganizationInPartnersResponse = {
id: '1',
businessName: 'org1',
}
const ORG2: Organization = {
const ORG2: OrganizationInPartnersResponse = {
id: '2',
businessName: 'org2',
}
Expand Down Expand Up @@ -88,7 +90,7 @@ describe('createApp', () => {
}

// When
const got = await partnersClient.createApp(ORG1, localApp.name, {
const got = await partnersClient.createApp({...ORG1, source: OrganizationSource.Partners}, localApp.name, {
scopesArray: ['write_products'],
isLaunchable: true,
})
Expand All @@ -113,7 +115,7 @@ describe('createApp', () => {
}

// When
const got = await partnersClient.createApp(ORG1, LOCAL_APP.name, {
const got = await partnersClient.createApp({...ORG1, source: OrganizationSource.Partners}, LOCAL_APP.name, {
isLaunchable: false,
scopesArray: ['write_products'],
})
Expand All @@ -132,7 +134,7 @@ describe('createApp', () => {
})

// When
const got = partnersClient.createApp(ORG2, LOCAL_APP.name)
const got = partnersClient.createApp({...ORG2, source: OrganizationSource.Partners}, LOCAL_APP.name)

// Then
await expect(got).rejects.toThrow(`some-error`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,8 @@ export class PartnersClient implements DeveloperPlatformClient {
async orgFromId(orgId: string): Promise<Organization | undefined> {
const variables: FindOrganizationBasicVariables = {id: orgId}
const result: FindOrganizationBasicQuerySchema = await this.request(FindOrganizationBasicQuery, variables)
const org: Organization | undefined = result.organizations.nodes[0]
if (org) org.source = OrganizationSource.Partners
return org
const org: Omit<Organization, 'source'> | undefined = result.organizations.nodes[0]
return org ? {...org, source: OrganizationSource.Partners} : undefined
}

async orgAndApps(orgId: string): Promise<Paginateable<{organization: Organization; apps: MinimalOrganizationApp[]}>> {
Expand Down
Loading