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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {fetchDestinationsContext} from './destinations.js'
import {selectOrg} from '@shopify/organizations'
import {AbortError} from '@shopify/cli-kit/node/error'
import {terminalSupportsPrompting} from '@shopify/cli-kit/node/system'
import {mockAndCaptureOutput} from '@shopify/cli-kit/node/testing/output'
import {describe, expect, test, vi, beforeEach} from 'vitest'

vi.mock('./destinations.js')
Expand Down Expand Up @@ -45,6 +46,7 @@ describe('resolveOrganizationForStore', () => {
vi.mocked(selectOrg).mockResolvedValue(selectedOrg)
vi.mocked(fetchDestinationsContext).mockResolvedValue({owningOrg: {id: '67890', name: 'Inferred Org'}})
vi.mocked(terminalSupportsPrompting).mockReturnValue(true)
mockAndCaptureOutput().clear()
})

test('selects the organization by ID when an organization ID is provided', async () => {
Expand Down Expand Up @@ -72,6 +74,32 @@ describe('resolveOrganizationForStore', () => {
expect(organization).toEqual(selectedOrg)
})

test('explains why the organization prompt is appearing, naming the store the developer provided', async () => {
vi.mocked(fetchDestinationsContext).mockResolvedValue({owningOrg: undefined})
const output = mockAndCaptureOutput()

await resolveOrganizationForStore(STORE)

expect(output.info()).toMatchInlineSnapshot(`
"╭─ info ───────────────────────────────────────────────────────────────────────╮
│ │
│ Could not determine which organization owns shop.myshopify.com. │
│ │
│ Select one below, or specify it with \`--organization-id\`. │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯
"
`)
})

test('stays quiet when the owning organization is inferred', async () => {
const output = mockAndCaptureOutput()

await resolveOrganizationForStore(STORE)

expect(output.info()).toBe('')
})

test('does not prompt non-interactively when ownership can be inferred', async () => {
vi.mocked(terminalSupportsPrompting).mockReturnValue(false)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {selectOrg, type Organization} from '@shopify/organizations'
import {AbortError} from '@shopify/cli-kit/node/error'
import {outputDebug} from '@shopify/cli-kit/node/output'
import {terminalSupportsPrompting} from '@shopify/cli-kit/node/system'
import {renderInfo} from '@shopify/cli-kit/node/ui'

interface FindStoreOwningOrganizationOptions {
store: string
Expand Down Expand Up @@ -55,5 +56,12 @@ export async function resolveOrganizationForStore(store: string, organizationId?
)
}

// The developer only gave a store domain, so explain why they're suddenly being asked to
// pick an organization. Echoing the domain back also makes a typo in it easy to spot.
renderInfo({
headline: `Could not determine which organization owns ${store}.`,
body: ['Select one below, or specify it with', {command: '--organization-id'}, {char: '.'}],
})

return selectOrg()
}
Loading