mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-10-11 15:23:17 +01:00
Set content-disposition 'attachment' for both local and S3 downloads. Added a bunch of tests. Fixes #1148.
This commit is contained in:
committed by
Gregor Vostrak
parent
ed3ba0135b
commit
453d5ed066
@@ -947,6 +947,35 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
$this->assertResponseCode($response, 200);
|
||||
}
|
||||
|
||||
public function test_index_export_endpoint_requests_the_download_url_as_an_attachment(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'time-entries:view:all',
|
||||
]);
|
||||
TimeEntry::factory()->forOrganization($data->organization)->forMember($data->member)->startWithDuration(Carbon::now(), 100)->create();
|
||||
Passport::actingAs($data->user);
|
||||
$capturedOptions = $this->captureTemporaryUrlOptions();
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.time-entries.index-export', [
|
||||
$data->organization->getKey(),
|
||||
'format' => ExportFormat::CSV,
|
||||
'start' => Carbon::now()->startOfYear()->toIso8601ZuluString(),
|
||||
'end' => Carbon::now()->endOfYear()->toIso8601ZuluString(),
|
||||
]));
|
||||
|
||||
// Assert
|
||||
$this->assertResponseCode($response, 200);
|
||||
$options = $capturedOptions();
|
||||
$this->assertIsArray($options);
|
||||
$this->assertMatchesRegularExpression(
|
||||
'/^attachment; filename="time-entries-export-.+\.csv"$/',
|
||||
$options['ResponseContentDisposition'] ?? ''
|
||||
);
|
||||
$this->assertStringStartsWith('https://storage.fake/exports/', $response->json('download_url'));
|
||||
}
|
||||
|
||||
public function test_index_export_endpoint_can_create_a_detailed_time_entry_report_in_format_ods(): void
|
||||
{
|
||||
// Arrange
|
||||
@@ -1321,6 +1350,38 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
$this->assertResponseCode($response, 200);
|
||||
}
|
||||
|
||||
public function test_aggregate_export_endpoint_requests_the_download_url_as_an_attachment(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'time-entries:view:all',
|
||||
]);
|
||||
TimeEntry::factory()->forOrganization($data->organization)->forMember($data->member)->startWithDuration(Carbon::now(), 100)->create();
|
||||
Passport::actingAs($data->user);
|
||||
$capturedOptions = $this->captureTemporaryUrlOptions();
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.time-entries.aggregate-export', [
|
||||
$data->organization->getKey(),
|
||||
'format' => ExportFormat::CSV,
|
||||
'group' => TimeEntryAggregationType::Client,
|
||||
'sub_group' => TimeEntryAggregationType::Project,
|
||||
'history_group' => TimeEntryAggregationTypeInterval::Month,
|
||||
'start' => Carbon::now()->startOfYear()->toIso8601ZuluString(),
|
||||
'end' => Carbon::now()->endOfYear()->toIso8601ZuluString(),
|
||||
]));
|
||||
|
||||
// Assert
|
||||
$this->assertResponseCode($response, 200);
|
||||
$options = $capturedOptions();
|
||||
$this->assertIsArray($options);
|
||||
$this->assertMatchesRegularExpression(
|
||||
'/^attachment; filename="time-entries-report-.+\.csv"$/',
|
||||
$options['ResponseContentDisposition'] ?? ''
|
||||
);
|
||||
$this->assertStringStartsWith('https://storage.fake/exports/', $response->json('download_url'));
|
||||
}
|
||||
|
||||
public function test_aggregate_export_endpoints_can_create_a_csv_report_as_employee_role_with_show_billable_rate(): void
|
||||
{
|
||||
// Arrange
|
||||
|
||||
Reference in New Issue
Block a user