Add ability to update billable rate of existing time entries

This commit is contained in:
Constantin Graf
2024-06-14 16:46:39 +02:00
committed by Gregor Vostrak
parent 7c26cee1ea
commit 2184b3c835
22 changed files with 1001 additions and 25 deletions

View File

@@ -6,7 +6,9 @@ namespace Tests\Unit\Endpoint\Api\V1;
use App\Http\Controllers\Api\V1\OrganizationController;
use App\Models\Organization;
use App\Service\BillableRateService;
use Laravel\Passport\Passport;
use Mockery\MockInterface;
use PHPUnit\Framework\Attributes\UsesClass;
#[UsesClass(OrganizationController::class)]
@@ -45,8 +47,8 @@ class OrganizationEndpointTest extends ApiEndpointTestAbstract
public function test_update_endpoint_fails_if_user_has_no_permission_to_update_organizations(): void
{
// Arrange
$data = $this->createUserWithPermission([
]);
$data = $this->createUserWithPermission();
$this->assertBillableRateServiceIsUnused();
$organizationFake = Organization::factory()->make();
Passport::actingAs($data->user);
@@ -65,6 +67,7 @@ class OrganizationEndpointTest extends ApiEndpointTestAbstract
$data = $this->createUserWithPermission([
'organizations:update',
]);
$this->assertBillableRateServiceIsUnused();
$organizationFake = Organization::factory()->make();
Passport::actingAs($data->user);
@@ -88,6 +91,7 @@ class OrganizationEndpointTest extends ApiEndpointTestAbstract
$data = $this->createUserWithPermission([
'organizations:update',
]);
$this->assertBillableRateServiceIsUnused();
$organizationFake = Organization::factory()->make();
Passport::actingAs($data->user);
@@ -104,4 +108,34 @@ class OrganizationEndpointTest extends ApiEndpointTestAbstract
'billable_rate' => $organizationFake->billable_rate,
]);
}
public function test_update_endpoint_can_update_billable_rate_of_organization_and_update_time_entries(): void
{
// Arrange
$data = $this->createUserWithPermission([
'organizations:update',
]);
$billableRate = 111;
$organizationFake = Organization::factory()->billableRate($billableRate)->make();
$this->mock(BillableRateService::class, function (MockInterface $mock) use ($data, $billableRate) {
$mock->shouldReceive('updateTimeEntriesBillableRateForOrganization')
->once()
->withArgs(fn (Organization $organization) => $organization->is($data->organization) && $organization->billable_rate === $billableRate);
});
Passport::actingAs($data->user);
// Act
$response = $this->withoutExceptionHandling()->putJson(route('api.v1.organizations.update', [$data->organization->getKey()]), [
'name' => $organizationFake->name,
'billable_rate' => $organizationFake->billable_rate,
'billable_rate_update_time_entries' => 'true',
]);
// Assert
$response->assertStatus(200);
$this->assertDatabaseHas(Organization::class, [
'name' => $organizationFake->name,
'billable_rate' => $organizationFake->billable_rate,
]);
}
}