mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-10-12 15:53:19 +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
@@ -90,4 +90,35 @@ class ExportEndpointTest extends ApiEndpointTestAbstract
|
||||
$response->assertJsonPath('success', true);
|
||||
$this->assertStringContainsString($filepath, $response->json('download_url'));
|
||||
}
|
||||
|
||||
public function test_export_requests_the_download_url_as_an_attachment(): void
|
||||
{
|
||||
// Arrange
|
||||
$user = $this->createUserWithPermission([
|
||||
'export',
|
||||
]);
|
||||
$filepath = 'exports/export_test.zip';
|
||||
$this->mock(ExportService::class, function (MockInterface $mock) use (&$user, $filepath): void {
|
||||
$mock->shouldReceive('export')
|
||||
->withArgs(function (Organization $organization) use (&$user): bool {
|
||||
return $organization->is($user->organization);
|
||||
})
|
||||
->andReturn($filepath)
|
||||
->once();
|
||||
});
|
||||
Passport::actingAs($user->user);
|
||||
$capturedOptions = $this->captureTemporaryUrlOptions();
|
||||
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.export.export', [
|
||||
'organization' => $user->organization->getKey(),
|
||||
]));
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$options = $capturedOptions();
|
||||
$this->assertIsArray($options);
|
||||
$this->assertSame('attachment; filename="export_test.zip"', $options['ResponseContentDisposition'] ?? null);
|
||||
$this->assertSame('https://storage.fake/'.$filepath, $response->json('download_url'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user