|
| 1 | +import {openStore} from './open.js' |
| 2 | +import {getStoreInfo} from './info/index.js' |
| 3 | +import {openURL} from '@shopify/cli-kit/node/system' |
| 4 | +import {renderInfo} from '@shopify/cli-kit/node/ui' |
| 5 | +import {beforeEach, describe, expect, test, vi} from 'vitest' |
| 6 | + |
| 7 | +vi.mock('./info/index.js') |
| 8 | +vi.mock('@shopify/cli-kit/node/system') |
| 9 | +vi.mock('@shopify/cli-kit/node/ui') |
| 10 | + |
| 11 | +describe('openStore', () => { |
| 12 | + beforeEach(() => { |
| 13 | + vi.mocked(openURL).mockResolvedValue(true) |
| 14 | + }) |
| 15 | + |
| 16 | + test('opens the canonical storefront URL for a regular store', async () => { |
| 17 | + vi.mocked(getStoreInfo).mockResolvedValue({subdomain: 'shop.myshopify.com'}) |
| 18 | + |
| 19 | + await openStore({store: 'shop.myshopify.com'}) |
| 20 | + |
| 21 | + expect(getStoreInfo).toHaveBeenCalledWith({store: 'shop.myshopify.com'}) |
| 22 | + expect(openURL).toHaveBeenCalledWith('https://shop.myshopify.com') |
| 23 | + expect(renderInfo).toHaveBeenCalledWith( |
| 24 | + expect.objectContaining({headline: expect.stringContaining('Opening the storefront')}), |
| 25 | + ) |
| 26 | + }) |
| 27 | + |
| 28 | + test('prefers the preview-store access URL when present', async () => { |
| 29 | + vi.mocked(getStoreInfo).mockResolvedValue({ |
| 30 | + subdomain: 'preview.myshopify.com', |
| 31 | + accessUrl: 'https://preview.myshopify.com/?token=abc', |
| 32 | + }) |
| 33 | + |
| 34 | + await openStore({store: 'preview.myshopify.com'}) |
| 35 | + |
| 36 | + expect(openURL).toHaveBeenCalledWith('https://preview.myshopify.com/?token=abc') |
| 37 | + }) |
| 38 | + |
| 39 | + test('prints the URL manually when the browser does not open', async () => { |
| 40 | + vi.mocked(getStoreInfo).mockResolvedValue({subdomain: 'shop.myshopify.com'}) |
| 41 | + vi.mocked(openURL).mockResolvedValue(false) |
| 42 | + |
| 43 | + await openStore({store: 'shop.myshopify.com'}) |
| 44 | + |
| 45 | + expect(renderInfo).toHaveBeenCalledWith( |
| 46 | + expect.objectContaining({headline: expect.stringContaining("didn't open automatically")}), |
| 47 | + ) |
| 48 | + }) |
| 49 | +}) |
0 commit comments