import { describe, expect, it } from 'vitest';

import { signRequest, verifyRequestSignature } from './hmac';

describe('integration HMAC', () => {
  it('signs and verifies canonical requests', () => {
    const parts = {
      method: 'POST',
      path: '/api/v1/integrations/whmcs/services',
      query: '',
      body: '{"externalServiceId":"42"}',
      timestamp: '1710000000000',
      nonce: 'nonce-1',
      idempotencyKey: 'idem-1',
    };

    const signature = signRequest('test-secret', parts);
    expect(
      verifyRequestSignature('test-secret', parts, signature, {
        now: 1_710_000_000_000,
      }),
    ).toBe(true);
    expect(verifyRequestSignature('wrong', parts, signature)).toBe(false);
  });
});
