mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-17 20:52:14 +01:00
Added me endpoints
This commit is contained in:
committed by
Gregor Vostrak
parent
0e7dec2f40
commit
21207a4058
43
tests/Unit/Endpoint/Api/V1/UserEndpointTest.php
Normal file
43
tests/Unit/Endpoint/Api/V1/UserEndpointTest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Endpoint\Api\V1;
|
||||
|
||||
use Laravel\Passport\Passport;
|
||||
|
||||
class UserEndpointTest extends ApiEndpointTestAbstract
|
||||
{
|
||||
public function test_me_fails_when_not_authenticated(): void
|
||||
{
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.users.me'));
|
||||
|
||||
// Assert
|
||||
$response->assertUnauthorized();
|
||||
$response->assertJson(['message' => 'Unauthenticated.']);
|
||||
}
|
||||
|
||||
public function test_me_returns_information_about_the_current_user(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.users.me'));
|
||||
|
||||
// Assert
|
||||
$response->assertSuccessful();
|
||||
$response->assertJson([
|
||||
'data' => [
|
||||
'id' => $data->user->getKey(),
|
||||
'name' => $data->user->name,
|
||||
'email' => $data->user->email,
|
||||
'profile_photo_url' => $data->user->profile_photo_url,
|
||||
'timezone' => $data->user->timezone,
|
||||
'week_start' => $data->user->week_start->value,
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
43
tests/Unit/Endpoint/Api/V1/UserMemberEndpointTest.php
Normal file
43
tests/Unit/Endpoint/Api/V1/UserMemberEndpointTest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Endpoint\Api\V1;
|
||||
|
||||
use App\Models\Member;
|
||||
use App\Models\Organization;
|
||||
use Laravel\Passport\Passport;
|
||||
|
||||
class UserMemberEndpointTest extends ApiEndpointTestAbstract
|
||||
{
|
||||
public function test_my_members_fails_when_not_authenticated(): void
|
||||
{
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.users.members.my-members'));
|
||||
|
||||
// Assert
|
||||
$response->assertUnauthorized();
|
||||
$response->assertJson(['message' => 'Unauthenticated.']);
|
||||
}
|
||||
|
||||
public function test_my_members_returns_information_about_the_organization_membership_of_the_current_user(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission();
|
||||
$otherOrganization = Organization::factory()->create();
|
||||
$otherMember = Member::factory()->forOrganization($otherOrganization)->forUser($data->user)->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.users.members.my-members'));
|
||||
|
||||
// Assert
|
||||
$response->assertSuccessful();
|
||||
$response->assertJsonCount(2, 'data');
|
||||
$otherMemberResponse = collect($response->json('data'))->where('id', '=', $otherMember->getKey())->first();
|
||||
$this->assertNotNull($otherMemberResponse);
|
||||
$this->assertSame($otherMember->organization->getKey(), $otherMemberResponse['organization']['id']);
|
||||
$memberResponse = collect($response->json('data'))->where('id', '=', $data->member->getKey())->first();
|
||||
$this->assertNotNull($memberResponse);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user