import { describe, expect, it } from 'vitest';
import { generateDeviceToken, hashDeviceToken } from '../infrastructure/device-token.js';
import { generateMemberCode } from '../infrastructure/member-code.js';

describe('club opaque tokens and member codes', () => {
  it('hashDeviceToken is deterministic sha256 hex', () => {
    const token = 'club-token-example';
    expect(hashDeviceToken(token)).toMatch(/^[a-f0-9]{64}$/);
    expect(hashDeviceToken(token)).toBe(hashDeviceToken(token));
    expect(hashDeviceToken(token)).not.toBe(token);
  });

  it('generateDeviceToken returns distinct opaque base64url tokens', () => {
    const first = generateDeviceToken();
    const second = generateDeviceToken();
    expect(first).toMatch(/^[A-Za-z0-9_-]{40,}$/);
    expect(second).toMatch(/^[A-Za-z0-9_-]{40,}$/);
    expect(first).not.toBe(second);
  });

  it('generateMemberCode uses MDV short-code format', () => {
    expect(generateMemberCode()).toMatch(/^MDV-[A-Z0-9]{8}$/);
  });
});
