optimizations
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Artwork;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
@@ -107,13 +108,14 @@ it('blocks duplicate hash when policy is block', function () {
|
||||
$main = UploadedFile::fake()->image('dupe.jpg', 400, 400);
|
||||
$hash = hash_file('sha256', $main->getPathname());
|
||||
|
||||
$publishedUploadId = createUploadRowForQuota($owner->id, [
|
||||
'status' => 'published',
|
||||
Artwork::factory()->create([
|
||||
'user_id' => $owner->id,
|
||||
'hash' => $hash,
|
||||
'artwork_status' => 'published',
|
||||
'published_at' => now()->subMinute(),
|
||||
'is_public' => true,
|
||||
]);
|
||||
|
||||
attachMainUploadFileForQuota($publishedUploadId, (int) $main->getSize(), $hash);
|
||||
|
||||
$response = $this->actingAs($uploader)->postJson('/api/uploads/preload', [
|
||||
'main' => $main,
|
||||
]);
|
||||
@@ -136,13 +138,14 @@ it('allows duplicate hash and returns warning when policy is warn', function ()
|
||||
$main = UploadedFile::fake()->image('dupe-warn.jpg', 400, 400);
|
||||
$hash = hash_file('sha256', $main->getPathname());
|
||||
|
||||
$publishedUploadId = createUploadRowForQuota($owner->id, [
|
||||
'status' => 'published',
|
||||
Artwork::factory()->create([
|
||||
'user_id' => $owner->id,
|
||||
'hash' => $hash,
|
||||
'artwork_status' => 'published',
|
||||
'published_at' => now()->subMinute(),
|
||||
'is_public' => true,
|
||||
]);
|
||||
|
||||
attachMainUploadFileForQuota($publishedUploadId, (int) $main->getSize(), $hash);
|
||||
|
||||
$response = $this->actingAs($uploader)->postJson('/api/uploads/preload', [
|
||||
'main' => $main,
|
||||
]);
|
||||
@@ -175,6 +178,37 @@ it('does not count published uploads as drafts', function () {
|
||||
]);
|
||||
});
|
||||
|
||||
it('ignores duplicate hashes that exist only in temporary upload tables', function () {
|
||||
Storage::fake('local');
|
||||
config([
|
||||
'uploads.draft_quota.max_drafts_per_user' => 20,
|
||||
'uploads.draft_quota.duplicate_hash_policy' => 'block',
|
||||
]);
|
||||
|
||||
$owner = User::factory()->create();
|
||||
$uploader = User::factory()->create();
|
||||
|
||||
$main = UploadedFile::fake()->image('temp-only-dupe.jpg', 400, 400);
|
||||
$hash = hash_file('sha256', $main->getPathname());
|
||||
|
||||
$publishedUploadId = createUploadRowForQuota($owner->id, [
|
||||
'status' => 'published',
|
||||
'published_at' => now()->subMinute(),
|
||||
]);
|
||||
|
||||
attachMainUploadFileForQuota($publishedUploadId, (int) $main->getSize(), $hash);
|
||||
|
||||
$response = $this->actingAs($uploader)->postJson('/api/uploads/preload', [
|
||||
'main' => $main,
|
||||
]);
|
||||
|
||||
$response->assertOk()->assertJsonStructure([
|
||||
'upload_id',
|
||||
'status',
|
||||
'expires_at',
|
||||
]);
|
||||
});
|
||||
|
||||
it('returns stable machine codes for quota errors', function () {
|
||||
Storage::fake('local');
|
||||
config(['uploads.draft_quota.max_drafts_per_user' => 1]);
|
||||
|
||||
Reference in New Issue
Block a user