Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/strict-toys-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/app': patch
---

Fix `app dev` always prompting for storefront password
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {Theme} from '@shopify/cli-kit/node/themes/types'
import {vi, describe, test, expect, beforeEach} from 'vitest'
import {renderInfo} from '@shopify/cli-kit/node/ui'
import {partnersFqdn, adminFqdn} from '@shopify/cli-kit/node/context/fqdn'
import {ensureValidPassword, isStorefrontPasswordProtected} from '@shopify/theme'

vi.mock('../../../utilities/extensions/theme/host-theme-manager')
vi.mock('@shopify/cli-kit/node/output')
Expand All @@ -35,6 +36,14 @@ vi.mock('@shopify/cli-kit/node/ui', async (realImport) => {
}),
}
})
vi.mock('@shopify/theme', async (realImport) => {
const realModule = await realImport<typeof import('@shopify/theme')>()
return {
...realModule,
ensureValidPassword: vi.fn(),
isStorefrontPasswordProtected: vi.fn(),
}
})

describe('setupPreviewThemeAppExtensionsProcess', () => {
const mockAdminSession = {storeFqdn: 'test.myshopify.com'} as any as AdminSession
Expand Down Expand Up @@ -176,6 +185,25 @@ describe('setupPreviewThemeAppExtensionsProcess', () => {
orderedNextSteps: true,
})
})

test('returns the validated storefront password when one is required', async () => {
const mockTheme = {id: 123} as Theme
const storefrontPassword = 'typed-password'
vi.mocked(fetchTheme).mockResolvedValue(mockTheme)
vi.mocked(isStorefrontPasswordProtected).mockResolvedValue(true)
vi.mocked(ensureValidPassword).mockResolvedValue(storefrontPassword)

const result = await setupPreviewThemeAppExtensionsProcess({
localApp: testApp({allExtensions: [await testThemeExtensions()]}),
remoteApp: testOrganizationApp(),
storeFqdn: 'test.myshopify.com',
theme: '1',
})

expect(ensureValidPassword).toHaveBeenCalledOnce()
expect(ensureValidPassword).toHaveBeenCalledWith(undefined, 'test.myshopify.com')
expect(result!.options.storefrontPassword).toEqual(storefrontPassword)
})
})

describe('findOrCreateHostTheme', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function setupPreviewThemeAppExtensionsProcess(

const storeFqdn = adminSession.storeFqdn
const storefrontPassword = (await isStorefrontPasswordProtected(adminSession))
? await ensureValidPassword('', storeFqdn)
? await ensureValidPassword(undefined, storeFqdn)
: undefined

const theme = await findOrCreateHostTheme(adminSession, options.theme)
Expand Down
Loading