File size: 2,095 Bytes
6773345
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php

namespace Tests\Feature;

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\URL;
use Tests\TestCase;

class FileStreamingTest extends TestCase
{
    protected function setUp(): void
    {
        parent::setUp();

        try {
            DB::connection()->getPdo();
        } catch (\Throwable) {
            $this->markTestSkipped('Database driver is not available in this environment.');
        }

        if (Schema::hasTable('stored_files')) {
            $this->markTestSkipped('stored_files already exists; skipping isolated route fixture setup.');
        }

        Schema::create('stored_files', function (Blueprint $table): void {
            $table->string('id')->primary();
            $table->string('storage_key');
            $table->string('original_filename');
            $table->string('mime_type')->nullable();
            $table->unsignedBigInteger('file_size_bytes')->default(1);
            $table->timestamp('deleted_at')->nullable();
            $table->timestamps();
        });
    }

    public function test_signed_stream_route_returns_inline_file_response(): void
    {
        config(['app.key' => 'test-signing-key']);
        Storage::disk('local')->put('testing/file-123.txt', 'hello');

        \DB::table('stored_files')->insert([
            'id' => 'file-123',
            'storage_key' => 'testing/file-123.txt',
            'original_filename' => 'hello.txt',
            'mime_type' => 'text/plain',
            'file_size_bytes' => 5,
            'created_at' => now(),
            'updated_at' => now(),
        ]);

        $url = URL::temporarySignedRoute('applicant.files.stream', now()->addMinutes(10), [
            'fileId' => 'file-123',
        ], false);

        $response = $this->get($url);

        $response->assertOk();
        $this->assertStringContainsString('inline', $response->headers->get('content-disposition'));
        $this->assertSame('hello', $response->getContent());
    }
}