Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/Reseller/SkusTest.php
Show All 9 Lines | class SkusTest extends TestCase | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
self::useResellerUrl(); | self::useResellerUrl(); | ||||
\config(['app.tenant_id' => 1]); | Sku::where('title', 'test')->delete(); | ||||
$this->clearBetaEntitlements(); | $this->clearBetaEntitlements(); | ||||
$this->clearMeetEntitlements(); | $this->clearMeetEntitlements(); | ||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
\config(['app.tenant_id' => 1]); | Sku::where('title', 'test')->delete(); | ||||
$this->clearBetaEntitlements(); | $this->clearBetaEntitlements(); | ||||
$this->clearMeetEntitlements(); | $this->clearMeetEntitlements(); | ||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test fetching SKUs list | * Test fetching SKUs list | ||||
*/ | */ | ||||
public function testIndex(): void | public function testIndex(): void | ||||
{ | { | ||||
$reseller1 = $this->getTestUser('reseller@kolabnow.com'); | $reseller1 = $this->getTestUser('reseller@' . \config('app.domain')); | ||||
$reseller2 = $this->getTestUser('reseller@reseller.com'); | $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local'); | ||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | $admin = $this->getTestUser('jeroen@jeroen.jeroen'); | ||||
$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(); | ||||
// 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 access not allowed on admin API | // User access not allowed | ||||
$response = $this->actingAs($user)->get("api/v4/skus"); | $response = $this->actingAs($user)->get("api/v4/skus"); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
// Admin access not allowed | // Admin access not allowed | ||||
$response = $this->actingAs($admin)->get("api/v4/skus"); | $response = $this->actingAs($admin)->get("api/v4/skus"); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
$response = $this->actingAs($reseller1)->get("api/v4/skus"); | $response = $this->actingAs($reseller1)->get("api/v4/skus"); | ||||
Show All 10 Lines | public function testIndex(): void | ||||
$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']); | ||||
// TODO: Test limiting SKUs to the tenant's SKUs | // Test with another tenant | ||||
$sku = Sku::where('title', 'mailbox')->where('tenant_id', $reseller2->tenant_id)->first(); | |||||
$response = $this->actingAs($reseller2)->get("api/v4/skus"); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertCount(6, $json); | |||||
$this->assertSame(100, $json[0]['prio']); | |||||
$this->assertSame($sku->id, $json[0]['id']); | |||||
$this->assertSame($sku->title, $json[0]['title']); | |||||
$this->assertSame($sku->name, $json[0]['name']); | |||||
$this->assertSame($sku->description, $json[0]['description']); | |||||
$this->assertSame($sku->cost, $json[0]['cost']); | |||||
$this->assertSame($sku->units_free, $json[0]['units_free']); | |||||
$this->assertSame($sku->period, $json[0]['period']); | |||||
$this->assertSame($sku->active, $json[0]['active']); | |||||
$this->assertSame('user', $json[0]['type']); | |||||
$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 | ||||
{ | { | ||||
$reseller1 = $this->getTestUser('reseller@kolabnow.com'); | $reseller1 = $this->getTestUser('reseller@' . \config('app.domain')); | ||||
$reseller2 = $this->getTestUser('reseller@reseller.com'); | $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local'); | ||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | $admin = $this->getTestUser('jeroen@jeroen.jeroen'); | ||||
$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); | ||||
// User access not allowed | // User access not allowed | ||||
$response = $this->actingAs($user)->get("api/v4/users/{$user->id}/skus"); | $response = $this->actingAs($user)->get("api/v4/users/{$user->id}/skus"); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
// Admin access not allowed | // Admin access not allowed | ||||
$response = $this->actingAs($admin)->get("api/v4/users/{$user->id}/skus"); | $response = $this->actingAs($admin)->get("api/v4/users/{$user->id}/skus"); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
// Reseller from another tenant not allowed | // Reseller from another tenant | ||||
$response = $this->actingAs($reseller2)->get("api/v4/users/{$user->id}/skus"); | $response = $this->actingAs($reseller2)->get("api/v4/users/{$user->id}/skus"); | ||||
$response->assertStatus(403); | $response->assertStatus(404); | ||||
// Reseller access | // Reseller access | ||||
$response = $this->actingAs($reseller1)->get("api/v4/users/{$user->id}/skus"); | $response = $this->actingAs($reseller1)->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); | ||||
// Note: Details are tested where we test API\V4\SkusController | // Note: Details are tested where we test API\V4\SkusController | ||||
// Reseller from another tenant not allowed | |||||
\config(['app.tenant_id' => 2]); | |||||
$response = $this->actingAs($reseller2)->get("api/v4/users/{$user->id}/skus"); | |||||
$response->assertStatus(404); | |||||
} | } | ||||
} | } |