|
| 1 | +import Release from './release.js' |
| 2 | +import {testAppLinked, testDeveloperPlatformClient, testOrganizationApp} from '../../models/app/app.test-data.js' |
| 3 | +import {OrganizationSource} from '../../models/organization.js' |
| 4 | +import {describe, expect, test, vi, beforeEach} from 'vitest' |
| 5 | +import {renderWarning} from '@shopify/cli-kit/node/ui' |
| 6 | + |
| 7 | +vi.mock('../../services/release.js') |
| 8 | +vi.mock('../../services/app-context.js') |
| 9 | +vi.mock('@shopify/cli-kit/node/metadata', async (importOriginal) => { |
| 10 | + const actual = await importOriginal<typeof import('@shopify/cli-kit/node/metadata')>() |
| 11 | + return {...actual, addPublicMetadata: vi.fn()} |
| 12 | +}) |
| 13 | +vi.mock('@shopify/cli-kit/node/ui', async (importOriginal) => { |
| 14 | + const actual = await importOriginal<typeof import('@shopify/cli-kit/node/ui')>() |
| 15 | + return {...actual, renderWarning: vi.fn()} |
| 16 | +}) |
| 17 | + |
| 18 | +describe('app release --force deprecation warning', () => { |
| 19 | + beforeEach(async () => { |
| 20 | + const {linkedAppContext} = await import('../../services/app-context.js') |
| 21 | + const {release} = await import('../../services/release.js') |
| 22 | + vi.mocked(linkedAppContext).mockResolvedValue({ |
| 23 | + app: testAppLinked(), |
| 24 | + remoteApp: testOrganizationApp(), |
| 25 | + developerPlatformClient: testDeveloperPlatformClient(), |
| 26 | + organization: { |
| 27 | + id: '1', |
| 28 | + businessName: 'test', |
| 29 | + source: OrganizationSource.Partners, |
| 30 | + }, |
| 31 | + specifications: [], |
| 32 | + }) |
| 33 | + vi.mocked(release).mockResolvedValue(undefined) |
| 34 | + }) |
| 35 | + |
| 36 | + test('shows deprecation warning when --force is passed', async () => { |
| 37 | + await Release.run(['--version', 'v1.0.0', '--force']) |
| 38 | + |
| 39 | + expect(renderWarning).toHaveBeenCalledWith( |
| 40 | + expect.objectContaining({ |
| 41 | + headline: expect.arrayContaining(['The']), |
| 42 | + body: expect.arrayContaining(['Use']), |
| 43 | + }), |
| 44 | + ) |
| 45 | + const call = vi.mocked(renderWarning).mock.calls[0]![0] |
| 46 | + expect(JSON.stringify(call)).toContain('--force') |
| 47 | + expect(JSON.stringify(call)).toContain('next major release') |
| 48 | + }) |
| 49 | + |
| 50 | + test('shows deprecation warning when SHOPIFY_FLAG_FORCE env var is set', async () => { |
| 51 | + vi.stubEnv('SHOPIFY_FLAG_FORCE', '1') |
| 52 | + |
| 53 | + await Release.run(['--version', 'v1.0.0']) |
| 54 | + |
| 55 | + expect(renderWarning).toHaveBeenCalled() |
| 56 | + const call = vi.mocked(renderWarning).mock.calls[0]![0] |
| 57 | + expect(JSON.stringify(call)).toContain('--force') |
| 58 | + |
| 59 | + vi.unstubAllEnvs() |
| 60 | + }) |
| 61 | + |
| 62 | + test('does not show deprecation warning when only --allow-updates is passed', async () => { |
| 63 | + await Release.run(['--version', 'v1.0.0', '--allow-updates']) |
| 64 | + |
| 65 | + expect(renderWarning).not.toHaveBeenCalled() |
| 66 | + }) |
| 67 | + |
| 68 | + test('does not show deprecation warning when --allow-updates and --allow-deletes are passed', async () => { |
| 69 | + await Release.run(['--version', 'v1.0.0', '--allow-updates', '--allow-deletes']) |
| 70 | + |
| 71 | + expect(renderWarning).not.toHaveBeenCalled() |
| 72 | + }) |
| 73 | + |
| 74 | + test('does not show deprecation warning when only --allow-deletes is passed', async () => { |
| 75 | + await Release.run(['--version', 'v1.0.0', '--allow-deletes']) |
| 76 | + |
| 77 | + expect(renderWarning).not.toHaveBeenCalled() |
| 78 | + }) |
| 79 | +}) |
0 commit comments