mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-14 19:22:14 +01:00
Add organization setting employees_can_see_billable_rates
This commit is contained in:
committed by
Constantin Graf
parent
9d279d4980
commit
51cd919db6
@@ -53,6 +53,32 @@ abstract class TestCaseWithDatabase extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
public function createUserWithRole(Role $role): object
|
||||
{
|
||||
$owner = User::factory()->create();
|
||||
$organization = Organization::factory()->withOwner($owner)->create();
|
||||
$ownerMember = Member::factory()->forUser($owner)->forOrganization($organization)->role(Role::Owner)->create();
|
||||
$owner->currentOrganization()->associate($organization);
|
||||
$owner->save();
|
||||
|
||||
if ($role === Role::Owner) {
|
||||
$user = $owner;
|
||||
$member = $ownerMember;
|
||||
} else {
|
||||
$user = User::factory()->create();
|
||||
$member = Member::factory()->forUser($user)->forOrganization($organization)->role($role)->create();
|
||||
$user->currentOrganization()->associate($organization);
|
||||
}
|
||||
|
||||
return (object) [
|
||||
'user' => $user,
|
||||
'organization' => $organization,
|
||||
'member' => $member,
|
||||
'owner' => $owner,
|
||||
'ownerMember' => $ownerMember,
|
||||
];
|
||||
}
|
||||
|
||||
protected function enableQueryLog(): void
|
||||
{
|
||||
DB::flushQueryLog();
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Endpoint\Api\V1;
|
||||
|
||||
use App\Enums\Role;
|
||||
use App\Http\Controllers\Api\V1\OrganizationController;
|
||||
use App\Models\Organization;
|
||||
use App\Service\BillableRateService;
|
||||
@@ -58,6 +59,40 @@ class OrganizationEndpointTest extends ApiEndpointTestAbstract
|
||||
$response->assertJsonPath('data.id', $data->organization->getKey());
|
||||
}
|
||||
|
||||
public function test_show_endpoint_shows_billable_rate_for_members_with_role_employee_if_organization_allows_it(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithRole(Role::Employee);
|
||||
$data->organization->employees_can_see_billable_rates = true;
|
||||
$data->organization->billable_rate = 100;
|
||||
$data->organization->save();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.organizations.show', [$data->organization->getKey()]));
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$response->assertJsonPath('data.billable_rate', 100);
|
||||
}
|
||||
|
||||
public function test_show_endpoint_does_not_show_billable_rate_for_members_with_role_employee_if_organization_does_not_allow_it(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithRole(Role::Employee);
|
||||
$data->organization->employees_can_see_billable_rates = false;
|
||||
$data->organization->billable_rate = 100;
|
||||
$data->organization->save();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.organizations.show', [$data->organization->getKey()]));
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$response->assertJsonPath('data.billable_rate', null);
|
||||
}
|
||||
|
||||
public function test_update_endpoint_fails_if_user_has_no_permission_to_update_organizations(): void
|
||||
{
|
||||
// Arrange
|
||||
@@ -123,6 +158,32 @@ class OrganizationEndpointTest extends ApiEndpointTestAbstract
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_update_endpoint_can_update_the_setting_employees_can_see_billable_rates(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'organizations:update',
|
||||
]);
|
||||
$this->assertBillableRateServiceIsUnused();
|
||||
$data->organization->employees_can_see_billable_rates = false;
|
||||
$data->organization->save();
|
||||
$organizationFake = Organization::factory()->make();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->putJson(route('api.v1.organizations.update', [$data->organization->getKey()]), [
|
||||
'name' => $organizationFake->name,
|
||||
'employees_can_see_billable_rates' => true,
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$this->assertDatabaseHas(Organization::class, [
|
||||
'name' => $organizationFake->name,
|
||||
'employees_can_see_billable_rates' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_update_endpoint_can_update_billable_rate_of_organization_and_update_time_entries(): void
|
||||
{
|
||||
// Arrange
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Endpoint\Api\V1;
|
||||
|
||||
use App\Enums\Role;
|
||||
use App\Http\Controllers\Api\V1\ProjectController;
|
||||
use App\Models\Client;
|
||||
use App\Models\Organization;
|
||||
@@ -159,6 +160,64 @@ class ProjectEndpointTest extends ApiEndpointTestAbstract
|
||||
$response->assertJsonCount(4, 'data');
|
||||
}
|
||||
|
||||
public function test_index_endpoint_sets_billable_rate_to_null_if_member_is_employee_and_organization_does_not_allow_employees_to_see_billable_rates(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithRole(Role::Employee);
|
||||
$organization = $data->organization;
|
||||
$organization->employees_can_see_billable_rates = false;
|
||||
$organization->save();
|
||||
$privateProjects = Project::factory()->forOrganization($data->organization)->isPrivate()->billable(111)->createMany(2);
|
||||
$publicProjects = Project::factory()->forOrganization($data->organization)->isPublic()->billable(112)->createMany(2);
|
||||
$privateProjectsWithMembership = Project::factory()->forOrganization($data->organization)->addMember($data->member)->billable(113)->isPrivate()->createMany(2);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.projects.index', [$organization->getKey()]));
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$response->assertJsonCount(4, 'data');
|
||||
$response->assertJson(fn (AssertableJson $json) => $json
|
||||
->has('data')
|
||||
->has('links')
|
||||
->has('meta')
|
||||
->where('data.0.billable_rate', null)
|
||||
->where('data.1.billable_rate', null)
|
||||
->where('data.2.billable_rate', null)
|
||||
->where('data.3.billable_rate', null)
|
||||
);
|
||||
}
|
||||
|
||||
public function test_index_endpoint_does_not_set_billable_rate_to_null_if_member_is_employee_and_organization_allows_employees_to_see_billable_rates(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithRole(Role::Employee);
|
||||
$organization = $data->organization;
|
||||
$organization->employees_can_see_billable_rates = true;
|
||||
$organization->save();
|
||||
$privateProjects = Project::factory()->forOrganization($data->organization)->isPrivate()->billable(111)->createdAt(now()->subMinutes(4))->createMany(2);
|
||||
$publicProjects = Project::factory()->forOrganization($data->organization)->isPublic()->billable(112)->createdAt(now()->subMinutes(3))->createMany(2);
|
||||
$privateProjectsWithMembership = Project::factory()->forOrganization($data->organization)->addMember($data->member)->billable(113)->isPrivate()->createdAt(now()->subMinutes(2))->createMany(2);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.projects.index', [$organization->getKey()]));
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$response->assertJsonCount(4, 'data');
|
||||
$response->assertJson(fn (AssertableJson $json) => $json
|
||||
->has('data')
|
||||
->has('links')
|
||||
->has('meta')
|
||||
->where('data.0.billable_rate', 112)
|
||||
->where('data.1.billable_rate', 112)
|
||||
->where('data.2.billable_rate', 113)
|
||||
->where('data.3.billable_rate', 113)
|
||||
);
|
||||
}
|
||||
|
||||
public function test_show_endpoint_fails_if_user_is_not_part_of_project_organization(): void
|
||||
{
|
||||
// Arrange
|
||||
|
||||
Reference in New Issue
Block a user