Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/AuthTest.php
Show First 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | public function testLogin(): string | ||||
$response->assertStatus(401); | $response->assertStatus(401); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertSame('error', $json['status']); | $this->assertSame('error', $json['status']); | ||||
$this->assertSame('Invalid username or password.', $json['message']); | $this->assertSame('Invalid username or password.', $json['message']); | ||||
// Valid user+password | // Valid user+password | ||||
$user = $this->getTestUser('john@kolab.org'); | |||||
$post = ['email' => 'john@kolab.org', 'password' => 'simple123']; | $post = ['email' => 'john@kolab.org', 'password' => 'simple123']; | ||||
$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']); | ||||
$this->assertEquals($user->id, $json['id']); | |||||
$this->assertEquals($user->email, $json['email']); | |||||
$this->assertTrue(is_array($json['statusInfo'])); | |||||
$this->assertTrue(is_array($json['settings'])); | |||||
$this->assertTrue(is_array($json['aliases'])); | |||||
// Valid user+password (upper-case) | // Valid user+password (upper-case) | ||||
$post = ['email' => 'John@Kolab.org', 'password' => 'simple123']; | $post = ['email' => 'John@Kolab.org', 'password' => 'simple123']; | ||||
$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'])); | ||||
▲ Show 20 Lines • Show All 76 Lines • Show Last 20 Lines |