|
| 1 | +import { describe, it, expect, vi } from 'vitest'; |
| 2 | +import { Command } from 'commander'; |
| 3 | + |
| 4 | +vi.mock('@uipath/uipath-ts-cli/actions', () => ({ |
| 5 | + executePush: vi.fn().mockResolvedValue(undefined), |
| 6 | + executePull: vi.fn().mockResolvedValue(undefined), |
| 7 | + executePack: vi.fn().mockResolvedValue(undefined), |
| 8 | + executePublish: vi.fn().mockResolvedValue(undefined), |
| 9 | + executeDeploy: vi.fn().mockResolvedValue(undefined), |
| 10 | +})); |
| 11 | + |
| 12 | +vi.mock('@uipath/auth', () => ({ |
| 13 | + getLoginStatusAsync: vi.fn().mockResolvedValue({ loginStatus: 'Not logged in' }), |
| 14 | + resolveEnvFilePathAsync: vi.fn(), |
| 15 | + saveEnvFileAsync: vi.fn(), |
| 16 | +})); |
| 17 | + |
| 18 | +vi.mock('../../src/utils/folder-selection.js', () => ({ |
| 19 | + ensureFolderKey: vi.fn().mockResolvedValue(undefined), |
| 20 | +})); |
| 21 | + |
| 22 | +import { registerPushCommand } from '../../src/commands/push.js'; |
| 23 | +import { registerPullCommand } from '../../src/commands/pull.js'; |
| 24 | +import { registerPackCommand } from '../../src/commands/pack.js'; |
| 25 | +import { registerPublishCommand } from '../../src/commands/publish.js'; |
| 26 | +import { registerDeployCommand } from '../../src/commands/deploy.js'; |
| 27 | + |
| 28 | +describe('Command Registration', () => { |
| 29 | + describe('push command', () => { |
| 30 | + it('should register push command on program', () => { |
| 31 | + const program = new Command(); |
| 32 | + registerPushCommand(program); |
| 33 | + |
| 34 | + const pushCmd = program.commands.find((c) => c.name() === 'push'); |
| 35 | + expect(pushCmd).toBeDefined(); |
| 36 | + expect(pushCmd!.description()).toContain('Push'); |
| 37 | + }); |
| 38 | + |
| 39 | + it('should have correct options', () => { |
| 40 | + const program = new Command(); |
| 41 | + registerPushCommand(program); |
| 42 | + |
| 43 | + const pushCmd = program.commands.find((c) => c.name() === 'push')!; |
| 44 | + const optionNames = pushCmd.options.map((o) => o.long); |
| 45 | + expect(optionNames).toContain('--buildDir'); |
| 46 | + expect(optionNames).toContain('--ignoreResources'); |
| 47 | + expect(optionNames).toContain('--baseUrl'); |
| 48 | + expect(optionNames).toContain('--orgId'); |
| 49 | + expect(optionNames).toContain('--tenantId'); |
| 50 | + expect(optionNames).toContain('--accessToken'); |
| 51 | + }); |
| 52 | + }); |
| 53 | + |
| 54 | + describe('pull command', () => { |
| 55 | + it('should register pull command on program', () => { |
| 56 | + const program = new Command(); |
| 57 | + registerPullCommand(program); |
| 58 | + |
| 59 | + const pullCmd = program.commands.find((c) => c.name() === 'pull'); |
| 60 | + expect(pullCmd).toBeDefined(); |
| 61 | + expect(pullCmd!.description()).toContain('Pull'); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should have overwrite option', () => { |
| 65 | + const program = new Command(); |
| 66 | + registerPullCommand(program); |
| 67 | + |
| 68 | + const pullCmd = program.commands.find((c) => c.name() === 'pull')!; |
| 69 | + const optionNames = pullCmd.options.map((o) => o.long); |
| 70 | + expect(optionNames).toContain('--overwrite'); |
| 71 | + expect(optionNames).toContain('--targetDir'); |
| 72 | + }); |
| 73 | + }); |
| 74 | + |
| 75 | + describe('pack command', () => { |
| 76 | + it('should register pack command on program', () => { |
| 77 | + const program = new Command(); |
| 78 | + registerPackCommand(program); |
| 79 | + |
| 80 | + const packCmd = program.commands.find((c) => c.name() === 'pack'); |
| 81 | + expect(packCmd).toBeDefined(); |
| 82 | + expect(packCmd!.description()).toContain('Package'); |
| 83 | + }); |
| 84 | + |
| 85 | + it('should require dist argument', () => { |
| 86 | + const program = new Command(); |
| 87 | + registerPackCommand(program); |
| 88 | + |
| 89 | + const packCmd = program.commands.find((c) => c.name() === 'pack')!; |
| 90 | + const args = packCmd.registeredArguments; |
| 91 | + expect(args.length).toBeGreaterThan(0); |
| 92 | + expect(args[0].required).toBe(true); |
| 93 | + }); |
| 94 | + |
| 95 | + it('should have packaging options', () => { |
| 96 | + const program = new Command(); |
| 97 | + registerPackCommand(program); |
| 98 | + |
| 99 | + const packCmd = program.commands.find((c) => c.name() === 'pack')!; |
| 100 | + const optionNames = packCmd.options.map((o) => o.long); |
| 101 | + expect(optionNames).toContain('--name'); |
| 102 | + expect(optionNames).toContain('--version'); |
| 103 | + expect(optionNames).toContain('--output'); |
| 104 | + expect(optionNames).toContain('--dry-run'); |
| 105 | + }); |
| 106 | + }); |
| 107 | + |
| 108 | + describe('publish command', () => { |
| 109 | + it('should register publish command on program', () => { |
| 110 | + const program = new Command(); |
| 111 | + registerPublishCommand(program); |
| 112 | + |
| 113 | + const publishCmd = program.commands.find((c) => c.name() === 'publish'); |
| 114 | + expect(publishCmd).toBeDefined(); |
| 115 | + expect(publishCmd!.description()).toContain('Publish'); |
| 116 | + }); |
| 117 | + |
| 118 | + it('should have publish options', () => { |
| 119 | + const program = new Command(); |
| 120 | + registerPublishCommand(program); |
| 121 | + |
| 122 | + const publishCmd = program.commands.find((c) => c.name() === 'publish')!; |
| 123 | + const optionNames = publishCmd.options.map((o) => o.long); |
| 124 | + expect(optionNames).toContain('--name'); |
| 125 | + expect(optionNames).toContain('--version'); |
| 126 | + expect(optionNames).toContain('--type'); |
| 127 | + expect(optionNames).toContain('--uipathDir'); |
| 128 | + }); |
| 129 | + }); |
| 130 | + |
| 131 | + describe('deploy command', () => { |
| 132 | + it('should register deploy command on program', () => { |
| 133 | + const program = new Command(); |
| 134 | + registerDeployCommand(program); |
| 135 | + |
| 136 | + const deployCmd = program.commands.find((c) => c.name() === 'deploy'); |
| 137 | + expect(deployCmd).toBeDefined(); |
| 138 | + expect(deployCmd!.description()).toContain('Deploy'); |
| 139 | + }); |
| 140 | + |
| 141 | + it('should have deploy options', () => { |
| 142 | + const program = new Command(); |
| 143 | + registerDeployCommand(program); |
| 144 | + |
| 145 | + const deployCmd = program.commands.find((c) => c.name() === 'deploy')!; |
| 146 | + const optionNames = deployCmd.options.map((o) => o.long); |
| 147 | + expect(optionNames).toContain('--name'); |
| 148 | + expect(optionNames).toContain('--folderKey'); |
| 149 | + expect(optionNames).toContain('--orgName'); |
| 150 | + }); |
| 151 | + }); |
| 152 | +}); |
0 commit comments