fix(editor): Ensure license activation modal works when used without EULA (#21681)

This commit is contained in:
Charlie Kolb 2025-11-10 14:26:53 +02:00 committed by GitHub
parent 9e240d6d74
commit 4e70050ab2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 3 deletions

View File

@ -123,6 +123,34 @@ describe('SettingsUsageAndPlan', () => {
expect(container.querySelector('.n8n-badge')).toHaveTextContent('Registered');
});
it('should correctly call activateLicense on non-eula acceptance', async () => {
usageStore.isLoading = false;
usageStore.planName = 'Community';
usersStore.currentUser = {
globalScopes: ['license:manage'],
} as IUser;
rbacStore.setGlobalScopes(['license:manage']);
usageStore.activateLicense.mockImplementation(async () => {});
const { getByRole } = renderComponent();
await userEvent.click(getByRole('button', { name: /activation/i }));
const input = document.querySelector('input') as HTMLInputElement;
await userEvent.type(input, 'test-key-123');
await userEvent.click(getByRole('button', { name: /activate/i }));
await waitFor(() => {
expect(usageStore.activateLicense).toHaveBeenCalledTimes(1);
expect(usageStore.activateLicense).toHaveBeenLastCalledWith('test-key-123', undefined);
});
expect(mockToast.showMessage).toHaveBeenCalledWith(
expect.objectContaining({
type: 'success',
}),
);
});
describe('License activation with EULA', () => {
it('should show EULA modal when activation fails with 400 error and eulaUrl', async () => {
usageStore.isLoading = false;
@ -249,7 +277,7 @@ describe('SettingsUsageAndPlan', () => {
await userEvent.click(getByRole('button', { name: /activate/i }));
await waitFor(() => {
expect(mockToast.showError).toHaveBeenCalledWith(error, expect.any(String));
expect(mockToast.showError).toHaveBeenCalledWith(error, 'Activation failed');
});
});
});

View File

@ -103,7 +103,7 @@ const isEulaError = (error: unknown): error is EulaErrorResponse => {
const onLicenseActivation = async (eulaUri?: string) => {
try {
await usageStore.activateLicense(activationKey.value, eulaUri);
await usageStore.activateLicense(activationKey.value.trim(), eulaUri?.trim());
activationKeyModal.value = false;
eulaModal.value = false;
activationKey.value = '';
@ -321,7 +321,7 @@ const openCommunityRegisterModal = () => {
<N8nButton type="secondary" @click="activationKeyModal = false">
{{ locale.baseText('settings.usageAndPlan.dialog.activation.cancel') }}
</N8nButton>
<N8nButton :disabled="!activationKey" @click="onLicenseActivation">
<N8nButton :disabled="!activationKey" @click="() => onLicenseActivation()">
{{ locale.baseText('settings.usageAndPlan.dialog.activation.activate') }}
</N8nButton>
</template>