Files
Goostaf 6ac9679fb5 feat(auth): base available login methods off GoTrue providers (#1869)
* feat(auth): base login fields on GoTrue providers

Signed-off-by: Goostaf <gasplund2@gmail.com>

# Conflicts:
#	app/(auth)/login/login-client.tsx
#	app/(auth)/register/page.tsx

* fix: address feedback

Signed-off-by: Goostaf <gasplund2@gmail.com>

* chore: remove hardcoded Google enabled checks

Signed-off-by: Goostaf <gasplund2@gmail.com>

# Conflicts:
#	.env.example

* feat: show label when password login is disabled

Signed-off-by: Goostaf <gasplund2@gmail.com>

* feat: use MicrosoftMark, correct comment

Signed-off-by: Goostaf <gasplund2@gmail.com>

* feat: display custom providers

Signed-off-by: Goostaf <gasplund2@gmail.com>

* feat: show when no methods are available

Signed-off-by: Goostaf <gasplund2@gmail.com>

* feat: display custom provider labels

Signed-off-by: Goostaf <gasplund2@gmail.com>

* feat: add SAML login path

Signed-off-by: Goostaf <gasplund2@gmail.com>

* feat: show when no methods are available

Signed-off-by: Goostaf <gasplund2@gmail.com>

* fix: display SAML button when enabled

Signed-off-by: Goostaf <gasplund2@gmail.com>

* fix: preserve nextPath and broken key

Signed-off-by: Goostaf <gasplund2@gmail.com>

* fix: redirect test to client

Signed-off-by: Goostaf <gasplund2@gmail.com>

* fix: expose registerEnabled

Signed-off-by: Goostaf <gasplund2@gmail.com>

* feat: provider allowlist and request timeout

Signed-off-by: Goostaf <gasplund2@gmail.com>

* fix: restore compact labels

Signed-off-by: Goostaf <gasplund2@gmail.com>

* refactor: move withTimeout implementation to utils

Signed-off-by: Goostaf <gasplund2@gmail.com>

* fix: include nextPath

Signed-off-by: Goostaf <gasplund2@gmail.com>

* fix: export function and test case

Signed-off-by: Goostaf <gasplund2@gmail.com>

* feat: only show SAML button if vars configured

Signed-off-by: Goostaf <gasplund2@gmail.com>

* fix(auth): map SAML sign-in error through getErrorMessage

The antipattern ratchet (check:guards, raw-user-error) rejects a raw
error.message reaching a user-visible sink. Route the signInWithSSO
error through getErrorMessage like the other auth error paths.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013BAzJjXQBa9F5L1U42wUMj
Signed-off-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com>

* feat(auth): GitHub brand mark on the provider button; decision log

GitHub allows its invertocat in solid black/white, so currentColor is
correct; custom OIDC providers keep the generic key icon.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013BAzJjXQBa9F5L1U42wUMj
Signed-off-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com>

---------

Signed-off-by: Goostaf <gasplund2@gmail.com>
Signed-off-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com>
Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-31 09:13:39 +01:00

63 lines
2.7 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { swedishToday, formatCurrency, withTimeout } from '../utils'
describe('swedishToday', () => {
it('formats the date as ISO yyyy-MM-dd with a Swedish weekday', () => {
// 2026-01-01 is a Thursday → "torsdag". Noon UTC keeps us clear of any
// midnight boundary so the assertion is timezone-stable.
expect(swedishToday(new Date('2026-01-01T12:00:00Z'))).toBe('2026-01-01 (torsdag)')
})
it('reports the date in Europe/Stockholm, not UTC', () => {
// 23:30 UTC on 2026-05-26 is already 01:30 on 2026-05-27 in Stockholm
// (CEST, UTC+2). A naive UTC date would read the day before: the off-by-one
// we explicitly format around for users near midnight.
expect(swedishToday(new Date('2026-05-26T23:30:00Z'))).toBe('2026-05-27 (onsdag)')
})
it('omits clock time so the cached prompt prefix stays stable across a day', () => {
const morning = swedishToday(new Date('2026-05-27T06:00:00Z'))
const evening = swedishToday(new Date('2026-05-27T18:00:00Z'))
expect(morning).toBe(evening)
expect(morning).not.toMatch(/\d{2}:\d{2}/)
})
})
describe('formatCurrency', () => {
it('falls back to SEK for a NULL currency instead of throwing', () => {
// transactions.currency is nullable and NULL is legacy for the 'SEK'
// column default (migration 20260726100000), but the Transaction type
// declares it required. Intl throws RangeError on `currency: null`, and
// one such row used to blank the whole transactions list.
expect(() => formatCurrency(1234.5, null)).not.toThrow()
expect(formatCurrency(1234.5, null)).toBe(formatCurrency(1234.5, 'SEK'))
})
it('falls back to SEK for undefined and for an empty string', () => {
expect(formatCurrency(10, undefined)).toBe(formatCurrency(10, 'SEK'))
expect(formatCurrency(10, '')).toBe(formatCurrency(10, 'SEK'))
expect(formatCurrency(10)).toBe(formatCurrency(10, 'SEK'))
})
it('still honours a real currency code', () => {
expect(formatCurrency(10, 'EUR')).toContain('€')
})
})
describe('withTimeout', () => {
it('resolves with the promise value when it settles in time', async () => {
const result = await withTimeout(Promise.resolve('ok'), 1000)
expect(result).toBe('ok')
})
it('rejects when the promise exceeds the deadline', async () => {
const slow = new Promise<string>((resolve) => setTimeout(() => resolve('late'), 200))
await expect(withTimeout(slow, 50)).rejects.toThrow('Timeout after 50ms')
})
it('rejects when the promise itself rejects', async () => {
const failing = Promise.reject(new Error('boom'))
await expect(withTimeout(failing, 1000)).rejects.toThrow('boom')
})
})