Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/UsersTest.php
Show First 20 Lines • Show All 249 Lines • ▼ Show 20 Lines | public function testLogin(): string | ||||
$response = $this->post("api/auth/login", $post); | $response = $this->post("api/auth/login", $post); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$this->assertTrue(!empty($json['access_token'])); | $this->assertTrue(!empty($json['access_token'])); | ||||
$this->assertEquals(\config('jwt.ttl') * 60, $json['expires_in']); | $this->assertEquals(\config('jwt.ttl') * 60, $json['expires_in']); | ||||
$this->assertEquals('bearer', $json['token_type']); | $this->assertEquals('bearer', $json['token_type']); | ||||
// TODO: We have browser tests for 2FA but we should probably also test it here | |||||
return $json['access_token']; | return $json['access_token']; | ||||
} | } | ||||
/** | /** | ||||
* Test /api/auth/logout | * Test /api/auth/logout | ||||
* | * | ||||
* @depends testLogin | * @depends testLogin | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 177 Lines • ▼ Show 20 Lines | public function testShow(): void | ||||
$response = $this->actingAs($john)->get("/api/v4/users/{$ned->id}"); | $response = $this->actingAs($john)->get("/api/v4/users/{$ned->id}"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$storage_sku = Sku::where('title', 'storage')->first(); | $storage_sku = Sku::where('title', 'storage')->first(); | ||||
$groupware_sku = Sku::where('title', 'groupware')->first(); | $groupware_sku = Sku::where('title', 'groupware')->first(); | ||||
$mailbox_sku = Sku::where('title', 'mailbox')->first(); | $mailbox_sku = Sku::where('title', 'mailbox')->first(); | ||||
$secondfactor_sku = Sku::where('title', '2fa')->first(); | |||||
$this->assertCount(3, $json['skus']); | $this->assertCount(4, $json['skus']); | ||||
$this->assertSame(2, $json['skus'][$storage_sku->id]['count']); | $this->assertSame(2, $json['skus'][$storage_sku->id]['count']); | ||||
$this->assertSame(1, $json['skus'][$groupware_sku->id]['count']); | $this->assertSame(1, $json['skus'][$groupware_sku->id]['count']); | ||||
$this->assertSame(1, $json['skus'][$mailbox_sku->id]['count']); | $this->assertSame(1, $json['skus'][$mailbox_sku->id]['count']); | ||||
$this->assertSame(1, $json['skus'][$secondfactor_sku->id]['count']); | |||||
} | } | ||||
/** | /** | ||||
* Test user creation (POST /api/v4/users) | * Test user creation (POST /api/v4/users) | ||||
*/ | */ | ||||
public function testStore(): void | public function testStore(): void | ||||
{ | { | ||||
$jack = $this->getTestUser('jack@kolab.org'); | $jack = $this->getTestUser('jack@kolab.org'); | ||||
▲ Show 20 Lines • Show All 374 Lines • Show Last 20 Lines |