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 App\Domain; | ||||
use App\Entitlement; | |||||
use App\Sku; | |||||
use Illuminate\Support\Facades\Queue; | use Illuminate\Support\Facades\Queue; | ||||
use Tests\TestCase; | use Tests\TestCase; | ||||
class DomainsTest extends TestCase | class DomainsTest extends TestCase | ||||
{ | { | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
Show All 11 Lines | class DomainsTest extends TestCase | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
$this->deleteTestDomain('domainscontroller.com'); | $this->deleteTestDomain('domainscontroller.com'); | ||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test domains confirming (not implemented) | |||||
*/ | |||||
public function testConfirm(): void | |||||
{ | |||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | |||||
$domain = $this->getTestDomain('kolab.org'); | |||||
// This end-point does not exist for admins | |||||
$response = $this->actingAs($admin)->get("api/v4/domains/{$domain->id}/confirm"); | |||||
$response->assertStatus(404); | |||||
} | |||||
/** | |||||
* Test domains searching (/api/v4/domains) | * Test domains searching (/api/v4/domains) | ||||
*/ | */ | ||||
public function testIndex(): void | public function testIndex(): void | ||||
{ | { | ||||
$john = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | $admin = $this->getTestUser('jeroen@jeroen.jeroen'); | ||||
// Non-admin user | // Non-admin user | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | public function testIndex(): void | ||||
$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 fetching domain info | |||||
*/ | |||||
public function testShow(): void | |||||
{ | |||||
$sku_domain = Sku::where('title', 'domain-hosting')->first(); | |||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | |||||
$user = $this->getTestUser('test1@domainscontroller.com'); | |||||
$domain = $this->getTestDomain('domainscontroller.com', [ | |||||
'status' => Domain::STATUS_NEW, | |||||
'type' => Domain::TYPE_EXTERNAL, | |||||
]); | |||||
Entitlement::create([ | |||||
'wallet_id' => $user->wallets()->first()->id, | |||||
'sku_id' => $sku_domain->id, | |||||
'entitleable_id' => $domain->id, | |||||
'entitleable_type' => Domain::class | |||||
]); | |||||
// Only admins can access it | |||||
$response = $this->actingAs($user)->get("api/v4/domains/{$domain->id}"); | |||||
$response->assertStatus(403); | |||||
$response = $this->actingAs($admin)->get("api/v4/domains/{$domain->id}"); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertEquals($domain->id, $json['id']); | |||||
$this->assertEquals($domain->namespace, $json['namespace']); | |||||
$this->assertEquals($domain->status, $json['status']); | |||||
$this->assertEquals($domain->type, $json['type']); | |||||
// Note: Other properties are being tested in the user controller tests | |||||
} | |||||
/** | |||||
* Test fetching domain status (GET /api/v4/domains/<domain-id>/status) | |||||
*/ | |||||
public function testStatus(): void | |||||
{ | |||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | |||||
$domain = $this->getTestDomain('kolab.org'); | |||||
// This end-point does not exist for admins | |||||
$response = $this->actingAs($admin)->get("/api/v4/domains/{$domain->id}/status"); | |||||
$response->assertStatus(404); | |||||
} | |||||
/** | |||||
* Test domain suspending (POST /api/v4/domains/<domain-id>/suspend) | * Test domain suspending (POST /api/v4/domains/<domain-id>/suspend) | ||||
*/ | */ | ||||
public function testSuspend(): void | public function testSuspend(): void | ||||
{ | { | ||||
Queue::fake(); // disable jobs | Queue::fake(); // disable jobs | ||||
$domain = $this->getTestDomain('domainscontroller.com', [ | $domain = $this->getTestDomain('domainscontroller.com', [ | ||||
'status' => Domain::STATUS_NEW, | 'status' => Domain::STATUS_NEW, | ||||
▲ Show 20 Lines • Show All 57 Lines • Show Last 20 Lines |