Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Align alert persistence fixtures with reader-owned requests

pulse-triage[bot]502b0a24e26b
diff --git a/frontend-modern/src/components/Alerts/WebhookConfig.mutations.test.tsx b/frontend-modern/src/components/Alerts/WebhookConfig.mutations.test.tsx
index b95ad446fb..245e2449aa 100644
--- a/frontend-modern/src/components/Alerts/WebhookConfig.mutations.test.tsx
+++ b/frontend-modern/src/components/Alerts/WebhookConfig.mutations.test.tsx
@@ -11,6 +11,7 @@ import {
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { NotificationsAPI, type Webhook } from '@/api/notifications';
+import { setOrgID } from '@/utils/apiClient';
import { useAlertWebhookDestinationsState } from '@/features/alerts/useAlertWebhookDestinationsState';
import { WebhookConfig } from './WebhookConfig';
@@ -95,6 +96,7 @@ function expectListLocked() {
describe('acknowledged webhook list mutations', () => {
beforeEach(() => {
vi.resetAllMocks();
+ setOrgID('default');
vi.mocked(NotificationsAPI.getWebhookTemplates).mockResolvedValue([]);
});
afterEach(cleanup);
@@ -112,10 +114,12 @@ describe('acknowledged webhook list mutations', () => {
fireEvent.click(disableAll);
expect(NotificationsAPI.updateWebhook).toHaveBeenCalledTimes(1);
- expect(NotificationsAPI.updateWebhook).toHaveBeenNthCalledWith(1, 'hook-1', {
- ...webhook,
- enabled: false,
- });
+ expect(NotificationsAPI.updateWebhook).toHaveBeenNthCalledWith(
+ 1,
+ 'hook-1',
+ { ...webhook, enabled: false },
+ { expectedOrgID: 'default', retry: false },
+ );
expectListLocked();
expect(screen.getByRole('button', { name: '+ Add Webhook' })).toBeDisabled();
expect(screen.getByRole('status')).toHaveTextContent('Saving webhook changes');
@@ -123,10 +127,12 @@ describe('acknowledged webhook list mutations', () => {
first.resolve({ ...webhook, enabled: false });
await waitFor(() => expect(NotificationsAPI.updateWebhook).toHaveBeenCalledTimes(2));
- expect(NotificationsAPI.updateWebhook).toHaveBeenNthCalledWith(2, 'hook-2', {
- ...secondWebhook,
- enabled: false,
- });
+ expect(NotificationsAPI.updateWebhook).toHaveBeenNthCalledWith(
+ 2,
+ 'hook-2',
+ { ...secondWebhook, enabled: false },
+ { expectedOrgID: 'default', retry: false },
+ );
expect(owner.webhooks()).toEqual([{ ...webhook, enabled: false }, secondWebhook, unchanged]);
expectListLocked();
diff --git a/frontend-modern/src/components/Alerts/WebhookConfig.persistence.test.tsx b/frontend-modern/src/components/Alerts/WebhookConfig.persistence.test.tsx
index f2e7bfb7bb..d737516d38 100644
--- a/frontend-modern/src/components/Alerts/WebhookConfig.persistence.test.tsx
+++ b/frontend-modern/src/components/Alerts/WebhookConfig.persistence.test.tsx
@@ -3,6 +3,7 @@ import { cleanup, fireEvent, render, renderHook, screen, waitFor } from '@solidj
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { NotificationsAPI, type Webhook } from '@/api/notifications';
+import { setOrgID } from '@/utils/apiClient';
import { notificationStore } from '@/stores/notifications';
import { useAlertWebhookDestinationsState } from '@/features/alerts/useAlertWebhookDestinationsState';
import { WebhookConfig } from './WebhookConfig';
@@ -73,6 +74,7 @@ function openNewDraft() {
describe('webhook persistence acknowledgement', () => {
beforeEach(() => {
vi.resetAllMocks();
+ setOrgID('default');
vi.mocked(NotificationsAPI.getWebhookTemplates).mockResolvedValue([]);
});
afterEach(cleanup);
@@ -156,8 +158,9 @@ describe('webhook persistence acknowledgement', () => {
expect(draft).toHaveValue('Edited destination');
expect(screen.getByLabelText('Custom header 1 value')).toHaveValue('********');
expect(owner.webhooks()).toEqual([savedWebhook]);
- const [id, payload] = vi.mocked(NotificationsAPI.updateWebhook).mock.calls[0];
+ const [id, payload, requestOptions] = vi.mocked(NotificationsAPI.updateWebhook).mock.calls[0];
expect(id).toBe(savedWebhook.id);
+ expect(requestOptions).toEqual({ expectedOrgID: 'default', retry: false });
expect(payload).toMatchObject({
...savedWebhook,
name: 'Edited destination',
@@ -171,7 +174,11 @@ describe('webhook persistence acknowledgement', () => {
fireEvent.click(screen.getByRole('button', { name: 'Update Webhook' }));
await waitFor(() => expect(screen.queryByLabelText('Name')).not.toBeInTheDocument());
expect(owner.webhooks()[0]).toEqual({ ...savedWebhook, name: 'Accepted edit', enabled: false });
- expect(vi.mocked(NotificationsAPI.updateWebhook).mock.calls[1]).toEqual([id, payload]);
+ expect(vi.mocked(NotificationsAPI.updateWebhook).mock.calls[1]).toEqual([
+ id,
+ payload,
+ requestOptions,
+ ]);
});
it('allows cancellation after a failure without an automatic save or stale error on reopening', async () => {
diff --git a/frontend-modern/src/features/alerts/__tests__/emailRateLimit.persistence.test.tsx b/frontend-modern/src/features/alerts/__tests__/emailRateLimit.persistence.test.tsx
index a957fef5a8..2c9db368f9 100644
--- a/frontend-modern/src/features/alerts/__tests__/emailRateLimit.persistence.test.tsx
+++ b/frontend-modern/src/features/alerts/__tests__/emailRateLimit.persistence.test.tsx
@@ -2,11 +2,14 @@ import { cleanup, fireEvent, render, renderHook, screen, waitFor } from '@solidj
import { Show, createSignal, onMount } from 'solid-js';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
-import { apiFetchJSON } from '@/utils/apiClient';
+import { apiFetchJSON, setOrgID } from '@/utils/apiClient';
import { AlertEmailDestinationsSection } from '../AlertEmailDestinationsSection';
import { useAlertDestinationsState } from '../useAlertDestinationsState';
-vi.mock('@/utils/apiClient', () => ({ apiFetchJSON: vi.fn() }));
+vi.mock('@/utils/apiClient', async (importOriginal) => ({
+ ...(await importOriginal<typeof import('@/utils/apiClient')>()),
+ apiFetchJSON: vi.fn(),
+}));
vi.mock('@/stores/license', () => ({ hasFeature: () => false }));
vi.mock('@/api/alerts', () => ({
AlertsAPI: {
@@ -47,6 +50,7 @@ describe('email rate-limit persistence', () => {
let loadedEnabled: boolean;
beforeEach(() => {
+ setOrgID('default');
loadedRateLimit = 17;
loadedEnabled = true;
vi.mocked(apiFetchJSON).mockReset();
diff --git a/frontend-modern/src/features/alerts/__tests__/useAlertDestinationsTabState.test.tsx b/frontend-modern/src/features/alerts/__tests__/useAlertDestinationsTabState.test.tsx
index c698c5af0e..12ed6100a6 100644
--- a/frontend-modern/src/features/alerts/__tests__/useAlertDestinationsTabState.test.tsx
+++ b/frontend-modern/src/features/alerts/__tests__/useAlertDestinationsTabState.test.tsx
@@ -508,7 +508,13 @@ describe('useAlertDestinationsTabState', () => {
}),
);
+ // A Test is withheld while the independently loaded webhook snapshot is pending.
await result.testEmailConfig();
+ expect(NotificationsAPI.testNotification).not.toHaveBeenCalled();
+ await waitFor(() => expect(result.isLoading()).toBe(false));
+ expect(result.hasLoadError()).toBeFalsy();
+ await result.testEmailConfig();
+ expect(NotificationsAPI.testNotification).toHaveBeenCalledOnce();
expect(notificationStore.warning).toHaveBeenCalledWith(
expect.stringContaining('delivery is paused'),
);