diff --git a/tests/classes/ManagerLocal.test.ts b/tests/classes/ManagerLocal.test.ts index 5b9fe8e..32ebed2 100644 --- a/tests/classes/ManagerLocal.test.ts +++ b/tests/classes/ManagerLocal.test.ts @@ -12,6 +12,7 @@ import { } from '../data/Project'; import { CONFIG_LOCAL_TEST } from '../data/Config'; import { ManagerLocal } from '../../src/classes/ManagerLocal'; +import { Package } from '../../src/classes/Package'; import { dirCreate, dirDelete, @@ -235,6 +236,37 @@ test('Install installer-only package still elevates when unprivileged', async () runCliAsAdminSpy.mockRestore(); }); +test('Install all installs every listed package', async () => { + const manager = new ManagerLocal(RegistryType.Plugins, CONFIG); + // Seed a single known package directly rather than sync()'ing the live registry - installAll() + // only cares about whatever's already in listPackages(), and this keeps the test's network + // footprint fixed regardless of how many packages the real registry happens to have. + const pkg = new Package(PLUGIN_PACKAGE.slug); + pkg.addVersion(PLUGIN_PACKAGE.version, PLUGIN); + manager.addPackage(pkg); + + const packages = await manager.installAll(); + expect(packages).toHaveLength(1); + expect(packages[0].getVersion(PLUGIN_PACKAGE.version)?.installed).toEqual(true); + + await manager.uninstall(PLUGIN_PACKAGE.slug, PLUGIN_PACKAGE.version); +}); + +test('Install all elevates when unprivileged', async () => { + const isAdminSpy = vi.spyOn(fileHelpers, 'isAdmin').mockReturnValue(false); + const isTestsSpy = vi.spyOn(utilsLocalHelpers, 'isTests').mockReturnValue(false); + const runCliAsAdminSpy = vi.spyOn(fileHelpers, 'runCliAsAdmin').mockResolvedValue(undefined); + + const manager = new ManagerLocal(RegistryType.Plugins, CONFIG); + await manager.installAll(); + expect(runCliAsAdminSpy).toHaveBeenCalledTimes(1); + expect(runCliAsAdminSpy).toHaveBeenCalledWith(expect.objectContaining({ operation: 'installAll' })); + + isAdminSpy.mockRestore(); + isTestsSpy.mockRestore(); + runCliAsAdminSpy.mockRestore(); +}); + test('Project sync, install project, install dependencies, uninstall dependencies', async () => { const manager = new ManagerLocal(RegistryType.Projects, CONFIG); await manager.sync();