import { describe, expect, test } from 'bun:test';

import { createDeviceToken, verifyDeviceToken } from '../utils/device-token';

describe('device token', () => {
  test('roundtrips valid payload', () => {
    const token = createDeviceToken({
      userId: 'user-1',
      deviceId: 'device-1',
      role: 'client',
    }, 60);

    const payload = verifyDeviceToken(token);

    expect(payload).not.toBeNull();
    expect(payload?.userId).toBe('user-1');
    expect(payload?.deviceId).toBe('device-1');
    expect(payload?.role).toBe('client');
  });

  test('rejects malformed tokens', () => {
    expect(verifyDeviceToken('bad-token')).toBeNull();
  });
});
