Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/SkusTest.php
<?php | <?php | ||||
namespace Tests\Feature\Controller; | namespace Tests\Feature\Controller; | ||||
use App\Http\Controllers\API\V4\SkusController; | |||||
use App\Sku; | use App\Sku; | ||||
use App\Tenant; | use App\Tenant; | ||||
use Tests\TestCase; | use Tests\TestCase; | ||||
class SkusTest extends TestCase | class SkusTest extends TestCase | ||||
{ | { | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
$this->deleteTestUser('jane@kolabnow.com'); | $this->deleteTestUser('jane@kolabnow.com'); | ||||
$this->clearBetaEntitlements(); | $this->clearBetaEntitlements(); | ||||
$this->clearMeetEntitlements(); | |||||
Sku::where('title', 'test')->delete(); | Sku::where('title', 'test')->delete(); | ||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
$this->deleteTestUser('jane@kolabnow.com'); | $this->deleteTestUser('jane@kolabnow.com'); | ||||
$this->clearBetaEntitlements(); | $this->clearBetaEntitlements(); | ||||
$this->clearMeetEntitlements(); | |||||
Sku::where('title', 'test')->delete(); | Sku::where('title', 'test')->delete(); | ||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test fetching SKUs list | * Test fetching SKUs list | ||||
*/ | */ | ||||
Show All 20 Lines | public function testIndex(): void | ||||
$nsku->tenant_id = $tenant->id; | $nsku->tenant_id = $tenant->id; | ||||
$nsku->save(); | $nsku->save(); | ||||
$response = $this->actingAs($john)->get("api/v4/skus"); | $response = $this->actingAs($john)->get("api/v4/skus"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertCount(10, $json); | $this->assertCount(11, $json); | ||||
$this->assertSame(100, $json[0]['prio']); | $this->assertSame(100, $json[0]['prio']); | ||||
$this->assertSame($sku->id, $json[0]['id']); | $this->assertSame($sku->id, $json[0]['id']); | ||||
$this->assertSame($sku->title, $json[0]['title']); | $this->assertSame($sku->title, $json[0]['title']); | ||||
$this->assertSame($sku->name, $json[0]['name']); | $this->assertSame($sku->name, $json[0]['name']); | ||||
$this->assertSame($sku->description, $json[0]['description']); | $this->assertSame($sku->description, $json[0]['description']); | ||||
$this->assertSame($sku->cost, $json[0]['cost']); | $this->assertSame($sku->cost, $json[0]['cost']); | ||||
$this->assertSame($sku->units_free, $json[0]['units_free']); | $this->assertSame($sku->units_free, $json[0]['units_free']); | ||||
Show All 13 Lines | public function testIndex(): void | ||||
$this->assertSame(100, $json[0]['nextCost']); // second domain costs 100 | $this->assertSame(100, $json[0]['nextCost']); // second domain costs 100 | ||||
// Test the type filter, and nextCost property (user with no domain) | // Test the type filter, and nextCost property (user with no domain) | ||||
$jane = $this->getTestUser('jane@kolabnow.com'); | $jane = $this->getTestUser('jane@kolabnow.com'); | ||||
$kolab = \App\Package::withEnvTenantContext()->where('title', 'kolab')->first(); | $kolab = \App\Package::withEnvTenantContext()->where('title', 'kolab')->first(); | ||||
$jane->assignPackage($kolab); | $jane->assignPackage($kolab); | ||||
$response = $this->actingAs($jane)->get("api/v4/skus?type=domain"); | $response = $this->actingAs($jane)->get("api/v4/skus?type=domain"); | ||||
$response->assertStatus(200); | |||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertCount(1, $json); | $this->assertCount(1, $json); | ||||
$this->assertSame('domain-hosting', $json[0]['title']); | $this->assertSame('domain-hosting', $json[0]['title']); | ||||
$this->assertSame(0, $json[0]['nextCost']); // first domain costs 0 | $this->assertSame(0, $json[0]['nextCost']); // first domain costs 0 | ||||
} | } | ||||
} | } |