Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/SkusTest.php
Show All 12 Lines | class SkusTest extends TestCase | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
$this->clearBetaEntitlements(); | $this->clearBetaEntitlements(); | ||||
$this->clearMeetEntitlements(); | $this->clearMeetEntitlements(); | ||||
Sku::where('title', 'test')->delete(); | Sku::withEnvTenantContext()->where('title', 'test')->delete(); | ||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
$this->clearBetaEntitlements(); | $this->clearBetaEntitlements(); | ||||
$this->clearMeetEntitlements(); | $this->clearMeetEntitlements(); | ||||
Sku::where('title', 'test')->delete(); | Sku::withEnvTenantContext()->where('title', 'test')->delete(); | ||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test fetching SKUs list | * Test fetching SKUs list | ||||
*/ | */ | ||||
public function testIndex(): void | public function testIndex(): void | ||||
{ | { | ||||
// Unauth access not allowed | // Unauth access not allowed | ||||
$response = $this->get("api/v4/skus"); | $response = $this->get("api/v4/skus"); | ||||
$response->assertStatus(401); | $response->assertStatus(401); | ||||
$user = $this->getTestUser('john@kolab.org'); | $user = $this->getTestUser('john@kolab.org'); | ||||
$sku = Sku::where('title', 'mailbox')->first(); | $sku = Sku::withEnvTenantContext()->where('title', 'mailbox')->first(); | ||||
// Create an sku for another tenant, to make sure it is not included in the result | // Create an sku for another tenant, to make sure it is not included in the result | ||||
$nsku = Sku::create([ | $nsku = Sku::create([ | ||||
'title' => 'test', | 'title' => 'test', | ||||
'name' => 'Test', | 'name' => 'Test', | ||||
'description' => '', | 'description' => '', | ||||
'active' => true, | 'active' => true, | ||||
'cost' => 100, | 'cost' => 100, | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | public function testUserSkus(): void | ||||
$this->assertSkuElement('storage', $json[1], [ | $this->assertSkuElement('storage', $json[1], [ | ||||
'prio' => 90, | 'prio' => 90, | ||||
'type' => 'user', | 'type' => 'user', | ||||
'handler' => 'storage', | 'handler' => 'storage', | ||||
'enabled' => true, | 'enabled' => true, | ||||
'readonly' => true, | 'readonly' => true, | ||||
'range' => [ | 'range' => [ | ||||
'min' => 2, | 'min' => 5, | ||||
'max' => 100, | 'max' => 100, | ||||
'unit' => 'GB', | 'unit' => 'GB', | ||||
] | ] | ||||
]); | ]); | ||||
$this->assertSkuElement('groupware', $json[2], [ | $this->assertSkuElement('groupware', $json[2], [ | ||||
'prio' => 80, | 'prio' => 80, | ||||
'type' => 'user', | 'type' => 'user', | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | public function testUserSkus(): void | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertCount(1, $json); | $this->assertCount(1, $json); | ||||
$this->assertSame('domain', $json[0]['type']); | $this->assertSame('domain', $json[0]['type']); | ||||
// Test inclusion of beta SKUs | // Test inclusion of beta SKUs | ||||
$sku = Sku::where('title', 'beta')->first(); | $sku = Sku::withEnvTenantContext()->where('title', 'beta')->first(); | ||||
$user->assignSku($sku); | $user->assignSku($sku); | ||||
$response = $this->actingAs($user)->get("api/v4/users/{$user->id}/skus?type=user"); | $response = $this->actingAs($user)->get("api/v4/users/{$user->id}/skus?type=user"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertCount(8, $json); | $this->assertCount(8, $json); | ||||
Show All 19 Lines | class SkusTest extends TestCase | ||||
* Assert content of the SKU element in an API response | * Assert content of the SKU element in an API response | ||||
* | * | ||||
* @param string $sku_title The SKU title | * @param string $sku_title The SKU title | ||||
* @param array $result The result to assert | * @param array $result The result to assert | ||||
* @param array $other Other items the SKU itself does not include | * @param array $other Other items the SKU itself does not include | ||||
*/ | */ | ||||
protected function assertSkuElement($sku_title, $result, $other = []): void | protected function assertSkuElement($sku_title, $result, $other = []): void | ||||
{ | { | ||||
$sku = Sku::where('title', $sku_title)->first(); | $sku = Sku::withEnvTenantContext()->where('title', $sku_title)->first(); | ||||
$this->assertSame($sku->id, $result['id']); | $this->assertSame($sku->id, $result['id']); | ||||
$this->assertSame($sku->title, $result['title']); | $this->assertSame($sku->title, $result['title']); | ||||
$this->assertSame($sku->name, $result['name']); | $this->assertSame($sku->name, $result['name']); | ||||
$this->assertSame($sku->description, $result['description']); | $this->assertSame($sku->description, $result['description']); | ||||
$this->assertSame($sku->cost, $result['cost']); | $this->assertSame($sku->cost, $result['cost']); | ||||
$this->assertSame($sku->units_free, $result['units_free']); | $this->assertSame($sku->units_free, $result['units_free']); | ||||
$this->assertSame($sku->period, $result['period']); | $this->assertSame($sku->period, $result['period']); | ||||
Show All 9 Lines |