n8n/packages/cli/test/integration/commands/license.cmd.test.ts
Cornelius Suermann a422c5ac7b
fix(core): Allow license:clear command to be used for licenses that failed renewal (#10665)
Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <netroy@users.noreply.github.com>
2024-09-05 16:42:22 +02:00

36 lines
1.2 KiB
TypeScript

import { Container } from 'typedi';
import { setupTestCommand } from '@test-integration/utils/test-command';
import { mockInstance } from '../../shared/mocking';
import { ClearLicenseCommand } from '@/commands/license/clear';
import { SETTINGS_LICENSE_CERT_KEY } from '@/constants';
import { SettingsRepository } from '@/databases/repositories/settings.repository';
import { License } from '@/license';
import { LoadNodesAndCredentials } from '@/load-nodes-and-credentials';
mockInstance(LoadNodesAndCredentials);
const license = mockInstance(License);
const command = setupTestCommand(ClearLicenseCommand);
test('license:clear invokes shutdown() to release any floating entitlements', async () => {
await command.run();
expect(license.init).toHaveBeenCalledTimes(1);
expect(license.shutdown).toHaveBeenCalledTimes(1);
});
test('license:clear deletes the license from the DB even if shutdown() fails', async () => {
license.shutdown.mockRejectedValueOnce(new Error('shutdown failed'));
const settingsRepository = Container.get(SettingsRepository);
settingsRepository.delete = jest.fn();
await command.run();
expect(settingsRepository.delete).toHaveBeenCalledWith({
key: SETTINGS_LICENSE_CERT_KEY,
});
});