From bcf708ecc343ce6e4aadbe50098a5a117127d5f8 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Wed, 8 Mar 2023 02:04:13 +0100 Subject: [PATCH] Add fallback notice --- src/MediaData.php | 3 +++ tests/Feature/IndexTest.php | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/MediaData.php b/src/MediaData.php index f0d667c..264b17e 100644 --- a/src/MediaData.php +++ b/src/MediaData.php @@ -32,6 +32,8 @@ class MediaData extends Data public array $conversions = []; + public bool $fallback = false; + public static function fromMedia(Media $media): self { $conversions = collect($media->getMediaConversionNames())->flip()->map(fn ($integer, $conversion) => [ @@ -60,6 +62,7 @@ class MediaData extends Data 'name' => pathinfo($default[0], PATHINFO_FILENAME), 'file_name' => pathinfo($default[0], PATHINFO_BASENAME), 'properties' => [], + 'fallback' => true, ]); } } diff --git a/tests/Feature/IndexTest.php b/tests/Feature/IndexTest.php index d46b4ec..4d2977d 100644 --- a/tests/Feature/IndexTest.php +++ b/tests/Feature/IndexTest.php @@ -28,6 +28,7 @@ test('it gets media for single', function () { $response->assertStatus(200); $response->assertJsonPath('id', $media->id); $response->assertJsonPath('properties.test', 'old'); + $response->assertJsonPath('fallback', false); }); test('it checks for authorization', function () { @@ -71,4 +72,5 @@ test('test it gets default single media', function () { $response->assertJsonPath('original_url', Storage::disk('public')->url('default.jpg')); $response->assertJsonPath('name', 'default'); $response->assertJsonPath('file_name', 'default.jpg'); + $response->assertJsonPath('fallback', true); });