the middle of the idiots
This commit is contained in:
60
qwen/hack/tests/Models/JobTest.php
Normal file
60
qwen/hack/tests/Models/JobTest.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?hh // strict
|
||||
|
||||
namespace Tests\Models;
|
||||
|
||||
use App\Models\Job;
|
||||
use DateTime;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class JobTest extends TestCase
|
||||
{
|
||||
public function testJobCreation(): void
|
||||
{
|
||||
$job = new Job(
|
||||
id: 1,
|
||||
title: 'Software Engineer',
|
||||
description: 'We are looking for a skilled software engineer...',
|
||||
location: 'New York, NY',
|
||||
employmentType: 'Full-time',
|
||||
tenantId: 'tenant-123'
|
||||
);
|
||||
|
||||
$this->assertEquals(1, $job->getId());
|
||||
$this->assertEquals('Software Engineer', $job->getTitle());
|
||||
$this->assertEquals('We are looking for a skilled software engineer...', $job->getDescription());
|
||||
$this->assertEquals('New York, NY', $job->getLocation());
|
||||
$this->assertEquals('Full-time', $job->getEmploymentType());
|
||||
$this->assertEquals('tenant-123', $job->getTenantId());
|
||||
$this->assertInstanceOf(DateTime::class, $job->getCreatedAt());
|
||||
$this->assertInstanceOf(DateTime::class, $job->getUpdatedAt());
|
||||
}
|
||||
|
||||
public function testJobSetters(): void
|
||||
{
|
||||
$job = new Job(
|
||||
id: 1,
|
||||
title: 'Software Engineer',
|
||||
description: 'We are looking for a skilled software engineer...',
|
||||
location: 'New York, NY',
|
||||
employmentType: 'Full-time',
|
||||
tenantId: 'tenant-123'
|
||||
);
|
||||
|
||||
$originalUpdatedAt = $job->getUpdatedAt();
|
||||
|
||||
// Update the job
|
||||
$job->setTitle('Senior Software Engineer');
|
||||
$job->setDescription('We are looking for a senior software engineer...');
|
||||
$job->setLocation('Remote');
|
||||
$job->setEmploymentType('Contract');
|
||||
|
||||
// Verify updates
|
||||
$this->assertEquals('Senior Software Engineer', $job->getTitle());
|
||||
$this->assertEquals('We are looking for a senior software engineer...', $job->getDescription());
|
||||
$this->assertEquals('Remote', $job->getLocation());
|
||||
$this->assertEquals('Contract', $job->getEmploymentType());
|
||||
|
||||
// Verify that updated_at was updated
|
||||
$this->assertNotEquals($originalUpdatedAt, $job->getUpdatedAt());
|
||||
}
|
||||
}
|
||||
52
qwen/hack/tests/Models/TenantTest.php
Normal file
52
qwen/hack/tests/Models/TenantTest.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?hh // strict
|
||||
|
||||
namespace Tests\Models;
|
||||
|
||||
use App\Models\Tenant;
|
||||
use DateTime;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class TenantTest extends TestCase
|
||||
{
|
||||
public function testTenantCreation(): void
|
||||
{
|
||||
$tenant = new Tenant(
|
||||
id: 'tenant-123',
|
||||
name: 'Test Tenant',
|
||||
subdomain: 'test',
|
||||
isActive: true
|
||||
);
|
||||
|
||||
$this->assertEquals('tenant-123', $tenant->getId());
|
||||
$this->assertEquals('Test Tenant', $tenant->getName());
|
||||
$this->assertEquals('test', $tenant->getSubdomain());
|
||||
$this->assertTrue($tenant->getIsActive());
|
||||
$this->assertInstanceOf(DateTime::class, $tenant->getCreatedAt());
|
||||
$this->assertInstanceOf(DateTime::class, $tenant->getUpdatedAt());
|
||||
}
|
||||
|
||||
public function testTenantSetters(): void
|
||||
{
|
||||
$tenant = new Tenant(
|
||||
id: 'tenant-123',
|
||||
name: 'Test Tenant',
|
||||
subdomain: 'test',
|
||||
isActive: true
|
||||
);
|
||||
|
||||
$originalUpdatedAt = $tenant->getUpdatedAt();
|
||||
|
||||
// Update the tenant
|
||||
$tenant->setName('Updated Test Tenant');
|
||||
$tenant->setSubdomain('updated-test');
|
||||
$tenant->setIsActive(false);
|
||||
|
||||
// Verify updates
|
||||
$this->assertEquals('Updated Test Tenant', $tenant->getName());
|
||||
$this->assertEquals('updated-test', $tenant->getSubdomain());
|
||||
$this->assertFalse($tenant->getIsActive());
|
||||
|
||||
// Verify that updated_at was updated
|
||||
$this->assertNotEquals($originalUpdatedAt, $tenant->getUpdatedAt());
|
||||
}
|
||||
}
|
||||
89
qwen/hack/tests/Services/ComplianceServiceTest.php
Normal file
89
qwen/hack/tests/Services/ComplianceServiceTest.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?hh // strict
|
||||
|
||||
namespace Tests\Services;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\ComplianceService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ComplianceServiceTest extends TestCase
|
||||
{
|
||||
private ComplianceService $complianceService;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->complianceService = new ComplianceService();
|
||||
}
|
||||
|
||||
public function testUserDataCompliance(): void
|
||||
{
|
||||
$user = new User(
|
||||
id: 1,
|
||||
email: 'test@example.com',
|
||||
name: 'Test User',
|
||||
role: 'job_seeker',
|
||||
tenantId: 'tenant-123'
|
||||
);
|
||||
|
||||
$this->assertTrue($this->complianceService->isUserDataCompliant($user));
|
||||
}
|
||||
|
||||
public function testUserDataComplianceWithMissingName(): void
|
||||
{
|
||||
$user = new User(
|
||||
id: 1,
|
||||
email: 'test@example.com',
|
||||
name: '',
|
||||
role: 'job_seeker',
|
||||
tenantId: 'tenant-123'
|
||||
);
|
||||
|
||||
$this->assertFalse($this->complianceService->isUserDataCompliant($user));
|
||||
}
|
||||
|
||||
public function testUserDataComplianceWithMissingEmail(): void
|
||||
{
|
||||
$user = new User(
|
||||
id: 1,
|
||||
email: '',
|
||||
name: 'Test User',
|
||||
role: 'job_seeker',
|
||||
tenantId: 'tenant-123'
|
||||
);
|
||||
|
||||
$this->assertFalse($this->complianceService->isUserDataCompliant($user));
|
||||
}
|
||||
|
||||
public function testJobPostingCompliance(): void
|
||||
{
|
||||
$jobData = [
|
||||
'title' => 'Software Engineer',
|
||||
'description' => 'Looking for a skilled developer',
|
||||
'location' => 'New York'
|
||||
];
|
||||
|
||||
$this->assertTrue($this->complianceService->isJobPostingCompliant($jobData));
|
||||
}
|
||||
|
||||
public function testJobPostingComplianceWithDiscriminatoryLanguage(): void
|
||||
{
|
||||
$jobData = [
|
||||
'title' => 'Software Engineer',
|
||||
'description' => 'Looking for a young male developer under 30',
|
||||
'location' => 'New York'
|
||||
];
|
||||
|
||||
$this->assertFalse($this->complianceService->isJobPostingCompliant($jobData));
|
||||
}
|
||||
|
||||
public function testJobPostingComplianceWithMissingField(): void
|
||||
{
|
||||
$jobData = [
|
||||
'title' => 'Software Engineer',
|
||||
'description' => 'Looking for a skilled developer'
|
||||
// Missing location
|
||||
];
|
||||
|
||||
$this->assertFalse($this->complianceService->isJobPostingCompliant($jobData));
|
||||
}
|
||||
}
|
||||
61
qwen/hack/tests/Services/TenantResolverTest.php
Normal file
61
qwen/hack/tests/Services/TenantResolverTest.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user