From b0cbaf59fe4cd13e1ccc6b9cdbb23d3540c6e487 Mon Sep 17 00:00:00 2001 From: Gonzalo Riestra Date: Thu, 19 Sep 2024 10:17:51 +0200 Subject: [PATCH] Use the right client on dev after creating an app in BP --- packages/app/src/cli/services/context.test.ts | 9 +++++++++ packages/app/src/cli/services/context.ts | 4 ++-- packages/app/src/cli/services/info.test.ts | 4 +++- packages/app/src/cli/services/info.ts | 4 +--- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/app/src/cli/services/context.test.ts b/packages/app/src/cli/services/context.test.ts index ede0b8ffc1..775393cd3a 100644 --- a/packages/app/src/cli/services/context.test.ts +++ b/packages/app/src/cli/services/context.test.ts @@ -284,6 +284,7 @@ describe('ensureGenerateContext', () => { specifications: [], remoteFlags: [], }) + vi.mocked(selectDeveloperPlatformClient).mockReturnValue(input.developerPlatformClient) // When const got = await ensureGenerateContext(input) @@ -314,6 +315,7 @@ describe('ensureGenerateContext', () => { specifications: [], remoteFlags: [], }) + vi.mocked(selectDeveloperPlatformClient).mockReturnValue(input.developerPlatformClient) // When const got = await ensureGenerateContext(input) @@ -345,6 +347,7 @@ describe('ensureGenerateContext', () => { specifications: [], remoteFlags: [], }) + vi.mocked(selectDeveloperPlatformClient).mockReturnValue(input.developerPlatformClient) // When const got = await ensureGenerateContext(input) @@ -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() @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/packages/app/src/cli/services/context.ts b/packages/app/src/cli/services/context.ts index 3260ec6be2..5c31f62929 100644 --- a/packages/app/src/cli/services/context.ts +++ b/packages/app/src/cli/services/context.ts @@ -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 { @@ -785,6 +783,8 @@ export async function getAppContext({ userProvidedConfigName: configName, }) + const developerPlatformClient = selectDeveloperPlatformClient({configuration}) + let remoteApp if (isCurrentAppSchema(configuration)) { remoteApp = await appFromId({ diff --git a/packages/app/src/cli/services/info.test.ts b/packages/app/src/cli/services/info.test.ts index 289a643993..cde077f62d 100644 --- a/packages/app/src/cli/services/info.test.ts +++ b/packages/app/src/cli/services/info.test.ts @@ -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' @@ -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'}) @@ -128,6 +129,7 @@ describe('info', () => { }), configContents: testConfig, }) + vi.mocked(selectDeveloperPlatformClient).mockReturnValue(buildDeveloperPlatformClient()) // When const result = stringifyMessage(await info(app, infoOptions())) diff --git a/packages/app/src/cli/services/info.ts b/packages/app/src/cli/services/info.ts index bc938baec8..5d9cb2a3b7 100644 --- a/packages/app/src/cli/services/info.ts +++ b/packages/app/src/cli/services/info.ts @@ -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,