Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/SkusTest.php
Show All 28 Lines | class SkusTest extends TestCase | ||||
{ | { | ||||
$this->clearBetaEntitlements(); | $this->clearBetaEntitlements(); | ||||
$this->clearMeetEntitlements(); | $this->clearMeetEntitlements(); | ||||
Sku::where('title', 'test')->delete(); | Sku::where('title', 'test')->delete(); | ||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | |||||
* Test fetching SKUs list for a domain (GET /domains/<id>/skus) | |||||
*/ | |||||
public function testDomainSkus(): void | |||||
{ | |||||
$user = $this->getTestUser('john@kolab.org'); | |||||
$domain = $this->getTestDomain('kolab.org'); | |||||
// Unauth access not allowed | |||||
$response = $this->get("api/v4/domains/{$domain->id}/skus"); | |||||
$response->assertStatus(401); | |||||
// Create an sku for another tenant, to make sure it is not included in the result | |||||
$nsku = Sku::create([ | |||||
'title' => 'test', | |||||
'name' => 'Test', | |||||
'description' => '', | |||||
'active' => true, | |||||
'cost' => 100, | |||||
'handler_class' => 'App\Handlers\Domain', | |||||
]); | |||||
$tenant = Tenant::whereNotIn('id', [\config('app.tenant_id')])->first(); | |||||
$nsku->tenant_id = $tenant->id; | |||||
$nsku->save(); | |||||
$response = $this->actingAs($user)->get("api/v4/domains/{$domain->id}/skus"); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertCount(1, $json); | |||||
$this->assertSkuElement('domain-hosting', $json[0], [ | |||||
'prio' => 0, | |||||
'type' => 'domain', | |||||
'handler' => 'domainhosting', | |||||
'enabled' => false, | |||||
'readonly' => false, | |||||
]); | |||||
} | |||||
/** | /** | ||||
* 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"); | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | public function testUserSkus(): void | ||||
$nsku->tenant_id = $tenant->id; | $nsku->tenant_id = $tenant->id; | ||||
$nsku->save(); | $nsku->save(); | ||||
$response = $this->actingAs($user)->get("api/v4/users/{$user->id}/skus"); | $response = $this->actingAs($user)->get("api/v4/users/{$user->id}/skus"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertCount(8, $json); | $this->assertCount(6, $json); | ||||
$this->assertSkuElement('mailbox', $json[0], [ | $this->assertSkuElement('mailbox', $json[0], [ | ||||
'prio' => 100, | 'prio' => 100, | ||||
'type' => 'user', | 'type' => 'user', | ||||
'handler' => 'mailbox', | 'handler' => 'mailbox', | ||||
'enabled' => true, | 'enabled' => true, | ||||
'readonly' => true, | 'readonly' => true, | ||||
]); | ]); | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | public function testUserSkus(): void | ||||
'prio' => 50, | 'prio' => 50, | ||||
'type' => 'user', | 'type' => 'user', | ||||
'handler' => 'meet', | 'handler' => 'meet', | ||||
'enabled' => false, | 'enabled' => false, | ||||
'readonly' => false, | 'readonly' => false, | ||||
'required' => ['groupware'], | 'required' => ['groupware'], | ||||
]); | ]); | ||||
$this->assertSkuElement('domain-hosting', $json[6], [ | |||||
'prio' => 0, | |||||
'type' => 'domain', | |||||
'handler' => 'domainhosting', | |||||
'enabled' => false, | |||||
'readonly' => false, | |||||
]); | |||||
$this->assertSkuElement('group', $json[7], [ | |||||
'prio' => 0, | |||||
'type' => 'group', | |||||
'handler' => 'group', | |||||
'enabled' => false, | |||||
'readonly' => false, | |||||
]); | |||||
// Test filter by type | |||||
$response = $this->actingAs($user)->get("api/v4/users/{$user->id}/skus?type=domain"); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertCount(1, $json); | |||||
$this->assertSame('domain', $json[0]['type']); | |||||
// Test inclusion of beta SKUs | // Test inclusion of beta SKUs | ||||
$sku = Sku::withEnvTenantContext()->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"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertCount(8, $json); | $this->assertCount(8, $json); | ||||
$this->assertSkuElement('meet', $json[5], [ | $this->assertSkuElement('beta', $json[6], [ | ||||
'prio' => 50, | 'prio' => 10, | ||||
'type' => 'user', | 'type' => 'user', | ||||
'handler' => 'meet', | 'handler' => 'beta', | ||||
'enabled' => false, | 'enabled' => false, | ||||
'readonly' => false, | 'readonly' => false, | ||||
'required' => ['groupware'], | |||||
]); | ]); | ||||
$this->assertSkuElement('beta', $json[6], [ | $this->assertSkuElement('distlist', $json[7], [ | ||||
'prio' => 10, | 'prio' => 10, | ||||
'type' => 'user', | 'type' => 'user', | ||||
'handler' => 'beta', | 'handler' => 'distlist', | ||||
'enabled' => false, | 'enabled' => false, | ||||
'readonly' => false, | 'readonly' => false, | ||||
'required' => ['beta'], | |||||
]); | ]); | ||||
} | } | ||||
/** | /** | ||||
* 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 | ||||
Show All 22 Lines |