Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/Admin/DomainsTest.php
<?php | <?php | ||||
namespace Tests\Feature\Controller\Admin; | namespace Tests\Feature\Controller\Admin; | ||||
use App\Domain; | |||||
use Illuminate\Support\Facades\Queue; | |||||
use Tests\TestCase; | use Tests\TestCase; | ||||
class DomainsTest extends TestCase | class DomainsTest extends TestCase | ||||
{ | { | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
self::useAdminUrl(); | self::useAdminUrl(); | ||||
$this->deleteTestDomain('domainscontroller.com'); | |||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
$this->deleteTestDomain('domainscontroller.com'); | |||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test domains searching (/api/v4/domains) | * Test domains searching (/api/v4/domains) | ||||
*/ | */ | ||||
public function testIndex(): void | public function testIndex(): void | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | public function testIndex(): void | ||||
$response = $this->actingAs($admin)->get("api/v4/domains?owner={$ned->id}"); | $response = $this->actingAs($admin)->get("api/v4/domains?owner={$ned->id}"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertSame(0, $json['count']); | $this->assertSame(0, $json['count']); | ||||
$this->assertCount(0, $json['list']); | $this->assertCount(0, $json['list']); | ||||
} | } | ||||
/** | |||||
* Test domain suspending (POST /api/v4/domains/<domain-id>/suspend) | |||||
*/ | |||||
public function testSuspend(): void | |||||
{ | |||||
Queue::fake(); // disable jobs | |||||
$domain = $this->getTestDomain('domainscontroller.com', [ | |||||
'status' => Domain::STATUS_NEW, | |||||
'type' => Domain::TYPE_EXTERNAL, | |||||
]); | |||||
$user = $this->getTestUser('test@domainscontroller.com'); | |||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | |||||
// Test unauthorized access to admin API | |||||
$response = $this->actingAs($user)->post("/api/v4/domains/{$domain->id}/suspend", []); | |||||
$response->assertStatus(403); | |||||
$this->assertFalse($domain->fresh()->isSuspended()); | |||||
// Test suspending the user | |||||
$response = $this->actingAs($admin)->post("/api/v4/domains/{$domain->id}/suspend", []); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertSame('success', $json['status']); | |||||
$this->assertSame("Domain suspended successfully.", $json['message']); | |||||
$this->assertCount(2, $json); | |||||
$this->assertTrue($domain->fresh()->isSuspended()); | |||||
} | |||||
/** | |||||
* Test user un-suspending (POST /api/v4/users/<user-id>/unsuspend) | |||||
*/ | |||||
public function testUnsuspend(): void | |||||
{ | |||||
Queue::fake(); // disable jobs | |||||
$domain = $this->getTestDomain('domainscontroller.com', [ | |||||
'status' => Domain::STATUS_NEW | Domain::STATUS_SUSPENDED, | |||||
'type' => Domain::TYPE_EXTERNAL, | |||||
]); | |||||
$user = $this->getTestUser('test@domainscontroller.com'); | |||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | |||||
// Test unauthorized access to admin API | |||||
$response = $this->actingAs($user)->post("/api/v4/domains/{$domain->id}/unsuspend", []); | |||||
$response->assertStatus(403); | |||||
$this->assertTrue($domain->fresh()->isSuspended()); | |||||
// Test suspending the user | |||||
$response = $this->actingAs($admin)->post("/api/v4/domains/{$domain->id}/unsuspend", []); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertSame('success', $json['status']); | |||||
$this->assertSame("Domain unsuspended successfully.", $json['message']); | |||||
$this->assertCount(2, $json); | |||||
$this->assertFalse($domain->fresh()->isSuspended()); | |||||
} | |||||
} | } |