import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';

describe('whmcs phase d sso contract', () => {
  it('documents SSO create and consume routes', () => {
    const whmcsSource = readFileSync(
      join(process.cwd(), 'src', 'integrations/whmcs/whmcs-integration.controller.ts'),
      'utf8',
    );
    assert.ok(whmcsSource.includes("'services/:externalServiceId/sso'"));

    const authSource = readFileSync(
      join(process.cwd(), 'src', 'auth/auth.controller.ts'),
      'utf8',
    );
    assert.ok(authSource.includes("'sso/consume'"));

    const ssoServiceSource = readFileSync(
      join(process.cwd(), 'src', 'auth/sso.service.ts'),
      'utf8',
    );
    assert.ok(ssoServiceSource.includes('createWhmcsServiceSso'));
    assert.ok(ssoServiceSource.includes('consumeTicket'));
    assert.ok(ssoServiceSource.includes('isImpersonation'));
  });

  it('documents WHMCS PHP SSO hooks', () => {
    const phpSource = readFileSync(
      join(
        process.cwd(),
        '..',
        '..',
        'integrations/whmcs/modules/servers/hexagamecloud/hexagamecloud.php',
      ),
      'utf8',
    );
    assert.ok(phpSource.includes('ServiceSingleSignOn'));
    assert.ok(phpSource.includes('AdminSingleSignOn'));
  });
});
