Skip to content

Commit

Permalink
update tests related to store selection prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
gracejychang committed Aug 1, 2024
1 parent 8ae9677 commit 220ce1a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
13 changes: 6 additions & 7 deletions packages/app/src/cli/prompts/dev.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ describe('selectApp', () => {
})

describe('selectStore', () => {
const defaultClientName = 'partners'
const defaultShowDomainOnPrompt = false
test('returns undefined if store list is empty', async () => {
// Given
const stores: OrganizationStore[] = []

// When
const got = await selectStorePrompt(stores, defaultClientName)
const got = await selectStorePrompt(stores, defaultShowDomainOnPrompt)

// Then
expect(got).toEqual(undefined)
Expand All @@ -154,7 +154,7 @@ describe('selectStore', () => {
const outputMock = mockAndCaptureOutput()

// When
const got = await selectStorePrompt(stores, defaultClientName)
const got = await selectStorePrompt(stores, defaultShowDomainOnPrompt)

// Then
expect(got).toEqual(STORE1)
Expand All @@ -168,7 +168,7 @@ describe('selectStore', () => {
vi.mocked(renderAutocompletePrompt).mockResolvedValue('2')

// When
const got = await selectStorePrompt(stores, defaultClientName)
const got = await selectStorePrompt(stores, defaultShowDomainOnPrompt)

// Then
expect(got).toEqual(STORE2)
Expand All @@ -181,14 +181,13 @@ describe('selectStore', () => {
})
})

test('renders stores list with domain if client is app-management ', async () => {
test('renders stores list with domain if showDomainOnPrompt is true ', async () => {
// Given
const clientName = 'app-management'
const stores: OrganizationStore[] = [STORE1, STORE2]
vi.mocked(renderAutocompletePrompt).mockResolvedValue('2')

// When
const got = await selectStorePrompt(stores, clientName)
const got = await selectStorePrompt(stores, true)

// Then
expect(got).toEqual(STORE2)
Expand Down
26 changes: 21 additions & 5 deletions packages/app/src/cli/services/dev/select-store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
confirmConversionToTransferDisabledStorePrompt,
} from '../../prompts/dev.js'
import {testDeveloperPlatformClient} from '../../models/app/app.test-data.js'
import {ClientName} from '../../utilities/developer-platform-client.js'
import {beforeEach, describe, expect, vi, test} from 'vitest'
import {isSpinEnvironment} from '@shopify/cli-kit/node/context/spin'
import {firstPartyDev} from '@shopify/cli-kit/node/context/local'
Expand Down Expand Up @@ -47,6 +48,8 @@ const STORE3: OrganizationStore = {
convertableToPartnerTest: false,
}

const defaultShowDomainOnPrompt = false

beforeEach(() => {
vi.mocked(isSpinEnvironment).mockReturnValue(false)
})
Expand All @@ -61,7 +64,20 @@ describe('selectStore', async () => {

// Then
expect(got).toEqual(STORE1)
expect(selectStorePrompt).toHaveBeenCalledWith([STORE1, STORE2])
expect(selectStorePrompt).toHaveBeenCalledWith([STORE1, STORE2], defaultShowDomainOnPrompt)
})

test('selectStorePrompt is called with showDomainOnPrompt = true if clientName is app-management', async () => {
// Given
vi.mocked(selectStorePrompt).mockResolvedValueOnce(STORE1)
const developerPlatformClient = testDeveloperPlatformClient({clientName: ClientName.AppManagement})

// When
const got = await selectStore([STORE1, STORE2], ORG1, developerPlatformClient)

// Then
expect(got).toEqual(STORE1)
expect(selectStorePrompt).toHaveBeenCalledWith([STORE1, STORE2], true)
})

test('prompts user to convert store to non-transferable if selection is invalid', async () => {
Expand All @@ -74,7 +90,7 @@ describe('selectStore', async () => {

// Then
expect(got).toEqual(STORE2)
expect(selectStorePrompt).toHaveBeenCalledWith([STORE1, STORE2])
expect(selectStorePrompt).toHaveBeenCalledWith([STORE1, STORE2], defaultShowDomainOnPrompt)
expect(confirmConversionToTransferDisabledStorePrompt).toHaveBeenCalled()
})

Expand All @@ -89,7 +105,7 @@ describe('selectStore', async () => {

// Then
expect(got).toEqual(STORE1)
expect(selectStorePrompt).toHaveBeenCalledWith([STORE1, STORE2])
expect(selectStorePrompt).toHaveBeenCalledWith([STORE1, STORE2], defaultShowDomainOnPrompt)
expect(confirmConversionToTransferDisabledStorePrompt).toHaveBeenCalled()
})

Expand All @@ -106,7 +122,7 @@ describe('selectStore', async () => {
// Then
expect(got).toEqual(STORE2)
expect(developerPlatformClient.convertToTransferDisabledStore).not.toHaveBeenCalled()
expect(selectStorePrompt).toHaveBeenCalledWith([STORE1, STORE2])
expect(selectStorePrompt).toHaveBeenCalledWith([STORE1, STORE2], defaultShowDomainOnPrompt)
})

test('throws if store is non convertible', async () => {
Expand All @@ -130,7 +146,7 @@ describe('selectStore', async () => {

// Then
await expect(got).rejects.toThrowError()
expect(selectStorePrompt).toHaveBeenCalledWith([STORE1, STORE2])
expect(selectStorePrompt).toHaveBeenCalledWith([STORE1, STORE2], defaultShowDomainOnPrompt)
})

test('prompts user to create & reload, fetches 10 times and tries again if reload is true', async () => {
Expand Down

0 comments on commit 220ce1a

Please sign in to comment.