-
Notifications
You must be signed in to change notification settings - Fork 72
chore: Add tests for the migration flow #1472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2c64104
Add tests for api/migrate
joe-yeager 2e002f3
Add tests for migrateApp
joe-yeager 81851b9
Add tests for project migrate
joe-yeager aef915b
chore add cursor boilerplate
joe-yeager 166084a
WIP
joe-yeager 833bf5f
Update tests
joe-yeager c94f3d0
Merge branch 'main' of github.com:HubSpot/hubspot-cli into jy/add-tes…
joe-yeager dc1e243
wip
joe-yeager 0120c80
Clean up
joe-yeager bee0289
Clean up
joe-yeager 17b7f3a
clean up
joe-yeager 757744f
Clean up comments
joe-yeager File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| import yargs, { Argv, ArgumentsCamelCase } from 'yargs'; | ||
| import { logger } from '@hubspot/local-dev-lib/logger'; | ||
| import { PLATFORM_VERSIONS } from '@hubspot/local-dev-lib/constants/projects'; | ||
| import { ProjectMigrateArgs } from '../migrate'; | ||
| import migrateCommand from '../migrate'; | ||
| import { migrateApp2025_2 } from '../../../lib/app/migrate'; | ||
| import { getProjectConfig } from '../../../lib/projects/config'; | ||
| import { commands } from '../../../lang/en'; | ||
| import { uiBetaTag, uiCommandReference } from '../../../lib/ui'; | ||
|
|
||
| jest.mock('yargs'); | ||
| jest.mock('@hubspot/local-dev-lib/logger'); | ||
| jest.mock('../../../lib/app/migrate'); | ||
| jest.mock('../../../lib/projects/config'); | ||
| jest.mock('../../../lib/ui'); | ||
|
|
||
| const { v2025_2 } = PLATFORM_VERSIONS; | ||
|
|
||
| describe('commands/project/migrate', () => { | ||
| const yargsMock = yargs as Argv; | ||
| const optionsSpy = jest.spyOn(yargsMock, 'option').mockReturnValue(yargsMock); | ||
|
|
||
| // Mock the imported functions | ||
| const migrateApp2025_2Mock = migrateApp2025_2 as jest.Mock; | ||
| const getProjectConfigMock = getProjectConfig as jest.Mock; | ||
| const uiBetaTagMock = uiBetaTag as jest.Mock; | ||
| const uiCommandReferenceMock = uiCommandReference as jest.Mock; | ||
|
|
||
| beforeEach(() => { | ||
| // Mock logger methods | ||
| jest.spyOn(logger, 'log').mockImplementation(); | ||
| jest.spyOn(logger, 'error').mockImplementation(); | ||
| migrateApp2025_2Mock.mockResolvedValue(undefined); | ||
| getProjectConfigMock.mockResolvedValue({ | ||
| projectConfig: { name: 'test-project' }, | ||
| }); | ||
| uiBetaTagMock.mockReturnValue('beta test description'); | ||
| uiCommandReferenceMock.mockReturnValue('command reference'); | ||
| }); | ||
|
|
||
| describe('command', () => { | ||
| it('should have the correct command structure', () => { | ||
| expect(migrateCommand.command).toEqual('migrate'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('describe', () => { | ||
| it('should provide a description', () => { | ||
| expect(migrateCommand.describe).toBe(undefined); | ||
| }); | ||
| }); | ||
|
|
||
| describe('builder', () => { | ||
| it('should support the correct options', () => { | ||
| migrateCommand.builder(yargsMock); | ||
|
|
||
| expect(optionsSpy).toHaveBeenCalledWith('platform-version', { | ||
| type: 'string', | ||
| choices: [v2025_2], | ||
| default: v2025_2, | ||
| hidden: true, | ||
| }); | ||
|
|
||
| expect(optionsSpy).toHaveBeenCalledWith('unstable', { | ||
| type: 'boolean', | ||
| default: false, | ||
| hidden: true, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('handler', () => { | ||
| let options: ArgumentsCamelCase<ProjectMigrateArgs>; | ||
| let mockExit: jest.SpyInstance; | ||
|
|
||
| beforeEach(() => { | ||
| mockExit = jest.spyOn(process, 'exit').mockImplementation(); | ||
| options = { | ||
| platformVersion: v2025_2, | ||
| unstable: false, | ||
| derivedAccountId: 123, | ||
| } as ArgumentsCamelCase<ProjectMigrateArgs>; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| mockExit.mockRestore(); | ||
| }); | ||
|
|
||
| it('should exit with error if no project config exists', async () => { | ||
| getProjectConfigMock.mockResolvedValue({ projectConfig: null }); | ||
|
|
||
| await migrateCommand.handler(options); | ||
|
|
||
| expect(logger.error).toHaveBeenCalledWith( | ||
| commands.project.migrate.errors.noProjectConfig('command reference') | ||
| ); | ||
| expect(mockExit).toHaveBeenCalledWith(1); | ||
| }); | ||
|
|
||
| it('should call migrateApp2025_2 with correct parameters', async () => { | ||
| await migrateCommand.handler(options); | ||
|
|
||
| expect(migrateApp2025_2Mock).toHaveBeenCalledWith( | ||
| 123, | ||
| { | ||
| ...options, | ||
| name: 'test-project', | ||
| platformVersion: v2025_2, | ||
| }, | ||
| { projectConfig: { name: 'test-project' } } | ||
| ); | ||
| expect(mockExit).toHaveBeenCalledWith(0); | ||
| }); | ||
|
|
||
| it('should use unstable platform version when unstable flag is true', async () => { | ||
| options.unstable = true; | ||
|
|
||
| await migrateCommand.handler(options); | ||
|
|
||
| expect(migrateApp2025_2Mock).toHaveBeenCalledWith( | ||
| 123, | ||
| { | ||
| ...options, | ||
| name: 'test-project', | ||
| platformVersion: PLATFORM_VERSIONS.unstable, | ||
| }, | ||
| { projectConfig: { name: 'test-project' } } | ||
| ); | ||
| }); | ||
|
|
||
| it('should handle errors and exit with error code', async () => { | ||
| const error = new Error('Test error'); | ||
| migrateApp2025_2Mock.mockRejectedValue(error); | ||
|
|
||
| await migrateCommand.handler(options); | ||
|
|
||
| expect(mockExit).toHaveBeenCalledWith(1); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| import yargs, { Argv, ArgumentsCamelCase } from 'yargs'; | ||
| import { i18n } from '../../../lib/lang'; | ||
| import { uiCommandReference, uiDeprecatedTag } from '../../../lib/ui'; | ||
| import { handlerGenerator } from '../../app/migrate'; | ||
| import { PLATFORM_VERSIONS } from '@hubspot/local-dev-lib/constants/projects'; | ||
| import { MigrateAppArgs } from '../../../lib/app/migrate'; | ||
| import migrateAppCommand from '../migrateApp'; | ||
|
|
||
| jest.mock('yargs'); | ||
| jest.mock('@hubspot/local-dev-lib/logger'); | ||
| jest.mock('../../../lib/lang'); | ||
| jest.mock('../../../lib/ui'); | ||
| jest.mock('../../app/migrate'); | ||
|
|
||
| const { v2023_2, v2025_2 } = PLATFORM_VERSIONS; | ||
|
|
||
| describe('commands/project/migrateApp', () => { | ||
| const yargsMock = yargs as Argv; | ||
| const optionsSpy = jest | ||
| .spyOn(yargsMock, 'options') | ||
| .mockReturnValue(yargsMock); | ||
| const exampleSpy = jest | ||
| .spyOn(yargsMock, 'example') | ||
| .mockReturnValue(yargsMock); | ||
|
|
||
| // Mock the imported functions | ||
| const i18nMock = i18n as jest.Mock; | ||
| const uiDeprecatedTagMock = uiDeprecatedTag as jest.Mock; | ||
| const uiCommandReferenceMock = uiCommandReference as jest.Mock; | ||
| const handlerGeneratorMock = handlerGenerator as jest.Mock; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| i18nMock.mockReturnValue('test description'); | ||
| uiDeprecatedTagMock.mockReturnValue('deprecated test description'); | ||
| uiCommandReferenceMock.mockReturnValue('command reference'); | ||
| handlerGeneratorMock.mockReturnValue( | ||
| jest.fn().mockResolvedValue(undefined) | ||
| ); | ||
| }); | ||
|
|
||
| describe('command', () => { | ||
| it('should have the correct command structure', () => { | ||
| expect(migrateAppCommand.command).toEqual('migrate-app'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('describe', () => { | ||
| it('should provide a description', () => { | ||
| expect(migrateAppCommand.describe).toBe(undefined); | ||
| }); | ||
|
|
||
| it('should be marked as deprecated', () => { | ||
| expect(migrateAppCommand.deprecated).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe('builder', () => { | ||
| it('should support the correct options', () => { | ||
| migrateAppCommand.builder(yargsMock); | ||
|
|
||
| expect(optionsSpy).toHaveBeenCalledWith({ | ||
| name: expect.objectContaining({ | ||
| describe: expect.any(String), | ||
| type: 'string', | ||
| }), | ||
| dest: expect.objectContaining({ | ||
| describe: expect.any(String), | ||
| type: 'string', | ||
| }), | ||
| 'app-id': expect.objectContaining({ | ||
| describe: expect.any(String), | ||
| type: 'number', | ||
| }), | ||
| 'platform-version': expect.objectContaining({ | ||
| type: 'string', | ||
| choices: [v2023_2, v2025_2], | ||
| hidden: true, | ||
| default: v2023_2, | ||
| }), | ||
| }); | ||
|
|
||
| expect(exampleSpy).toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('handler', () => { | ||
| let options: ArgumentsCamelCase<MigrateAppArgs>; | ||
| const mockLocalHandler = jest.fn().mockResolvedValue(undefined); | ||
|
|
||
| beforeEach(() => { | ||
| options = { | ||
| platformVersion: v2023_2, | ||
| } as ArgumentsCamelCase<MigrateAppArgs>; | ||
|
|
||
| handlerGeneratorMock.mockReturnValue(mockLocalHandler); | ||
| }); | ||
|
|
||
| it('should call the local handler with the provided options', async () => { | ||
| await migrateAppCommand.handler(options); | ||
|
|
||
| expect(handlerGeneratorMock).toHaveBeenCalledWith('migrate-app'); | ||
| expect(mockLocalHandler).toHaveBeenCalledWith(options); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha yeah, Claude had some creative ideas about how to fix the tests