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.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
test(cloudcp): prove Pulse Account app flows
rcourtmanef4426a70f15
diff --git a/internal/cloudcp/portal/dist/build_manifest.json b/internal/cloudcp/portal/dist/build_manifest.jsonindex 3c3e5f95aa..0036ffc85e 100644--- a/internal/cloudcp/portal/dist/build_manifest.json+++ b/internal/cloudcp/portal/dist/build_manifest.json@@ -1,5 +1,5 @@{- "source_hash": "a0bf793c666d66b4c67754d20f97ea6d329fc972209646646174e0ff4d91479a",+ "source_hash": "f28967eb0031c49b09af97d9d4117a7d4eb01d8125632ad125af1edd498fb944","build_inputs": ["package.json","tsconfig.json",diff --git a/internal/cloudcp/portal/dist/portal_app.js b/internal/cloudcp/portal/dist/portal_app.jsindex e3ed80f385..25f4ef16c6 100644--- a/internal/cloudcp/portal/dist/portal_app.js+++ b/internal/cloudcp/portal/dist/portal_app.js@@ -1075,7 +1075,7 @@},onRequestStart: function() {},- onConfirmSuccess: function(data) {+ afterConfirmSuccess: function(data) {window.location.href = data.url;},renderPanel: renderManagePanel@@ -1109,12 +1109,10 @@serviceState.flows.retrieve.result = null;}, false);},- onConfirmSuccess: function(data) {- updateServiceState(function(serviceState) {- serviceState.flows.retrieve.result = data.license;- serviceState.flows.retrieve.codeValue = "";- setFlowStatus(serviceState, "retrieve", "License retrieved successfully.", false);- }, false);+ applyConfirmSuccessState: function(serviceState, data) {+ serviceState.flows.retrieve.result = data.license;+ serviceState.flows.retrieve.codeValue = "";+ setFlowStatus(serviceState, "retrieve", "License retrieved successfully.", false);},renderPanel: renderRetrievePanel},@@ -1147,16 +1145,12 @@serviceState.flows.export.result = null;}, false);},- onConfirmSuccess: function(data) {- updateServiceState(function(serviceState) {- serviceState.flows.export.result = data;- serviceState.flows.export.codeValue = "";- setFlowStatus(serviceState, "export", "Data export retrieved successfully.", false);- }, false);- resetVerificationFlow("export");- updateServiceState(function(serviceState) {- serviceState.flows.export.result = data;- }, false);+ applyConfirmSuccessState: function(serviceState, data) {+ var emailValue = serviceState.flows.export.emailValue;+ resetVerificationFlowState(serviceState, "export");+ serviceState.flows.export.emailValue = emailValue;+ serviceState.flows.export.result = data;+ setFlowStatus(serviceState, "export", "Data export retrieved successfully.", false);},renderPanel: renderExportPanel,renderResult: renderExportResult@@ -1194,20 +1188,22 @@}return true;},- onConfirmSuccess: function(data) {+ applyConfirmSuccessState: function(serviceState, data) {+ var emailValue = serviceState.flows.delete.emailValue;+ resetVerificationFlowState(serviceState, "delete");+ serviceState.flows.delete.emailValue = emailValue;+ setFlowStatus(+ serviceState,+ "delete",+ data.deleted_count > 0 && data.stripe_reminder ? data.message + " " + data.stripe_reminder : data.message,+ false+ );+ },+ afterConfirmSuccess: function() {var checkbox = getElement3("data-delete-confirm-check");if (checkbox) {checkbox.checked = false;}- resetVerificationFlow("delete");- updateServiceState(function(serviceState) {- setFlowStatus(- serviceState,- "delete",- data.deleted_count > 0 && data.stripe_reminder ? data.message + " " + data.stripe_reminder : data.message,- false- );- }, false);},renderPanel: renderDeletePanel}@@ -1276,8 +1272,13 @@var data = await api.postCommercialJSON(flow.confirmPath, { email, code });updateServiceState(function(serviceState) {succeedMutationState(serviceState.flows[flowID].confirm);- }, false);- flow.onConfirmSuccess(data, email);+ if (flow.applyConfirmSuccessState) {+ flow.applyConfirmSuccessState(serviceState, data, email);+ }+ });+ if (flow.afterConfirmSuccess) {+ flow.afterConfirmSuccess(data, email);+ }} catch (err) {var message = err instanceof Error ? err.message : flow.confirmErrorMessage;updateServiceState(function(serviceState) {diff --git a/internal/cloudcp/portal/frontend/src/app.test.ts b/internal/cloudcp/portal/frontend/src/app.test.tsindex c2e4b7fd84..c3777a02be 100644--- a/internal/cloudcp/portal/frontend/src/app.test.ts+++ b/internal/cloudcp/portal/frontend/src/app.test.ts@@ -1,10 +1,29 @@import { beforeEach, describe, expect, it, vi } from 'vitest';import { installPortalApp } from './app';-import { createBootstrapDefaults, createPortalRuntime } from './runtime';+import { createPortalRuntime } from './runtime';import { createPortalStore } from './store';import type { PortalBootstrapData } from './types';+function jsonResponse(payload: unknown, ok = true, status = ok ? 200 : 500) {+ return {+ ok,+ status,+ headers: new Headers({ 'content-type': 'application/json' }),+ json: vi.fn().mockResolvedValue(payload),+ text: vi.fn().mockResolvedValue(typeof payload === 'string' ? payload : JSON.stringify(payload)),+ };+}++async function flushAsync() {+ await Promise.resolve();+ await Promise.resolve();+ await Promise.resolve();+ await new Promise(function(resolve) {+ setTimeout(resolve, 0);+ });+}+const bootstrapDefaults: Omit<PortalBootstrapData, 'authenticated' | 'email' | 'accounts'> = {public_site_url: 'https://pulserelay.pro',support_email: '[email protected]',@@ -117,4 +136,167 @@ describe('portal app', function() {expect(runtime.store.getBootstrap().authenticated).toBe(true);expect(runtime.store.getBootstrap().email).toBe('[email protected]');});++ it('completes the signed-out magic-link flow through the real shell and auth runtime', async function() {+ var store = createPortalStore(bootstrapDefaults, {+ authenticated: false,+ email: '',+ accounts: [],+ });+ var fetchMock = vi.fn().mockResolvedValue(jsonResponse({}));+ vi.stubGlobal('fetch', fetchMock);++ installPortalApp({+ bootstrapDefaults: bootstrapDefaults,+ store: store,+ });++ var emailInput = document.getElementById('portal-login-email') as HTMLInputElement | null;+ expect(emailInput).not.toBeNull();+ emailInput!.value = '[email protected]';+ emailInput!.dispatchEvent(new Event('input', { bubbles: true }));++ document.getElementById('portal-login-send')?.dispatchEvent(new MouseEvent('click', { bubbles: true }));+ await flushAsync();++ expect(fetchMock).toHaveBeenCalledWith(+ '/api/public/magic-link/request',+ expect.objectContaining({+ method: 'POST',+ body: JSON.stringify({ email: '[email protected]' }),+ })+ );+ expect(document.getElementById('portal-app-root')?.textContent).toContain('Magic link sent. Check your inbox and click the link to sign in.');+ });++ it('completes the retrieve-license flow through the real authenticated app shell', async function() {+ var accounts = [+ {+ id: 'acct_1',+ name: 'Acme MSP',+ kind: 'msp',+ kind_label: 'MSP',+ role: 'owner',+ can_manage: true,+ has_billing: true,+ workspaces: [],+ },+ ];+ var store = createPortalStore(bootstrapDefaults, {+ authenticated: true,+ email: '[email protected]',+ accounts: accounts,+ });+ var fetchMock = vi.fn(async function(input: RequestInfo | URL) {+ var url = String(input);+ if (url === '/api/portal/bootstrap') {+ return jsonResponse({+ authenticated: true,+ email: '[email protected]',+ accounts: accounts,+ });+ }+ if (url === 'https://license.pulserelay.pro/v1/retrieve-license/request') {+ return jsonResponse({});+ }+ if (url === 'https://license.pulserelay.pro/v1/retrieve-license') {+ return jsonResponse({+ license: {+ token: 'pulse_token_123',+ tier: 'Pro',+ issued_at: '2026-03-01T10:00:00Z',+ expires_at: null,+ email: '[email protected]',+ },+ });+ }+ throw new Error('Unexpected fetch: ' + url);+ });+ vi.stubGlobal('fetch', fetchMock);++ var app = installPortalApp({+ bootstrapDefaults: bootstrapDefaults,+ store: store,+ });+ await app.startupRefresh;++ document.getElementById('open-retrieve-service')?.dispatchEvent(new MouseEvent('click', { bubbles: true }));+ var retrievePanel = document.getElementById('retrieve-service-panel');+ expect(retrievePanel?.classList.contains('visible')).toBe(true);++ var emailInput = document.getElementById('retrieve-inline-email') as HTMLInputElement | null;+ expect(emailInput?.value).toBe('[email protected]');++ document.getElementById('retrieve-inline-request')?.dispatchEvent(new MouseEvent('click', { bubbles: true }));+ await flushAsync();++ var codeInput = document.getElementById('retrieve-inline-code') as HTMLInputElement | null;+ expect(codeInput).not.toBeNull();+ codeInput!.value = '123456';+ codeInput!.dispatchEvent(new Event('input', { bubbles: true }));+ document.getElementById('retrieve-inline-confirm')?.dispatchEvent(new MouseEvent('click', { bubbles: true }));+ await flushAsync();++ expect(fetchMock.mock.calls).toContainEqual([+ 'https://license.pulserelay.pro/v1/retrieve-license/request',+ expect.objectContaining({+ method: 'POST',+ body: JSON.stringify({ email: '[email protected]' }),+ }),+ ]);+ expect(fetchMock.mock.calls).toContainEqual([+ 'https://license.pulserelay.pro/v1/retrieve-license',+ expect.objectContaining({+ method: 'POST',+ body: JSON.stringify({ email: '[email protected]', code: '123456' }),+ }),+ ]);+ expect((store.getServiceState().flows.retrieve.result as { token?: string } | null)?.token).toBe('pulse_token_123');+ expect((document.getElementById('retrieve-inline-result') as HTMLElement | null)?.style.display).toBe('block');+ expect((document.getElementById('retrieve-inline-copy') as HTMLButtonElement | null)?.style.display).toBe('inline-block');+ expect(document.getElementById('retrieve-inline-status')?.textContent).toContain('License retrieved successfully.');+ });++ it('loads team membership through the real authenticated account shell', async function() {+ var accounts = [+ {+ id: 'acct_1',+ name: 'Acme MSP',+ kind: 'msp',+ kind_label: 'MSP',+ role: 'owner',+ can_manage: true,+ has_billing: true,+ workspaces: [],+ },+ ];+ var store = createPortalStore(bootstrapDefaults, {+ authenticated: true,+ email: '[email protected]',+ accounts: accounts,+ });+ var fetchMock = vi.fn()+ .mockResolvedValueOnce(jsonResponse({+ authenticated: true,+ email: '[email protected]',+ accounts: accounts,+ }))+ .mockResolvedValueOnce(jsonResponse([+ { email: '[email protected]', role: 'owner', user_id: 'u_1' },+ ]));+ vi.stubGlobal('fetch', fetchMock);++ var app = installPortalApp({+ bootstrapDefaults: bootstrapDefaults,+ store: store,+ });+ await app.startupRefresh;++ document.querySelector('[data-action="toggle-team"][data-account-id="acct_1"]')?.dispatchEvent(new MouseEvent('click', { bubbles: true }));+ await flushAsync();++ expect(fetchMock).toHaveBeenNthCalledWith(2, '/api/accounts/acct_1/members');+ expect(document.getElementById('team-section-acct_1')?.classList.contains('visible')).toBe(true);+ expect(document.getElementById('team-list-acct_1')?.textContent).toContain('[email protected]');+ });});diff --git a/internal/cloudcp/portal/frontend/src/services.ts b/internal/cloudcp/portal/frontend/src/services.tsindex 763823b6c4..b454e2f4f0 100644--- a/internal/cloudcp/portal/frontend/src/services.ts+++ b/internal/cloudcp/portal/frontend/src/services.ts@@ -29,7 +29,7 @@ import {setValue,setVisible,} from './services_view';-import type { PortalServiceFlowID, VerificationFlowState } from './types';+import type { PortalServiceFlowID, PortalServiceState, VerificationFlowState } from './types';interface VerificationFlowDefinition {requestPath: string;@@ -53,7 +53,8 @@ interface VerificationFlowDefinition {readCodeValue?: () => string;onRequestStart?: () => void;beforeConfirm?: () => boolean;- onConfirmSuccess: (data: any, email?: string) => void;+ applyConfirmSuccessState?: (serviceState: PortalServiceState, data: any, email?: string) => void;+ afterConfirmSuccess?: (data: any, email?: string) => void;renderPanel: (flowState: VerificationFlowState) => void;renderResult?: (result: unknown) => void;}@@ -160,7 +161,7 @@ export function installServicesRuntime(deps: ServicesRuntimeDeps): void {return getServiceState().flows.manage.codeValue;},onRequestStart: function() {},- onConfirmSuccess: function(data) {+ afterConfirmSuccess: function(data) {window.location.href = data.url;},renderPanel: renderManagePanel,@@ -194,12 +195,10 @@ export function installServicesRuntime(deps: ServicesRuntimeDeps): void {serviceState.flows.retrieve.result = null;}, false);},- onConfirmSuccess: function(data) {- updateServiceState(function(serviceState) {- serviceState.flows.retrieve.result = data.license;- serviceState.flows.retrieve.codeValue = '';- setFlowStatus(serviceState, 'retrieve', 'License retrieved successfully.', false);- }, false);+ applyConfirmSuccessState: function(serviceState, data) {+ serviceState.flows.retrieve.result = data.license;+ serviceState.flows.retrieve.codeValue = '';+ setFlowStatus(serviceState, 'retrieve', 'License retrieved successfully.', false);},renderPanel: renderRetrievePanel,},@@ -232,16 +231,12 @@ export function installServicesRuntime(deps: ServicesRuntimeDeps): void {serviceState.flows.export.result = null;}, false);},- onConfirmSuccess: function(data) {- updateServiceState(function(serviceState) {- serviceState.flows.export.result = data;- serviceState.flows.export.codeValue = '';- setFlowStatus(serviceState, 'export', 'Data export retrieved successfully.', false);- }, false);- resetVerificationFlow('export');- updateServiceState(function(serviceState) {- serviceState.flows.export.result = data;- }, false);+ applyConfirmSuccessState: function(serviceState, data) {+ var emailValue = serviceState.flows.export.emailValue;+ resetVerificationFlowState(serviceState, 'export');+ serviceState.flows.export.emailValue = emailValue;+ serviceState.flows.export.result = data;+ setFlowStatus(serviceState, 'export', 'Data export retrieved successfully.', false);},renderPanel: renderExportPanel,renderResult: renderExportResult,@@ -279,20 +274,22 @@ export function installServicesRuntime(deps: ServicesRuntimeDeps): void {}return true;},- onConfirmSuccess: function(data) {+ applyConfirmSuccessState: function(serviceState, data) {+ var emailValue = serviceState.flows.delete.emailValue;+ resetVerificationFlowState(serviceState, 'delete');+ serviceState.flows.delete.emailValue = emailValue;+ setFlowStatus(+ serviceState,+ 'delete',+ data.deleted_count > 0 && data.stripe_reminder ? data.message + ' ' + data.stripe_reminder : data.message,+ false+ );+ },+ afterConfirmSuccess: function() {var checkbox = getElement<HTMLInputElement>('data-delete-confirm-check');if (checkbox) {checkbox.checked = false;}- resetVerificationFlow('delete');- updateServiceState(function(serviceState) {- setFlowStatus(- serviceState,- 'delete',- data.deleted_count > 0 && data.stripe_reminder ? data.message + ' ' + data.stripe_reminder : data.message,- false- );- }, false);},renderPanel: renderDeletePanel,},@@ -364,8 +361,13 @@ export function installServicesRuntime(deps: ServicesRuntimeDeps): void {var data = await api.postCommercialJSON(flow.confirmPath, { email: email, code: code });updateServiceState(function(serviceState) {succeedMutationState(serviceState.flows[flowID].confirm);- }, false);- flow.onConfirmSuccess(data, email);+ if (flow.applyConfirmSuccessState) {+ flow.applyConfirmSuccessState(serviceState, data, email);+ }+ });+ if (flow.afterConfirmSuccess) {+ flow.afterConfirmSuccess(data, email);+ }} catch (err) {var message = err instanceof Error ? err.message : flow.confirmErrorMessage;updateServiceState(function(serviceState) {