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

Fix dev after app creation with App Management API #4478

Merged
merged 1 commit into from
Sep 19, 2024
Merged
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
9 changes: 9 additions & 0 deletions packages/app/src/cli/services/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ describe('ensureGenerateContext', () => {
specifications: [],
remoteFlags: [],
})
vi.mocked(selectDeveloperPlatformClient).mockReturnValue(input.developerPlatformClient)

// When
const got = await ensureGenerateContext(input)
Expand Down Expand Up @@ -314,6 +315,7 @@ describe('ensureGenerateContext', () => {
specifications: [],
remoteFlags: [],
})
vi.mocked(selectDeveloperPlatformClient).mockReturnValue(input.developerPlatformClient)

// When
const got = await ensureGenerateContext(input)
Expand Down Expand Up @@ -345,6 +347,7 @@ describe('ensureGenerateContext', () => {
specifications: [],
remoteFlags: [],
})
vi.mocked(selectDeveloperPlatformClient).mockReturnValue(input.developerPlatformClient)

// When
const got = await ensureGenerateContext(input)
Expand Down Expand Up @@ -407,6 +410,7 @@ describe('ensureDevContext', async () => {
test('returns selected data using config file set in cache', async () => {
await inTemporaryDirectory(async (tmp) => {
// Given
vi.mocked(selectDeveloperPlatformClient).mockReturnValue(buildDeveloperPlatformClient())
vi.mocked(getCachedAppInfo).mockReturnValue(CACHED1_WITH_CONFIG)
vi.mocked(loadAppConfiguration).mockReset()
const {schema: configSchema} = await buildVersionedAppSchema()
Expand Down Expand Up @@ -500,6 +504,7 @@ dev_store_url = "domain1"
})
vi.mocked(fetchStoreByDomain).mockResolvedValue({organization: ORG1, store: STORE1})
const options = devOptions({apiKey: APP2.apiKey})
vi.mocked(selectDeveloperPlatformClient).mockReturnValue(options.developerPlatformClient)

// When
const got = await ensureDevContext(options)
Expand Down Expand Up @@ -553,6 +558,7 @@ dev_store_url = "domain1"
const app = await mockApp(tmp, localApp)
vi.mocked(loadApp).mockResolvedValue(app)
const options = devOptions()
vi.mocked(selectDeveloperPlatformClient).mockReturnValue(options.developerPlatformClient)

// When
await ensureDevContext(options)
Expand Down Expand Up @@ -589,6 +595,7 @@ dev_store_url = "domain1"
const app = await mockApp(tmp, localApp)
vi.mocked(loadApp).mockResolvedValue(app)
const options = devOptions()
vi.mocked(selectDeveloperPlatformClient).mockReturnValue(options.developerPlatformClient)

// When
await ensureDevContext(options)
Expand Down Expand Up @@ -643,6 +650,7 @@ api_version = "2023-04"
const app = await mockApp(tmp, localApp)
vi.mocked(loadApp).mockResolvedValue(app)
const options = devOptions()
vi.mocked(selectDeveloperPlatformClient).mockReturnValue(options.developerPlatformClient)

// When
await ensureDevContext(options)
Expand Down Expand Up @@ -904,6 +912,7 @@ api_version = "2023-04"
const app = await mockApp(tmp, localApp)
vi.mocked(loadApp).mockResolvedValue(app)
const options = devOptions({reset: true})
vi.mocked(selectDeveloperPlatformClient).mockReturnValue(options.developerPlatformClient)

// When
const got = await ensureDevContext(options)
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/cli/services/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,13 +766,11 @@ interface AppContext {
export async function getAppContext({
reset,
directory,
developerPlatformClient,
configName,
enableLinkingPrompt = true,
}: {
reset: boolean
directory: string
developerPlatformClient: DeveloperPlatformClient
configName?: string
enableLinkingPrompt?: boolean
}): Promise<AppContext> {
Expand All @@ -785,6 +783,8 @@ export async function getAppContext({
userProvidedConfigName: configName,
})

const developerPlatformClient = selectDeveloperPlatformClient({configuration})

let remoteApp
if (isCurrentAppSchema(configuration)) {
remoteApp = await appFromId({
Expand Down
4 changes: 3 additions & 1 deletion packages/app/src/cli/services/info.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
testAppConfigExtensions,
} from '../models/app/app.test-data.js'
import {AppErrors} from '../models/app/loader.js'
import {DeveloperPlatformClient} from '../utilities/developer-platform-client.js'
import {DeveloperPlatformClient, selectDeveloperPlatformClient} from '../utilities/developer-platform-client.js'
import {describe, expect, vi, test} from 'vitest'
import {checkForNewVersion} from '@shopify/cli-kit/node/node-package-manager'
import {joinPath} from '@shopify/cli-kit/node/path'
Expand All @@ -24,6 +24,7 @@ vi.mock('./local-storage.js')
vi.mock('./app/fetch-app-from-config-or-select.js')
vi.mock('../prompts/dev.js')
vi.mock('@shopify/cli-kit/node/node-package-manager')
vi.mock('../utilities/developer-platform-client.js')

const APP = testOrganizationApp()
const APP1 = testOrganizationApp({id: '123', title: 'my app', apiKey: '12345'})
Expand Down Expand Up @@ -128,6 +129,7 @@ describe('info', () => {
}),
configContents: testConfig,
})
vi.mocked(selectDeveloperPlatformClient).mockReturnValue(buildDeveloperPlatformClient())

// When
const result = stringifyMessage(await info(app, infoOptions()))
Expand Down
4 changes: 1 addition & 3 deletions packages/app/src/cli/services/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,13 @@ class AppInfo {

async devConfigsSection(): Promise<[string, string]> {
const title = `Current app configuration`
let developerPlatformClient = this.options.developerPlatformClient!
const {cachedInfo, remoteApp} = await getAppContext({
developerPlatformClient,
directory: this.app.directory,
reset: false,
configName: this.options.configName,
enableLinkingPrompt: false,
})
developerPlatformClient = remoteApp?.developerPlatformClient ?? developerPlatformClient
const developerPlatformClient = remoteApp?.developerPlatformClient ?? this.options.developerPlatformClient!

const postscript = outputContent`💡 To change these, run ${outputToken.packagejsonScript(
this.app.packageManager,
Expand Down
Loading