/**
 * Unit tests for notifications module — types + validation.
 */

import { describe, it, expect } from 'vitest';
import { RegisterDeviceSchema, UpdatePrefsSchema } from './types.js';

describe('RegisterDeviceSchema', () => {
  it('accepts valid device registration', () => {
    const result = RegisterDeviceSchema.safeParse({
      userId: 'user_123',
      deviceId: 'dev_mac_001',
      platform: 'macos',
    });
    expect(result.success).toBe(true);
  });

  it('accepts with optional fields', () => {
    const result = RegisterDeviceSchema.safeParse({
      userId: 'user_123',
      deviceId: 'dev_ios_001',
      platform: 'ios',
      pushToken: 'apns_token_abc',
      appVersion: '1.2.0',
      osVersion: '17.2',
    });
    expect(result.success).toBe(true);
  });

  it('rejects invalid platform', () => {
    const result = RegisterDeviceSchema.safeParse({
      userId: 'user_123',
      deviceId: 'dev_001',
      platform: 'linux',
    });
    expect(result.success).toBe(false);
  });

  it('rejects missing deviceId', () => {
    const result = RegisterDeviceSchema.safeParse({
      userId: 'user_123',
      platform: 'ios',
    });
    expect(result.success).toBe(false);
  });
});

describe('UpdatePrefsSchema', () => {
  it('accepts partial updates', () => {
    const result = UpdatePrefsSchema.safeParse({
      pushEnabled: false,
      categories: { marketing: false, updates: true },
    });
    expect(result.success).toBe(true);
  });

  it('accepts empty object', () => {
    const result = UpdatePrefsSchema.safeParse({});
    expect(result.success).toBe(true);
  });
});
