Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/SkusTest.php
Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | public function testDomainSkus(): void | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertCount(1, $json); | $this->assertCount(1, $json); | ||||
$this->assertSkuElement('domain-hosting', $json[0], [ | $this->assertSkuElement('domain-hosting', $json[0], [ | ||||
'prio' => 0, | 'prio' => 0, | ||||
'type' => 'domain', | 'type' => 'domain', | ||||
'handler' => 'domainhosting', | 'handler' => 'DomainHosting', | ||||
'enabled' => false, | 'enabled' => false, | ||||
'readonly' => false, | 'readonly' => false, | ||||
]); | ]); | ||||
} | } | ||||
/** | /** | ||||
* Test fetching SKUs list | * Test fetching SKUs list | ||||
*/ | */ | ||||
Show All 31 Lines | public function testIndex(): void | ||||
$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']); | ||||
$this->assertSame($sku->period, $json[0]['period']); | $this->assertSame($sku->period, $json[0]['period']); | ||||
$this->assertSame($sku->active, $json[0]['active']); | $this->assertSame($sku->active, $json[0]['active']); | ||||
$this->assertSame('user', $json[0]['type']); | $this->assertSame('user', $json[0]['type']); | ||||
$this->assertSame('mailbox', $json[0]['handler']); | $this->assertSame('Mailbox', $json[0]['handler']); | ||||
} | } | ||||
/** | /** | ||||
* Test fetching SKUs list for a user (GET /users/<id>/skus) | * Test fetching SKUs list for a user (GET /users/<id>/skus) | ||||
*/ | */ | ||||
public function testUserSkus(): void | public function testUserSkus(): void | ||||
{ | { | ||||
$user = $this->getTestUser('john@kolab.org'); | $user = $this->getTestUser('john@kolab.org'); | ||||
// Unauth access not allowed | // Unauth access not allowed | ||||
$response = $this->get("api/v4/users/{$user->id}/skus"); | $response = $this->get("api/v4/users/{$user->id}/skus"); | ||||
$response->assertStatus(401); | $response->assertStatus(401); | ||||
// 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, | ||||
'handler_class' => 'App\Handlers\Mailbox', | 'handler_class' => 'Mailbox', | ||||
]); | ]); | ||||
$tenant = Tenant::whereNotIn('id', [\config('app.tenant_id')])->first(); | $tenant = Tenant::whereNotIn('id', [\config('app.tenant_id')])->first(); | ||||
$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(6, $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, | ||||
]); | ]); | ||||
$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' => 5, | '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', | ||||
'handler' => 'groupware', | 'handler' => 'Groupware', | ||||
'enabled' => false, | 'enabled' => false, | ||||
'readonly' => false, | 'readonly' => false, | ||||
]); | ]); | ||||
$this->assertSkuElement('activesync', $json[3], [ | $this->assertSkuElement('activesync', $json[3], [ | ||||
'prio' => 70, | 'prio' => 70, | ||||
'type' => 'user', | 'type' => 'user', | ||||
'handler' => 'activesync', | 'handler' => 'Activesync', | ||||
'enabled' => false, | 'enabled' => false, | ||||
'readonly' => false, | 'readonly' => false, | ||||
'required' => ['groupware'], | 'required' => ['Groupware'], | ||||
]); | ]); | ||||
$this->assertSkuElement('2fa', $json[4], [ | $this->assertSkuElement('2fa', $json[4], [ | ||||
'prio' => 60, | 'prio' => 60, | ||||
'type' => 'user', | 'type' => 'user', | ||||
'handler' => 'auth2f', | 'handler' => 'Auth2F', | ||||
'enabled' => false, | 'enabled' => false, | ||||
'readonly' => false, | 'readonly' => false, | ||||
'forbidden' => ['activesync'], | 'forbidden' => ['Activesync'], | ||||
]); | ]); | ||||
$this->assertSkuElement('meet', $json[5], [ | $this->assertSkuElement('meet', $json[5], [ | ||||
'prio' => 50, | 'prio' => 50, | ||||
'type' => 'user', | 'type' => 'user', | ||||
'handler' => 'meet', | 'handler' => 'Meet', | ||||
'enabled' => false, | 'enabled' => false, | ||||
'readonly' => false, | 'readonly' => false, | ||||
'required' => ['groupware'], | 'required' => ['Groupware'], | ||||
]); | ]); | ||||
// 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"); | $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(10, $json); | $this->assertCount(10, $json); | ||||
$this->assertSkuElement('beta', $json[6], [ | $this->assertSkuElement('beta', $json[6], [ | ||||
'prio' => 10, | 'prio' => 10, | ||||
'type' => 'user', | 'type' => 'user', | ||||
'handler' => 'beta', | 'handler' => 'Beta', | ||||
'enabled' => false, | 'enabled' => false, | ||||
'readonly' => false, | 'readonly' => false, | ||||
]); | ]); | ||||
$this->assertSkuElement('beta-resources', $json[7], [ | $this->assertSkuElement('beta-distlists', $json[7], [ | ||||
'prio' => 10, | 'prio' => 10, | ||||
'type' => 'user', | 'type' => 'user', | ||||
'handler' => 'resources', // TODO: shouldn't it be beta-resources or beta/resources? | 'handler' => 'Beta\Distlists', | ||||
'enabled' => false, | 'enabled' => false, | ||||
'readonly' => false, | 'readonly' => false, | ||||
'required' => ['beta'], | 'required' => ['Beta'], | ||||
]); | ]); | ||||
$this->assertSkuElement('beta-shared-folders', $json[8], [ | $this->assertSkuElement('beta-resources', $json[8], [ | ||||
'prio' => 10, | 'prio' => 10, | ||||
'type' => 'user', | 'type' => 'user', | ||||
'handler' => 'sharedfolders', | 'handler' => 'Beta\Resources', | ||||
'enabled' => false, | 'enabled' => false, | ||||
'readonly' => false, | 'readonly' => false, | ||||
'required' => ['beta'], | 'required' => ['Beta'], | ||||
]); | ]); | ||||
$this->assertSkuElement('distlist', $json[9], [ | $this->assertSkuElement('beta-shared-folders', $json[9], [ | ||||
'prio' => 10, | 'prio' => 10, | ||||
'type' => 'user', | 'type' => 'user', | ||||
'handler' => 'distlist', | 'handler' => 'Beta\SharedFolders', | ||||
'enabled' => false, | 'enabled' => false, | ||||
'readonly' => false, | 'readonly' => false, | ||||
'required' => ['beta'], | '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 |