/**
 * (exports, toast timing, grant types; regex helpers for IP / referer).
 */
import {
  APPLICATION_LIST_INITIAL_PAGE_SIZE,
  APPLICATION_LIST_PAGE_SIZE,
  APPLICATION_STATUS,
  DEFAULT_GRANT_TYPES,
  FALLBACK_TOAST_DURATION_MS,
  TOAST_EXIT_ANIMATION_MS,
} from '@/constants/application'
import {
  HTTP_REFERER_PATTERN,
  IPV4_WITH_OPTIONAL_CIDR,
  IPV6_WITH_OPTIONAL_CIDR,
} from '@/constants/regex'

describe('[constants/application]', () => {
  describe('exports', () => {
    it('exposes status list, pagination sizes and toast durations', () => {
      expect(APPLICATION_STATUS).toEqual([
        'ACTIVE',
        'INACTIVE',
        'PENDING',
        'APPROVED',
      ])
      expect(APPLICATION_LIST_PAGE_SIZE).toBe(3)
      expect(APPLICATION_LIST_INITIAL_PAGE_SIZE).toBe(6)
      expect(FALLBACK_TOAST_DURATION_MS).toBe(5000)
      expect(TOAST_EXIT_ANIMATION_MS).toBe(300)
      expect(DEFAULT_GRANT_TYPES).toEqual(['password', 'client_credentials'])
    })
  })

  describe('IP regex (BVA-style samples)', () => {
    it('matches representative IPv4 and IPv6 strings', () => {
      expect(IPV4_WITH_OPTIONAL_CIDR.test('192.168.1.1')).toBe(true)
      expect(IPV6_WITH_OPTIONAL_CIDR.test('2001:db8::1')).toBe(true)
    })
  })

  describe('HTTP_REFERER_PATTERN', () => {
    it('accepts host and wildcard-style referer strings', () => {
      expect(HTTP_REFERER_PATTERN.test('www.example.com/path')).toBe(true)
      expect(HTTP_REFERER_PATTERN.test('sub.example.com/*')).toBe(true)
      expect(HTTP_REFERER_PATTERN.test('*.example.com/*')).toBe(true)
    })

    it('rejects URL scheme and invalid host shape', () => {
      expect(HTTP_REFERER_PATTERN.test('https://example.com')).toBe(false)
      expect(HTTP_REFERER_PATTERN.test('example .com')).toBe(false)
    })
  })
})
