Scrum4Me/__tests__/lib/user-agent.test.ts
Madhura68 13ab53ab8d feat(ST-1135): UA-redirect bij login — phone naar /m/* (T-322/T-323/T-324)
- lib/user-agent.ts (nieuw): isPhoneUA() — Mobi-substring heuristiek
  (telefoons hebben Mobi, tablets/desktop niet)
- actions/auth.ts loginAction: leest user-agent header na session.save();
  phone-UA + actief product → /m/products/[id]/solo, zonder → /m/settings;
  tablet/desktop/null-UA → /dashboard (ongewijzigd)
- Tests: 7 helper-cases + 6 loginAction-paden incl. demo-user

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 10:09:09 +02:00

37 lines
1.4 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { isPhoneUA } from '@/lib/user-agent'
describe('isPhoneUA', () => {
it('iPhone Safari Mobile → true', () => {
const ua = 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 Mobile/15E148 Safari/604.1'
expect(isPhoneUA(ua)).toBe(true)
})
it('Android Chrome (phone) → true', () => {
const ua = 'Mozilla/5.0 (Linux; Android 14; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Mobile Safari/537.36'
expect(isPhoneUA(ua)).toBe(true)
})
it('iPad → false (geen Mobi)', () => {
const ua = 'Mozilla/5.0 (iPad; CPU OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 Safari/604.1'
expect(isPhoneUA(ua)).toBe(false)
})
it('Android tablet (Galaxy Tab) → false', () => {
const ua = 'Mozilla/5.0 (Linux; Android 14; SM-X910) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'
expect(isPhoneUA(ua)).toBe(false)
})
it('Desktop Chrome → false', () => {
const ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'
expect(isPhoneUA(ua)).toBe(false)
})
it('null → false', () => {
expect(isPhoneUA(null)).toBe(false)
})
it('lege string → false', () => {
expect(isPhoneUA('')).toBe(false)
})
})