mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-10-14 16:53:17 +01:00
Add tests for billable rate restriction in importers and API edge cases
This commit is contained in:
committed by
Gregor Vostrak
parent
902270a189
commit
c69edc81be
@@ -1186,4 +1186,25 @@ class MemberEndpointTest extends ApiEndpointTestAbstract
|
||||
$this->assertSame(10000, $timeEntry->refresh()->billable_rate);
|
||||
}
|
||||
|
||||
public function test_member_update_does_not_remove_billable_rate_if_organization_can_not_use_billable_rates(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'members:update',
|
||||
]);
|
||||
$member = Member::factory()->forOrganization($data->organization)->forUser(User::factory()->create())->role(Role::Employee)->create([
|
||||
'billable_rate' => 10000,
|
||||
]);
|
||||
$this->actAsOrganizationWithoutBillableRates();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->putJson(route('api.v1.members.update', [$data->organization->getKey(), $member->getKey()]), [
|
||||
'billable_rate' => null,
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertOk();
|
||||
$this->assertSame(10000, $member->refresh()->billable_rate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6253,6 +6253,73 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
$this->assertSame('Mass update', $nonBillableTimeEntry->description);
|
||||
}
|
||||
|
||||
public function test_time_entry_update_multiple_can_remove_billable_flag_if_organization_can_not_use_billable_rates(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'time-entries:update:own',
|
||||
]);
|
||||
$timeEntry = TimeEntry::factory()->forOrganization($data->organization)->forMember($data->member)->billable()->create();
|
||||
$this->actAsOrganizationWithoutBillableRates();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->patchJson(route('api.v1.time-entries.update-multiple', [$data->organization->getKey()]), [
|
||||
'ids' => [$timeEntry->getKey()],
|
||||
'changes' => [
|
||||
'billable' => false,
|
||||
],
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertOk();
|
||||
$response->assertExactJson([
|
||||
'success' => [$timeEntry->getKey()],
|
||||
'error' => [],
|
||||
]);
|
||||
$timeEntry->refresh();
|
||||
$this->assertFalse($timeEntry->billable);
|
||||
$this->assertNull($timeEntry->billable_rate);
|
||||
}
|
||||
|
||||
public function test_time_entry_update_with_project_change_does_not_make_time_entry_billable_if_organization_can_not_use_billable_rates(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'time-entries:update:own',
|
||||
]);
|
||||
$project = Project::factory()->forOrganization($data->organization)->isPublic()->billable(10000)->create();
|
||||
$otherProject = Project::factory()->forOrganization($data->organization)->isPublic()->billable(20000)->create();
|
||||
$billableTimeEntry = TimeEntry::factory()->forOrganization($data->organization)->forMember($data->member)->forProject($project)->billable()
|
||||
->startWithDuration(Carbon::now()->subHours(5), 3600)->create();
|
||||
$nonBillableTimeEntry = TimeEntry::factory()->forOrganization($data->organization)->forMember($data->member)->notBillable()
|
||||
->startWithDuration(Carbon::now()->subHours(3), 3600)->create();
|
||||
$this->actAsOrganizationWithoutBillableRates();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$responseBillable = $this->putJson(route('api.v1.time-entries.update', [$data->organization->getKey(), $billableTimeEntry->getKey()]), [
|
||||
'project_id' => $otherProject->getKey(),
|
||||
'billable' => true,
|
||||
]);
|
||||
$responseNonBillable = $this->putJson(route('api.v1.time-entries.update', [$data->organization->getKey(), $nonBillableTimeEntry->getKey()]), [
|
||||
'project_id' => $otherProject->getKey(),
|
||||
'billable' => true,
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$responseBillable->assertOk();
|
||||
$responseNonBillable->assertOk();
|
||||
$billableTimeEntry->refresh();
|
||||
$this->assertSame($otherProject->getKey(), $billableTimeEntry->project_id);
|
||||
$this->assertTrue($billableTimeEntry->billable);
|
||||
$this->assertSame(20000, $billableTimeEntry->billable_rate);
|
||||
$nonBillableTimeEntry->refresh();
|
||||
$this->assertSame($otherProject->getKey(), $nonBillableTimeEntry->project_id);
|
||||
$this->assertFalse($nonBillableTimeEntry->billable);
|
||||
$this->assertNull($nonBillableTimeEntry->billable_rate);
|
||||
}
|
||||
|
||||
public function test_time_entry_store_does_not_check_billable_rates_for_non_billable_time_entry(): void
|
||||
{
|
||||
// Arrange
|
||||
|
||||
Reference in New Issue
Block a user