|
| 1 | +import { resolve } from 'node:path'; |
| 2 | +import { prepareAuthTokens } from '@spotify-confidence/testing/auth'; |
| 3 | +import { pluginCommand } from '@commands/plugin.js'; |
| 4 | +import { captureOutput } from '../helpers/capture.js'; |
| 5 | +import { createMockIntegration } from '../helpers/mock-integration.js'; |
| 6 | +import { createRunner } from '../helpers/run-command.js'; |
| 7 | + |
| 8 | +const mockIntegration = createMockIntegration(); |
| 9 | + |
| 10 | +const mockInstallPlugin = vi.fn().mockResolvedValue('cli'); |
| 11 | +const mockUpdatePlugin = vi.fn().mockResolvedValue('cli'); |
| 12 | +const mockUninstallPlugin = vi.fn().mockResolvedValue(undefined); |
| 13 | + |
| 14 | +vi.mock('@spotify-confidence/core', async (importOriginal) => { |
| 15 | + const actual = await importOriginal<typeof import('@spotify-confidence/core')>(); |
| 16 | + return { |
| 17 | + ...actual, |
| 18 | + getIntegration: () => mockIntegration, |
| 19 | + getIntegrations: () => [mockIntegration], |
| 20 | + installPlugin: (...args: unknown[]) => mockInstallPlugin(...args), |
| 21 | + updatePlugin: (...args: unknown[]) => mockUpdatePlugin(...args), |
| 22 | + uninstallPlugin: (...args: unknown[]) => mockUninstallPlugin(...args), |
| 23 | + }; |
| 24 | +}); |
| 25 | + |
| 26 | +beforeEach(() => { |
| 27 | + vi.clearAllMocks(); |
| 28 | +}); |
| 29 | + |
| 30 | +const run = createRunner(pluginCommand); |
| 31 | + |
| 32 | +describe('plugin install', () => { |
| 33 | + it('installs the plugin for the specified IDE with default project scope', async () => { |
| 34 | + using _auth = prepareAuthTokens('none'); |
| 35 | + using _output = captureOutput(); |
| 36 | + |
| 37 | + await run(['plugin', 'install', '--ide', 'claude']); |
| 38 | + |
| 39 | + expect(mockInstallPlugin).toHaveBeenCalledWith('claude', process.cwd(), 'project'); |
| 40 | + }); |
| 41 | + |
| 42 | + it('passes --dir as project directory', async () => { |
| 43 | + using _auth = prepareAuthTokens('none'); |
| 44 | + using _output = captureOutput(); |
| 45 | + |
| 46 | + await run(['plugin', 'install', '--ide', 'claude', '--dir', 'some/relative/path']); |
| 47 | + |
| 48 | + expect(mockInstallPlugin).toHaveBeenCalledWith( |
| 49 | + 'claude', |
| 50 | + resolve('some/relative/path'), |
| 51 | + 'project', |
| 52 | + ); |
| 53 | + }); |
| 54 | + |
| 55 | + it('passes --scope to the installer', async () => { |
| 56 | + using _auth = prepareAuthTokens('none'); |
| 57 | + using _output = captureOutput(); |
| 58 | + |
| 59 | + await run(['plugin', 'install', '--ide', 'claude', '--scope', 'global']); |
| 60 | + |
| 61 | + expect(mockInstallPlugin).toHaveBeenCalledWith('claude', process.cwd(), 'global'); |
| 62 | + }); |
| 63 | + |
| 64 | + it('reports failure to stderr', async () => { |
| 65 | + using _auth = prepareAuthTokens('none'); |
| 66 | + using output = captureOutput(); |
| 67 | + mockInstallPlugin.mockRejectedValueOnce(new Error('install failed')); |
| 68 | + |
| 69 | + await run(['plugin', 'install', '--ide', 'claude']); |
| 70 | + |
| 71 | + expect(output.stderr).toContain('install failed'); |
| 72 | + }); |
| 73 | +}); |
| 74 | + |
| 75 | +describe('plugin update', () => { |
| 76 | + it('updates the plugin for the specified IDE with default project scope', async () => { |
| 77 | + using _auth = prepareAuthTokens('none'); |
| 78 | + using _output = captureOutput(); |
| 79 | + |
| 80 | + await run(['plugin', 'update', '--ide', 'claude']); |
| 81 | + |
| 82 | + expect(mockUpdatePlugin).toHaveBeenCalledWith('claude', process.cwd(), 'project'); |
| 83 | + }); |
| 84 | + |
| 85 | + it('passes --dir as project directory', async () => { |
| 86 | + using _auth = prepareAuthTokens('none'); |
| 87 | + using _output = captureOutput(); |
| 88 | + |
| 89 | + await run(['plugin', 'update', '--ide', 'claude', '--dir', '/tmp/my-project']); |
| 90 | + |
| 91 | + expect(mockUpdatePlugin).toHaveBeenCalledWith('claude', '/tmp/my-project', 'project'); |
| 92 | + }); |
| 93 | + |
| 94 | + it('passes --scope to the updater', async () => { |
| 95 | + using _auth = prepareAuthTokens('none'); |
| 96 | + using _output = captureOutput(); |
| 97 | + |
| 98 | + await run(['plugin', 'update', '--ide', 'claude', '--scope', 'local']); |
| 99 | + |
| 100 | + expect(mockUpdatePlugin).toHaveBeenCalledWith('claude', process.cwd(), 'local'); |
| 101 | + }); |
| 102 | + |
| 103 | + it('reports failure to stderr', async () => { |
| 104 | + using _auth = prepareAuthTokens('none'); |
| 105 | + using output = captureOutput(); |
| 106 | + mockUpdatePlugin.mockRejectedValueOnce(new Error('update failed')); |
| 107 | + |
| 108 | + await run(['plugin', 'update', '--ide', 'claude']); |
| 109 | + |
| 110 | + expect(output.stderr).toContain('update failed'); |
| 111 | + }); |
| 112 | +}); |
| 113 | + |
| 114 | +describe('plugin uninstall', () => { |
| 115 | + it('uninstalls the plugin for the specified IDE with default project scope', async () => { |
| 116 | + using _auth = prepareAuthTokens('none'); |
| 117 | + using _output = captureOutput(); |
| 118 | + |
| 119 | + await run(['plugin', 'uninstall', '--ide', 'claude']); |
| 120 | + |
| 121 | + expect(mockUninstallPlugin).toHaveBeenCalledWith('claude', process.cwd(), 'project'); |
| 122 | + }); |
| 123 | + |
| 124 | + it('passes --dir as project directory', async () => { |
| 125 | + using _auth = prepareAuthTokens('none'); |
| 126 | + using _output = captureOutput(); |
| 127 | + |
| 128 | + await run(['plugin', 'uninstall', '--ide', 'claude', '--dir', '/tmp/my-project']); |
| 129 | + |
| 130 | + expect(mockUninstallPlugin).toHaveBeenCalledWith('claude', '/tmp/my-project', 'project'); |
| 131 | + }); |
| 132 | + |
| 133 | + it('passes --scope to the uninstaller', async () => { |
| 134 | + using _auth = prepareAuthTokens('none'); |
| 135 | + using _output = captureOutput(); |
| 136 | + |
| 137 | + await run(['plugin', 'uninstall', '--ide', 'claude', '--scope', 'global']); |
| 138 | + |
| 139 | + expect(mockUninstallPlugin).toHaveBeenCalledWith('claude', process.cwd(), 'global'); |
| 140 | + }); |
| 141 | + |
| 142 | + it('reports failure to stderr', async () => { |
| 143 | + using _auth = prepareAuthTokens('none'); |
| 144 | + using output = captureOutput(); |
| 145 | + mockUninstallPlugin.mockRejectedValueOnce(new Error('uninstall failed')); |
| 146 | + |
| 147 | + await run(['plugin', 'uninstall', '--ide', 'claude']); |
| 148 | + |
| 149 | + expect(output.stderr).toContain('uninstall failed'); |
| 150 | + }); |
| 151 | +}); |
0 commit comments