mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 19:07:41 +00:00
wip(team): tests, account menu org line, i18n sync, dev url handoff
This commit is contained in:
@@ -2,6 +2,7 @@ import { withCloudBuildDefaults } from '../cloud-build-defaults'
|
||||
// Plan & billing for the active Orca profile's signed-in account. Results are values, never
|
||||
// throws, so the renderer can show a precise state. A billing-service refusal never signs the
|
||||
// user out; only Orca Cloud auth rejecting the session does (via runWithFreshOrcaCloudSession).
|
||||
import { appendFile } from 'node:fs/promises'
|
||||
import { app, shell } from 'electron'
|
||||
import type {
|
||||
OrcaBillingCheckoutArgs,
|
||||
@@ -147,7 +148,13 @@ async function openHosted(
|
||||
return { status: 'signed-out' }
|
||||
}
|
||||
// createUrl already restricted this to Stripe's hosted Checkout/Portal hosts.
|
||||
await shell.openExternal(url)
|
||||
const devUrlFile = app.isPackaged
|
||||
? ''
|
||||
: (process.env.ORCA_BILLING_DEV_OPEN_URL_FILE?.trim() ?? '')
|
||||
// Dev automation only: hand the Stripe URL to a test driver instead of the user's browser.
|
||||
await (devUrlFile
|
||||
? appendFile(devUrlFile, `${url}\n`, { mode: 0o600 })
|
||||
: shell.openExternal(url))
|
||||
return { status: 'opened' }
|
||||
} catch (error) {
|
||||
return openResultForError(error)
|
||||
|
||||
@@ -8,9 +8,11 @@ export type BillingSummary = {
|
||||
/** null until the first read answers (or when billing is off for this build/account). */
|
||||
subscribed: boolean | null
|
||||
canManageBilling: boolean
|
||||
/** "Team" when subscribed; null otherwise. */
|
||||
planLabel: string | null
|
||||
}
|
||||
|
||||
let summary: BillingSummary = { subscribed: null, canManageBilling: false }
|
||||
let summary: BillingSummary = { subscribed: null, canManageBilling: false, planLabel: null }
|
||||
const listeners = new Set<() => void>()
|
||||
let lastReadAt = 0
|
||||
let inFlight: Promise<void> | null = null
|
||||
@@ -21,14 +23,16 @@ export function recordBillingStatus(result: OrcaBillingStatusResult): void {
|
||||
result.status === 'ok'
|
||||
? {
|
||||
subscribed: isActivePlan(result.entitlement),
|
||||
canManageBilling: result.entitlement.canManageBilling
|
||||
canManageBilling: result.entitlement.canManageBilling,
|
||||
planLabel: isActivePlan(result.entitlement) ? result.entitlement.planLabel : null
|
||||
}
|
||||
: result.status === 'failed'
|
||||
? summary
|
||||
: { subscribed: null, canManageBilling: false }
|
||||
: { subscribed: null, canManageBilling: false, planLabel: null }
|
||||
if (
|
||||
next.subscribed !== summary.subscribed ||
|
||||
next.canManageBilling !== summary.canManageBilling
|
||||
next.canManageBilling !== summary.canManageBilling ||
|
||||
next.planLabel !== summary.planLabel
|
||||
) {
|
||||
summary = next
|
||||
for (const listener of listeners) {
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { sampleTeam } from '../plan-billing-fixtures'
|
||||
import { checkoutPollVerdict, nextPhaseAfterOpen } from './checkout-flow'
|
||||
|
||||
const order = { interval: 'month' as const, seats: 2 }
|
||||
|
||||
describe('checkoutPollVerdict', () => {
|
||||
it('waits until a subscription exists', () => {
|
||||
expect(checkoutPollVerdict({ ...sampleTeam, plan: null, status: 'none' })).toBe('waiting')
|
||||
})
|
||||
it('is paid once the subscription is active or trialing', () => {
|
||||
expect(checkoutPollVerdict(sampleTeam)).toBe('paid')
|
||||
expect(checkoutPollVerdict({ ...sampleTeam, status: 'trialing' })).toBe('paid')
|
||||
})
|
||||
it('flags a first invoice that needs action (3-D Secure, decline)', () => {
|
||||
expect(checkoutPollVerdict({ ...sampleTeam, status: 'incomplete' })).toBe('needs-attention')
|
||||
expect(checkoutPollVerdict({ ...sampleTeam, status: 'past_due' })).toBe('needs-attention')
|
||||
})
|
||||
})
|
||||
|
||||
describe('nextPhaseAfterOpen', () => {
|
||||
it('awaits payment when the browser opened', () => {
|
||||
expect(nextPhaseAfterOpen(order, { status: 'opened' }, 5)).toEqual({
|
||||
kind: 'awaiting-payment',
|
||||
order,
|
||||
since: 5
|
||||
})
|
||||
})
|
||||
it('reports why Checkout could not open', () => {
|
||||
expect(nextPhaseAfterOpen(order, { status: 'forbidden' }, 5)).toEqual({
|
||||
kind: 'open-failed',
|
||||
order,
|
||||
result: { status: 'forbidden' }
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -16,6 +16,7 @@ import { useMountedRef } from '@/hooks/useMountedRef'
|
||||
import { useOptionalShortcutLabel } from '@/hooks/useShortcutLabel'
|
||||
import { useTranslate } from '@/i18n/use-translate'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { useBillingSummary } from '../../billing/billing-summary-store'
|
||||
import { useSetupGuideProgress } from '../../setup-guide/use-setup-guide-progress'
|
||||
import { getAccountMenuIdentity, type AccountMenuIdentity } from './account-menu-identity'
|
||||
import { selectVisibleAccountMenuItems, useRegisteredAccountMenuItems } from './account-menu-items'
|
||||
@@ -66,6 +67,14 @@ export function SidebarAccountMenu(): React.JSX.Element {
|
||||
const mountedRef = useMountedRef()
|
||||
|
||||
const identity = getAccountMenuIdentity(authStatus)
|
||||
const billingSummary = useBillingSummary()
|
||||
const orgName = authStatus?.state === 'connected' ? authStatus.cloud?.activeOrgName : undefined
|
||||
// "Acme · Team": which team this account acts for, and its plan once billing has answered.
|
||||
const orgLine = orgName
|
||||
? billingSummary.planLabel
|
||||
? `${orgName} · ${billingSummary.planLabel}`
|
||||
: orgName
|
||||
: null
|
||||
const extensionItems = selectVisibleAccountMenuItems(registeredItems, authStatus)
|
||||
const milestones =
|
||||
setupProgress.ready && setupProgress.coreDoneCount < setupProgress.coreTotal
|
||||
@@ -158,6 +167,9 @@ export function SidebarAccountMenu(): React.JSX.Element {
|
||||
{identity.email}
|
||||
</span>
|
||||
) : null}
|
||||
{orgLine ? (
|
||||
<span className="truncate text-xs text-muted-foreground">{orgLine}</span>
|
||||
) : null}
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
|
||||
-21
@@ -209,27 +209,6 @@
|
||||
"tokensAndCost_other": "{{tokens}} tokens · {{cost}}"
|
||||
}
|
||||
},
|
||||
"billing": {
|
||||
"team": {
|
||||
"askAdmin": "Only owners and admins can invite or remove members.",
|
||||
"cannotChangeOwnRole": "You cannot change your own role.",
|
||||
"cannotRemoveSelf": "You cannot remove yourself.",
|
||||
"invite": "Invite",
|
||||
"inviteEmail": "Email to invite",
|
||||
"invitePlaceholder": "teammate@company.com",
|
||||
"invited": "Invite sent to {{value0}}. They join (and become a billed seat) when they accept.",
|
||||
"memberCount": "{{value0}} members",
|
||||
"memberSeats": "{{value0}} members · {{value1}} seats billed. Seats follow membership; pending invites are free until accepted.",
|
||||
"pending": "Pending invites",
|
||||
"remove": "Remove {{value0}}",
|
||||
"removeDescription2": "They lose access to the org right away. Their seat stays paid until your plan renews, then drops off.",
|
||||
"removed": "Member removed.",
|
||||
"revoke": "Revoke",
|
||||
"revoked": "Invite revoked.",
|
||||
"roleChanged": "Role updated.",
|
||||
"seatsDrop": "Seats paid this period stay until {{value0}}, then drop to {{value1}}."
|
||||
}
|
||||
},
|
||||
"browser-pane": {
|
||||
"markup": {
|
||||
"errorAttach": "Could not attach the markup screenshot.",
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { findOrcaBillingReturnLink, parseOrcaBillingReturnLink } from './orca-billing'
|
||||
|
||||
describe('parseOrcaBillingReturnLink', () => {
|
||||
it('accepts only the three return outcomes', () => {
|
||||
expect(parseOrcaBillingReturnLink('orca://billing/return?checkout=success')).toEqual({
|
||||
kind: 'checkout-success'
|
||||
})
|
||||
expect(parseOrcaBillingReturnLink('orca://billing/return?checkout=cancel')).toEqual({
|
||||
kind: 'checkout-cancel'
|
||||
})
|
||||
expect(parseOrcaBillingReturnLink('orca://billing/return?portal=return')).toEqual({
|
||||
kind: 'portal'
|
||||
})
|
||||
})
|
||||
it('rejects other hosts, paths, schemes and junk', () => {
|
||||
for (const raw of [
|
||||
'orca://billing/return',
|
||||
'orca://billing/return?checkout=paid',
|
||||
'orca://evil/return?checkout=success',
|
||||
'orca://billing/other?checkout=success',
|
||||
'https://billing/return?checkout=success',
|
||||
'not a url'
|
||||
]) {
|
||||
expect(parseOrcaBillingReturnLink(raw)).toBeNull()
|
||||
}
|
||||
})
|
||||
it('finds the link among launch arguments', () => {
|
||||
expect(
|
||||
findOrcaBillingReturnLink([
|
||||
'/Applications/Orca.app',
|
||||
'--x',
|
||||
'orca://billing/return?checkout=cancel'
|
||||
])
|
||||
).toEqual({ kind: 'checkout-cancel' })
|
||||
expect(findOrcaBillingReturnLink(['--flag'])).toBeNull()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user