mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-13 02:32:15 +01:00
Added shareable reports
This commit is contained in:
committed by
Constantin Graf
parent
0ee0175f04
commit
c03aad1abd
@@ -200,7 +200,7 @@ class OrganizationEndpointTest extends ApiEndpointTestAbstract
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->withoutExceptionHandling()->putJson(route('api.v1.organizations.update', [$data->organization->getKey()]), [
|
||||
$response = $this->putJson(route('api.v1.organizations.update', [$data->organization->getKey()]), [
|
||||
'name' => $organizationFake->name,
|
||||
'billable_rate' => $organizationFake->billable_rate,
|
||||
]);
|
||||
|
||||
@@ -23,7 +23,7 @@ class ProjectMemberEndpointTest extends ApiEndpointTestAbstract
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission();
|
||||
$project = Project::factory()->forOrganization($data->organization)->create();
|
||||
$projectMembers = ProjectMember::factory()->forProject($project)->createMany(4);
|
||||
ProjectMember::factory()->forProject($project)->createMany(4);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
@@ -46,7 +46,7 @@ class ProjectMemberEndpointTest extends ApiEndpointTestAbstract
|
||||
'project-members:view',
|
||||
]);
|
||||
$project = Project::factory()->forOrganization($otherData->organization)->create();
|
||||
$projectMembers = ProjectMember::factory()->forProject($project)->createMany(4);
|
||||
ProjectMember::factory()->forProject($project)->createMany(4);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
@@ -66,7 +66,7 @@ class ProjectMemberEndpointTest extends ApiEndpointTestAbstract
|
||||
'project-members:view',
|
||||
]);
|
||||
$project = Project::factory()->forOrganization($data->organization)->create();
|
||||
$projectMembers = ProjectMember::factory()->forProject($project)->createMany(4);
|
||||
ProjectMember::factory()->forProject($project)->createMany(4);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
|
||||
113
tests/Unit/Endpoint/Api/V1/Public/PublicReportEndpointTest.php
Normal file
113
tests/Unit/Endpoint/Api/V1/Public/PublicReportEndpointTest.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Endpoint\Api\V1\Public;
|
||||
|
||||
use App\Models\Report;
|
||||
use Tests\Unit\Endpoint\Api\V1\ApiEndpointTestAbstract;
|
||||
|
||||
class PublicReportEndpointTest extends ApiEndpointTestAbstract
|
||||
{
|
||||
public function test_show_fails_with_not_found_if_secret_is_incorrect(): void
|
||||
{
|
||||
// Arrange
|
||||
Report::factory()->public()->create();
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.public.reports.show'), [
|
||||
'X-Api-Key' => 'incorrect-secret',
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_show_fails_with_not_found_if_no_secret_is_provided(): void
|
||||
{
|
||||
// Arrange
|
||||
Report::factory()->public()->create();
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.public.reports.show'));
|
||||
|
||||
// Assert
|
||||
$response->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_show_fails_with_not_found_if_report_is_not_public(): void
|
||||
{
|
||||
// Arrange
|
||||
$report = Report::factory()->private()->create();
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.public.reports.show'), [
|
||||
'X-Api-Key' => $report->share_secret,
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_show_fails_with_not_found_if_report_is_expired(): void
|
||||
{
|
||||
// Arrange
|
||||
$report = Report::factory()->public()->create([
|
||||
'public_until' => now()->subDay(),
|
||||
]);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.public.reports.show'), [
|
||||
'X-Api-Key' => $report->share_secret,
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_show_returns_detailed_information_about_the_report(): void
|
||||
{
|
||||
// Arrange
|
||||
$report = Report::factory()->public()->create([
|
||||
'public_until' => null,
|
||||
]);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.public.reports.show'), [
|
||||
'X-Api-Key' => $report->share_secret,
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertOk();
|
||||
$response->assertJsonFragment([
|
||||
'id' => $report->id,
|
||||
'name' => $report->name,
|
||||
'description' => $report->description,
|
||||
'is_public' => $report->is_public,
|
||||
'public_until' => $report->public_until?->toIso8601ZuluString(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_show_returns_detailed_information_about_the_report_with_not_expired_expiration_date(): void
|
||||
{
|
||||
// Arrange
|
||||
$report = Report::factory()->public()->create([
|
||||
'public_until' => now()->addDay(),
|
||||
]);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.public.reports.show'), [
|
||||
'X-Api-Key' => $report->share_secret,
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertOk();
|
||||
$response->assertJsonFragment([
|
||||
'id' => $report->id,
|
||||
'name' => $report->name,
|
||||
'description' => $report->description,
|
||||
'is_public' => $report->is_public,
|
||||
'public_until' => $report->public_until?->toIso8601ZuluString(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
490
tests/Unit/Endpoint/Api/V1/ReportEndpointTest.php
Normal file
490
tests/Unit/Endpoint/Api/V1/ReportEndpointTest.php
Normal file
@@ -0,0 +1,490 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Endpoint\Api\V1;
|
||||
|
||||
use App\Enums\TimeEntryAggregationType;
|
||||
use App\Http\Controllers\Api\V1\ReportController;
|
||||
use App\Models\Report;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Testing\Fluent\AssertableJson;
|
||||
use Laravel\Passport\Passport;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
|
||||
#[UsesClass(ReportController::class)]
|
||||
class ReportEndpointTest extends ApiEndpointTestAbstract
|
||||
{
|
||||
public function test_index_endpoint_fails_if_user_does_not_have_permission_to_view_reports(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission();
|
||||
Report::factory()->forOrganization($data->organization)->createMany(4);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.reports.index', ['organization' => $data->organization->getKey()]));
|
||||
|
||||
// Assert
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_index_endpoint_returns_list_of_all_reports_of_organization_ordered_by_created_at_desc_per_default(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'reports:view',
|
||||
]);
|
||||
Report::factory()->forOrganization($data->organization)->randomCreatedAt()->createMany(4);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.reports.index', [$data->organization->getKey()]));
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$response->assertJsonCount(4, 'data');
|
||||
$reports = Report::query()->orderBy('created_at', 'desc')->get();
|
||||
$response->assertJson(fn (AssertableJson $json) => $json
|
||||
->has('data')
|
||||
->has('links')
|
||||
->has('meta')
|
||||
->count('data', 4)
|
||||
->where('data.0.id', $reports->get(0)->getKey())
|
||||
->where('data.1.id', $reports->get(1)->getKey())
|
||||
->where('data.2.id', $reports->get(2)->getKey())
|
||||
->where('data.3.id', $reports->get(3)->getKey())
|
||||
);
|
||||
}
|
||||
|
||||
public function test_store_endpoint_fails_if_user_has_no_permission_to_create_report(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.reports.store', [$data->organization->getKey()]), [
|
||||
'name' => 'Test Report',
|
||||
'is_public' => false,
|
||||
'properties' => [
|
||||
'group' => TimeEntryAggregationType::Project->value,
|
||||
'sub_group' => TimeEntryAggregationType::Task->value,
|
||||
],
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_store_endpoint_creates_new_report_with_minimal_properties(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'reports:create',
|
||||
]);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.reports.store', [$data->organization->getKey()]), [
|
||||
'name' => 'Test Report',
|
||||
'is_public' => false,
|
||||
'properties' => [
|
||||
'group' => TimeEntryAggregationType::Project->value,
|
||||
'sub_group' => TimeEntryAggregationType::Task->value,
|
||||
],
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(201);
|
||||
$response->assertJson(fn (AssertableJson $json) => $json
|
||||
->has('data')
|
||||
->where('data.name', 'Test Report')
|
||||
->where('data.description', null)
|
||||
->where('data.is_public', false)
|
||||
->where('data.shareable_link', null)
|
||||
->where('data.properties.group', TimeEntryAggregationType::Project->value)
|
||||
->where('data.properties.sub_group', TimeEntryAggregationType::Task->value)
|
||||
);
|
||||
}
|
||||
|
||||
public function test_store_endpoint_creates_new_report_with_all_properties(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'reports:create',
|
||||
]);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.reports.store', [$data->organization->getKey()]), [
|
||||
'name' => 'Test Report',
|
||||
'description' => 'Test description',
|
||||
'is_public' => true,
|
||||
'public_until' => Carbon::now()->addDays(30)->toIso8601ZuluString(),
|
||||
'properties' => [
|
||||
'start' => Carbon::now()->subDays(30)->toIso8601ZuluString(),
|
||||
'end' => Carbon::now()->toIso8601ZuluString(),
|
||||
'active' => true,
|
||||
'member_ids' => [],
|
||||
'billable' => true,
|
||||
'client_ids' => [],
|
||||
'project_ids' => [],
|
||||
'tag_ids' => [],
|
||||
'task_ids' => [],
|
||||
'group' => TimeEntryAggregationType::Project->value,
|
||||
'sub_group' => TimeEntryAggregationType::Task->value,
|
||||
],
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(201);
|
||||
/** @var Report $report */
|
||||
$report = Report::query()->findOrFail($response->json('data.id'));
|
||||
$response->assertJson(fn (AssertableJson $json) => $json
|
||||
->has('data')
|
||||
->where('data.name', 'Test Report')
|
||||
->where('data.description', 'Test description')
|
||||
->where('data.is_public', true)
|
||||
->where('data.shareable_link', $report->getShareableLink())
|
||||
->where('data.properties.group', TimeEntryAggregationType::Project->value)
|
||||
->where('data.properties.sub_group', TimeEntryAggregationType::Task->value)
|
||||
);
|
||||
}
|
||||
|
||||
public function test_update_endpoint_fails_if_user_has_no_permission_to_update_report(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission();
|
||||
$report = Report::factory()->forOrganization($data->organization)->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->putJson(route('api.v1.reports.update', [$data->organization->getKey(), $report->getKey()]), [
|
||||
'name' => 'Updated Report',
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_update_endpoint_fails_if_report_does_not_exist(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'reports:update',
|
||||
]);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->putJson(route('api.v1.reports.update', [$data->organization->getKey(), 1]), [
|
||||
'name' => 'Updated Report',
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_update_endpoint_fails_if_report_does_not_belong_to_organization(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'reports:update',
|
||||
]);
|
||||
$report = Report::factory()->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->putJson(route('api.v1.reports.update', [$data->organization->getKey(), $report->getKey()]), [
|
||||
'name' => 'Updated Report',
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_update_endpoint_can_update_only_the_name_of_the_report(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'reports:update',
|
||||
]);
|
||||
$report = Report::factory()->forOrganization($data->organization)->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->putJson(route('api.v1.reports.update', [$data->organization->getKey(), $report->getKey()]), [
|
||||
'name' => 'Updated Report',
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$report->refresh();
|
||||
$this->assertSame('Updated Report', $report->name);
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(fn (AssertableJson $json) => $json
|
||||
->has('data')
|
||||
->where('data.name', 'Updated Report')
|
||||
);
|
||||
}
|
||||
|
||||
public function test_update_endpoint_can_update_only_the_description_of_the_report(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'reports:update',
|
||||
]);
|
||||
$report = Report::factory()->forOrganization($data->organization)->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->putJson(route('api.v1.reports.update', [$data->organization->getKey(), $report->getKey()]), [
|
||||
'description' => 'Updated description',
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$report->refresh();
|
||||
$this->assertSame('Updated description', $report->description);
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(fn (AssertableJson $json) => $json
|
||||
->has('data')
|
||||
->where('data.description', 'Updated description')
|
||||
);
|
||||
}
|
||||
|
||||
public function test_update_endpoint_can_set_a_report_to_public_which_generates_a_new_secret(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'reports:update',
|
||||
]);
|
||||
$report = Report::factory()->private()->forOrganization($data->organization)->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->putJson(route('api.v1.reports.update', [$data->organization->getKey(), $report->getKey()]), [
|
||||
'is_public' => true,
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$report->refresh();
|
||||
$this->assertTrue($report->is_public);
|
||||
$this->assertNotNull($report->share_secret);
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(fn (AssertableJson $json) => $json
|
||||
->has('data')
|
||||
->where('data.is_public', true)
|
||||
->where('data.shareable_link', $report->getShareableLink())
|
||||
);
|
||||
}
|
||||
|
||||
public function test_update_endpoint_can_set_a_report_to_private_which_resets_the_secret(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'reports:update',
|
||||
]);
|
||||
$report = Report::factory()->public()->forOrganization($data->organization)->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->putJson(route('api.v1.reports.update', [$data->organization->getKey(), $report->getKey()]), [
|
||||
'is_public' => false,
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$report->refresh();
|
||||
$this->assertFalse($report->is_public);
|
||||
$this->assertNull($report->share_secret);
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(fn (AssertableJson $json) => $json
|
||||
->has('data')
|
||||
->where('data.is_public', false)
|
||||
->where('data.shareable_link', null)
|
||||
);
|
||||
}
|
||||
|
||||
public function test_update_endpoint_does_not_change_the_secret_of_a_public_report_if_it_is_set_to_public_again(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'reports:update',
|
||||
]);
|
||||
$report = Report::factory()->public()->forOrganization($data->organization)->create();
|
||||
$secret = $report->share_secret;
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->putJson(route('api.v1.reports.update', [$data->organization->getKey(), $report->getKey()]), [
|
||||
'is_public' => true,
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$report->refresh();
|
||||
$this->assertTrue($report->is_public);
|
||||
$this->assertSame($secret, $report->share_secret);
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(fn (AssertableJson $json) => $json
|
||||
->has('data')
|
||||
->where('data.is_public', true)
|
||||
->where('data.shareable_link', $report->getShareableLink())
|
||||
);
|
||||
}
|
||||
|
||||
public function test_update_endpoint_can_update_the_report_all_properties_set(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'reports:update',
|
||||
]);
|
||||
$report = Report::factory()->forOrganization($data->organization)->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->putJson(route('api.v1.reports.update', [$data->organization->getKey(), $report->getKey()]), [
|
||||
'name' => 'Updated Report',
|
||||
'description' => 'Updated description',
|
||||
'is_public' => true,
|
||||
'public_until' => Carbon::now()->addDays(30)->toIso8601ZuluString(),
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(fn (AssertableJson $json) => $json
|
||||
->has('data')
|
||||
->where('data.name', 'Updated Report')
|
||||
->where('data.description', 'Updated description')
|
||||
->where('data.is_public', true)
|
||||
->where('data.properties.group', TimeEntryAggregationType::Project->value)
|
||||
->where('data.properties.sub_group', TimeEntryAggregationType::Task->value)
|
||||
);
|
||||
}
|
||||
|
||||
public function test_show_endpoint_fails_if_user_has_no_permission_to_view_report(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission();
|
||||
$report = Report::factory()->forOrganization($data->organization)->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.reports.show', [$data->organization->getKey(), $report->getKey()]));
|
||||
|
||||
// Assert
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_show_endpoint_fails_if_report_does_not_exist(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'reports:view',
|
||||
]);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.reports.show', [$data->organization->getKey(), 1]));
|
||||
|
||||
// Assert
|
||||
$response->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_show_endpoint_fails_if_report_does_not_belong_to_organization(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'reports:view',
|
||||
]);
|
||||
$report = Report::factory()->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.reports.show', [$data->organization->getKey(), $report->getKey()]));
|
||||
|
||||
// Assert
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_show_endpoint_returns_detailed_report(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'reports:view',
|
||||
]);
|
||||
$report = Report::factory()->forOrganization($data->organization)->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.reports.show', [$data->organization->getKey(), $report->getKey()]));
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(fn (AssertableJson $json) => $json
|
||||
->has('data')
|
||||
->where('data.id', $report->getKey())
|
||||
);
|
||||
}
|
||||
|
||||
public function test_destroy_endpoint_fails_if_user_has_no_permission_to_delete_report(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission();
|
||||
$report = Report::factory()->forOrganization($data->organization)->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->deleteJson(route('api.v1.reports.destroy', [$data->organization->getKey(), $report->getKey()]));
|
||||
|
||||
// Assert
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_destroy_endpoint_fails_if_report_belongs_to_another_organization(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'reports:delete',
|
||||
]);
|
||||
$report = Report::factory()->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->deleteJson(route('api.v1.reports.destroy', [$data->organization->getKey(), $report->getKey()]));
|
||||
|
||||
// Assert
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_destroy_endpoint_fails_if_report_does_not_exist(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'reports:delete',
|
||||
]);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->deleteJson(route('api.v1.reports.destroy', [$data->organization->getKey(), 1]));
|
||||
|
||||
// Assert
|
||||
$response->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_destroy_endpoint_deletes_a_report(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'reports:delete',
|
||||
]);
|
||||
$report = Report::factory()->forOrganization($data->organization)->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->deleteJson(route('api.v1.reports.destroy', [$data->organization->getKey(), $report->getKey()]));
|
||||
|
||||
// Assert
|
||||
$response->assertNoContent();
|
||||
$this->assertDatabaseMissing(Report::class, [
|
||||
'id' => $report->getKey(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -930,6 +930,25 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_aggregate_endpoint_fails_if_request_has_sub_group_but_no_group(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'time-entries:view:all',
|
||||
]);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.time-entries.aggregate', [
|
||||
$data->organization->getKey(),
|
||||
'sub_group' => TimeEntryAggregationType::Task->value,
|
||||
]));
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(422);
|
||||
$response->assertJsonValidationErrorFor('group');
|
||||
}
|
||||
|
||||
public function test_aggregate_endpoint_works_for_user_with_only_access_to_own_time_entries(): void
|
||||
{
|
||||
// Arrange
|
||||
|
||||
Reference in New Issue
Block a user