mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-14 19:22:14 +01:00
Added placeholder users; Better exception handling; Enhanced local setup
This commit is contained in:
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace Tests\Unit\Endpoint\Api\V1;
|
||||
|
||||
use App\Models\Organization;
|
||||
use App\Service\Import\Importers\ReportDto;
|
||||
use App\Service\Import\ImportService;
|
||||
use Laravel\Passport\Passport;
|
||||
use Mockery\MockInterface;
|
||||
@@ -20,7 +21,7 @@ class ImportEndpointTest extends ApiEndpointTestAbstract
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.import', ['organization' => $data->organization->id]), [
|
||||
$response = $this->postJson(route('api.v1.import.import', ['organization' => $data->organization->id]), [
|
||||
'type' => 'toggl_time_entries',
|
||||
'data' => 'some data',
|
||||
'options' => [],
|
||||
@@ -41,6 +42,14 @@ class ImportEndpointTest extends ApiEndpointTestAbstract
|
||||
->withArgs(function (Organization $organization, string $importerType, string $data, array $options) use (&$user): bool {
|
||||
return $organization->is($user->organization) && $importerType === 'toggl_time_entries' && $data === 'some data' && $options === [];
|
||||
})
|
||||
->andReturn(new ReportDto(
|
||||
clientsCreated: 1,
|
||||
projectsCreated: 2,
|
||||
tasksCreated: 3,
|
||||
timeEntriesCreated: 4,
|
||||
tagsCreated: 5,
|
||||
usersCreated: 6,
|
||||
))
|
||||
->once();
|
||||
});
|
||||
Passport::actingAs($user->user);
|
||||
@@ -54,5 +63,27 @@ class ImportEndpointTest extends ApiEndpointTestAbstract
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson([
|
||||
'report' => [
|
||||
'clients' => [
|
||||
'created' => 1,
|
||||
],
|
||||
'projects' => [
|
||||
'created' => 2,
|
||||
],
|
||||
'tasks' => [
|
||||
'created' => 3,
|
||||
],
|
||||
'time-entries' => [
|
||||
'created' => 4,
|
||||
],
|
||||
'tags' => [
|
||||
'created' => 5,
|
||||
],
|
||||
'users' => [
|
||||
'created' => 6,
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
85
tests/Unit/Endpoint/Api/V1/UserEndpointTest.php
Normal file
85
tests/Unit/Endpoint/Api/V1/UserEndpointTest.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Endpoint\Api\V1;
|
||||
|
||||
use App\Models\Organization;
|
||||
use App\Models\User;
|
||||
use Laravel\Passport\Passport;
|
||||
|
||||
class UserEndpointTest extends ApiEndpointTestAbstract
|
||||
{
|
||||
public function test_index_returns_members_of_organization(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'users:view',
|
||||
]);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.users.index', $data->organization->id));
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
public function test_invite_placeholder_fails_if_user_does_not_have_permission(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
]);
|
||||
$user = User::factory()->create([
|
||||
'is_placeholder' => true,
|
||||
]);
|
||||
$data->organization->users()->attach($user);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.users.invite-placeholder', ['organization' => $data->organization->id, 'user' => $user->id]));
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(403);
|
||||
}
|
||||
|
||||
public function test_invite_placeholder_fails_if_user_is_not_part_of_organization(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'users:invite-placeholder',
|
||||
]);
|
||||
$otherOrganization = Organization::factory()->create();
|
||||
$user = User::factory()->create([
|
||||
'is_placeholder' => true,
|
||||
]);
|
||||
$otherOrganization->users()->attach($user);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.users.invite-placeholder', ['organization' => $data->organization->id, 'user' => $user->id]));
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(403);
|
||||
}
|
||||
|
||||
public function test_invite_placeholder_returns_400_if_user_is_not_placeholder(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'users:invite-placeholder',
|
||||
]);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.users.invite-placeholder', ['organization' => $data->organization->id, 'user' => $data->user->id]));
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(400);
|
||||
$response->assertExactJson([
|
||||
'error' => true,
|
||||
'key' => 'user_not_placeholder',
|
||||
'message' => 'The given user is not a placeholder',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user