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(); | |||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
$this->clearBetaEntitlements(); | $this->clearBetaEntitlements(); | ||||
$this->clearMeetEntitlements(); | $this->clearMeetEntitlements(); | ||||
Sku::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::where('title', 'mailbox')->first(); | ||||
// 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\Mailbox', | |||||
]); | |||||
$nsku->tenant_id = 2; | |||||
$nsku->save(); | |||||
$response = $this->actingAs($user)->get("api/v4/skus"); | $response = $this->actingAs($user)->get("api/v4/skus"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertCount(9, $json); | $this->assertCount(9, $json); | ||||
$this->assertSame(100, $json[0]['prio']); | $this->assertSame(100, $json[0]['prio']); | ||||
Show All 15 Lines | class SkusTest extends TestCase | ||||
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 | |||||
$nsku = Sku::create([ | |||||
'title' => 'test', | |||||
'name' => 'Test', | |||||
'description' => '', | |||||
'active' => true, | |||||
'cost' => 100, | |||||
'handler_class' => 'App\Handlers\Mailbox', | |||||
]); | |||||
$nsku->tenant_id = 2; | |||||
$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(8, $json); | ||||
$this->assertSkuElement('mailbox', $json[0], [ | $this->assertSkuElement('mailbox', $json[0], [ | ||||
▲ Show 20 Lines • Show All 135 Lines • Show Last 20 Lines |