Files
accounted/lib/branding/__tests__/service.test.ts
T
Jakob Wennberg c74b19df1b Accounted rebrand + swarm-skill cleanup + bank-reconciliation fixes (#643)
* feat(reconciliation): close the bank-feed loop on voucher links and re-tag mis-typed opening balances

Two related fixes to bank reconciliation correctness:

1. Auto-reconcile on voucher link. Linking an invoice or supplier invoice to
   an existing voucher previously advanced only the invoice — the bank
   transaction that paid it kept sitting in the Transactions inbox with a null
   journal_entry_id. linkInvoiceToVoucher / linkSupplierInvoiceToVoucher now
   call autoReconcileTransactionForLinkedVoucher (lib/reconciliation), which
   links the bank transaction to the same verifikat when exactly one unbooked
   line matches it. Best-effort and post-commit: a failure here never fails the
   link. The result surfaces reconciledTransactionId; the inbox row leaves the
   list and the UI shows link_success_tx_reconciled.

2. Re-tag mis-typed opening balances. getReconciliationStatus and the GL-line
   matching RPCs identify a cash account's ingående balans solely by
   journal_entries.source_type='opening_balance'. Companies migrated from other
   systems often booked the bank IB as an ordinary voucher (source_type
   'import' or 'manual'), so it was never excluded and surfaced as a phantom
   reconciliation difference equal to the opening balance. Adds:
   - migration mark_entry_as_opening_balance: a GUC-gated carve-out in the
     immutability trigger plus a SECURITY DEFINER RPC that validates the entry
     (balance-sheet lines only, dated on a fiscal-period boundary), flips the
     source_type, and writes an audit row — no blanket data sweep.
   - POST /api/reconciliation/bank/mark-opening-balance + MarkOpeningBalanceSchema.
   - BankReconciliationView action to trigger it from the IB diff.

The gnubok_create_voucher executor now accepts a typed is_opening_balance flag
and derives source_type='opening_balance' only after validating class 1/2 lines
on the period start, so new IBs land correctly typed.

Covered by lib/reconciliation auto-reconcile tests, voucher-executors tests,
and a mark-entry-as-opening-balance pg-real test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* chore: rebrand gnubok → Accounted and prune swarm agent skills

Product rebrand and skills housekeeping. No runtime behaviour change.

Rebrand: replace user-visible "gnubok" with "Accounted" across docs, READMEs,
in-code comments, doc-site content, MCP skill/resource prose, and the
gnubok-mcp package description. The MCP resource URI scheme is moved gnubok://
→ Accounted:// consistently across resource registrations, the event-type
comment, and the resource/skill tests. Deliberately preserved as stable
identifiers (NOT rebranded): the gnubok-company-id cookie, gnubok_sk_ / gnubok_inv_
token prefixes, the gnubok-mcp npm bridge name, and the AGI <gem:Programnamn>
value (kept 'gnubok' per its source comment — it is the software identifier sent
to Skatteverket and must not churn across visual rebrands).

Skills: remove the 27 swarm-* agent SKILL.md atoms (no longer used; already
absent from the agent_atom_registry in prod), refresh the remaining skill docs,
add the .claude/rules/ path-scoped rule set, and regenerate the
seed_agent_atom_bodies migration + .skill-body-manifest.json via
`npm run skills:generate` so the DB-backed skill bodies match the trimmed set.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-03 10:52:01 +02:00

149 lines
5.9 KiB
TypeScript

import { describe, it, expect, beforeEach, afterEach } from 'vitest'
const ENV_KEYS = [
'NEXT_PUBLIC_BRANDING_APP_NAME',
'NEXT_PUBLIC_BRANDING_APP_DESCRIPTION',
'BRANDING_LEGAL_ENTITY',
'BRANDING_SUPPORT_EMAIL',
'BRANDING_PRIVACY_EMAIL',
'BRANDING_SECURITY_EMAIL',
'NEXT_PUBLIC_BRANDING_AUTH_EMAIL_FROM',
'NEXT_PUBLIC_BRANDING_LOGO_PATH',
'NEXT_PUBLIC_BRANDING_FAVICON_PATH',
'NEXT_PUBLIC_BRANDING_APPLE_ICON_PATH',
'NEXT_PUBLIC_BRANDING_PWA_ICON_BASE',
'NEXT_PUBLIC_BRANDING_THEME_COLOR',
'NEXT_PUBLIC_BRANDING_MANIFEST_THEME_COLOR',
'NEXT_PUBLIC_BRANDING_MANIFEST_BG_COLOR',
'NEXT_PUBLIC_BRANDING_HIDDEN_NAV',
'NEXT_PUBLIC_BRANDING_NAV_DENSITY',
] as const
describe('branding service', () => {
const originalEnv: Record<string, string | undefined> = {}
beforeEach(() => {
for (const key of ENV_KEYS) {
originalEnv[key] = process.env[key]
delete process.env[key]
}
})
afterEach(async () => {
for (const key of ENV_KEYS) {
if (originalEnv[key] === undefined) delete process.env[key]
else process.env[key] = originalEnv[key]
}
const { registerBrandingService } = await import('../service')
registerBrandingService({})
})
it('returns accounted defaults when nothing is overridden', async () => {
const { getBranding } = await import('../service')
const b = getBranding()
expect(b.appName).toBe('Accounted')
expect(b.appDescription).toBe('Ekonomihantering')
expect(b.legalEntity).toBe('Arcim Technology AB')
expect(b.supportEmail).toBe('support@gnubok.se')
expect(b.privacyEmail).toBe('privacy@gnubok.se')
expect(b.securityEmail).toBe('security@arcim.io')
expect(b.authEmailFrom).toBe('noreply@gnubok.se')
expect(b.logoPath).toBe('/accounted-icon.png')
expect(b.faviconPath).toBe('/favicon.ico')
expect(b.appleTouchIconPath).toBe('/icons/icon-192.png')
expect(b.pwaIconBasePath).toBe('/icons')
expect(b.themeColor).toBe('#304D83')
expect(b.manifestThemeColor).toBe('#1a1a1a')
expect(b.manifestBackgroundColor).toBe('#ffffff')
expect(b.hiddenNavHrefs).toEqual([])
expect(b.navDensity).toBe('standard')
})
it('accepts NEXT_PUBLIC_BRANDING_NAV_DENSITY=slim', async () => {
process.env.NEXT_PUBLIC_BRANDING_NAV_DENSITY = 'slim'
const { getBranding } = await import('../service')
expect(getBranding().navDensity).toBe('slim')
})
it('ignores invalid NEXT_PUBLIC_BRANDING_NAV_DENSITY values', async () => {
process.env.NEXT_PUBLIC_BRANDING_NAV_DENSITY = 'compact'
const { getBranding } = await import('../service')
expect(getBranding().navDensity).toBe('standard')
})
it('extension override can set navDensity', async () => {
const { getBranding, registerBrandingService } = await import('../service')
registerBrandingService({ navDensity: 'slim' })
expect(getBranding().navDensity).toBe('slim')
})
it('parses NEXT_PUBLIC_BRANDING_HIDDEN_NAV as comma-separated hrefs', async () => {
process.env.NEXT_PUBLIC_BRANDING_HIDDEN_NAV = '/salary,/salary/employees,/customers'
const { getBranding } = await import('../service')
expect(getBranding().hiddenNavHrefs).toEqual(['/salary', '/salary/employees', '/customers'])
})
it('trims whitespace and drops empty entries in hidden nav list', async () => {
process.env.NEXT_PUBLIC_BRANDING_HIDDEN_NAV = ' /salary , ,/customers, '
const { getBranding } = await import('../service')
expect(getBranding().hiddenNavHrefs).toEqual(['/salary', '/customers'])
})
it('empty NEXT_PUBLIC_BRANDING_HIDDEN_NAV keeps default empty list', async () => {
process.env.NEXT_PUBLIC_BRANDING_HIDDEN_NAV = ''
const { getBranding } = await import('../service')
expect(getBranding().hiddenNavHrefs).toEqual([])
})
it('extension override replaces hiddenNavHrefs', async () => {
process.env.NEXT_PUBLIC_BRANDING_HIDDEN_NAV = '/salary'
const { getBranding, registerBrandingService } = await import('../service')
registerBrandingService({ hiddenNavHrefs: ['/customers', '/suppliers'] })
expect(getBranding().hiddenNavHrefs).toEqual(['/customers', '/suppliers'])
})
it('env vars override defaults', async () => {
process.env.NEXT_PUBLIC_BRANDING_APP_NAME = 'Holdio'
process.env.BRANDING_SUPPORT_EMAIL = 'hello@holdio.se'
process.env.NEXT_PUBLIC_BRANDING_LOGO_PATH = '/holdio-logo.svg'
process.env.NEXT_PUBLIC_BRANDING_AUTH_EMAIL_FROM = 'noreply@holdio.se'
const { getBranding } = await import('../service')
const b = getBranding()
expect(b.appName).toBe('Holdio')
expect(b.supportEmail).toBe('hello@holdio.se')
expect(b.logoPath).toBe('/holdio-logo.svg')
expect(b.authEmailFrom).toBe('noreply@holdio.se')
expect(b.appDescription).toBe('Ekonomihantering')
})
it('extension override beats env vars', async () => {
process.env.NEXT_PUBLIC_BRANDING_APP_NAME = 'EnvName'
const { getBranding, registerBrandingService } = await import('../service')
registerBrandingService({ appName: 'ExtensionName' })
expect(getBranding().appName).toBe('ExtensionName')
})
it('extension partial override leaves untouched fields at default', async () => {
const { getBranding, registerBrandingService } = await import('../service')
registerBrandingService({ appName: 'Holdio' })
const b = getBranding()
expect(b.appName).toBe('Holdio')
expect(b.legalEntity).toBe('Arcim Technology AB')
expect(b.supportEmail).toBe('support@gnubok.se')
})
it('empty string env var does not override', async () => {
process.env.NEXT_PUBLIC_BRANDING_APP_NAME = ''
const { getBranding } = await import('../service')
expect(getBranding().appName).toBe('Accounted')
})
it('clearing extension override returns to env/default resolution', async () => {
const { getBranding, registerBrandingService } = await import('../service')
registerBrandingService({ appName: 'Holdio' })
expect(getBranding().appName).toBe('Holdio')
registerBrandingService({})
expect(getBranding().appName).toBe('Accounted')
})
})