d3ro-voice/apps/desktop/tests/unit/license-open-billing.test.ts
Yun Chan 7fe49c437e chore: land in-progress workspace changes before 1.16.2
The tree carried uncommitted work from several areas (web push, mobile
screens, admin charts, test-hygiene cleanup, CI and map docs). It is landed
as one commit so the release pipeline can start from a clean tree; the
desktop transcript-correction behaviour shipped in the previous commit and
is unchanged here.
2026-11-05 21:58:44 +09:00

50 lines
1.7 KiB
TypeScript

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<string, CapturedHandler>()
async function openBilling(tier: 'pro' | 'pro_plus'): Promise<unknown> {
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')
})
})