import { beforeEach, describe, expect, it, vi } from 'vitest' import { app, ipcMain, shell } from 'electron' import { IPC_CHANNELS } from '@d3ro/core/ipc-channels' vi.mock('../../src/main/services/LicenseService', () => ({ getLicenseService: () => ({ on: vi.fn() }) })) import { registerLicenseHandlers } from '../../src/main/ipc/license-handlers' type CapturedHandler = (...args: unknown[]) => unknown const handlers = new Map() async function openBilling(tier: 'pro' | 'pro_plus'): Promise { const handler = handlers.get(IPC_CHANNELS.LICENSE.OPEN_BILLING) if (!handler) throw new Error('Missing OPEN_BILLING handler') return handler({}, { tier }) } function setPackaged(value: boolean): void { Object.defineProperty(app, 'isPackaged', { value, configurable: true, writable: true }) } beforeEach(() => { vi.clearAllMocks() handlers.clear() vi.mocked(ipcMain.handle).mockImplementation((channel: string, handler: CapturedHandler) => { handlers.set(channel, handler) }) registerLicenseHandlers() }) describe('LICENSE.OPEN_BILLING', () => { it('opens the single web billing entry with the chosen tier in packaged builds', async () => { setPackaged(true) try { await expect(openBilling('pro_plus')).resolves.toEqual({ success: true, data: undefined }) expect(shell.openExternal).toHaveBeenCalledWith('https://d3ro.chanpaca.net/app/billing?tier=pro_plus') } finally { setPackaged(false) } }) it('opens the local web app under the same base path in development', async () => { setPackaged(false) await openBilling('pro') expect(shell.openExternal).toHaveBeenCalledWith('http://localhost:3000/app/billing?tier=pro') }) })