Files
MOHPortalTest-AllAgents-All…/qwen/hack/tests/Services/TenantResolverTest.php
2025-10-24 16:29:40 -05:00

61 lines
1.9 KiB
PHP

<?hh // strict
namespace Tests\Services;
use App\Services\TenantResolver;
use PHPUnit\Framework\TestCase;
use Slim\Psr7\Factory\ServerRequestFactory;
class TenantResolverTest extends TestCase
{
private TenantResolver $tenantResolver;
protected function setUp(): void
{
$this->tenantResolver = new TenantResolver();
}
public function testResolveTenantFromSubdomain(): void
{
$requestFactory = new ServerRequestFactory();
$request = $requestFactory->createServerRequest('GET', 'https://abc.merchantsofhope.org');
$tenant = $this->tenantResolver->resolveTenant($request);
$this->assertNotNull($tenant);
$this->assertEquals('abc', $tenant->getSubdomain());
$this->assertEquals('Abc Tenant', $tenant->getName());
}
public function testResolveTenantFromPath(): void
{
$requestFactory = new ServerRequestFactory();
$request = $requestFactory->createServerRequest('GET', 'https://merchantsofhope.org/xyz');
$tenant = $this->tenantResolver->resolveTenant($request);
$this->assertNotNull($tenant);
$this->assertEquals('xyz', $tenant->getSubdomain());
$this->assertEquals('Xyz Tenant', $tenant->getName());
}
public function testResolveTenantWithNoTenant(): void
{
$requestFactory = new ServerRequestFactory();
$request = $requestFactory->createServerRequest('GET', 'https://merchantsofhope.org');
$tenant = $this->tenantResolver->resolveTenant($request);
$this->assertNull($tenant);
}
public function testResolveTenantFromInvalidSubdomain(): void
{
$requestFactory = new ServerRequestFactory();
$request = $requestFactory->createServerRequest('GET', 'https://merchantsofhope.org');
$tenant = $this->tenantResolver->resolveTenant($request);
$this->assertNull($tenant);
}
}