Merge pull request #183 from jonnybarnes/improving_media_endpoint_querying_aaronpk

Return null for media endpoint when no media exists
This commit is contained in:
Jonny Barnes 2020-06-28 17:27:52 +01:00 committed by GitHub
commit da0517382c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View file

@ -58,7 +58,7 @@ class MicropubMediaController extends Controller
try {
$media = Media::latest()->whereDate('created_at', '>=', Carbon::now()->subMinutes(30))->firstOrFail();
} catch (ModelNotFoundException $exception) {
return response()->json([], 404);
return response()->json(['url' => null]);
}
return response()->json(['url' => $media->url]);

View file

@ -28,7 +28,8 @@ class MicropubMediaTest extends TestCase
'/api/media?q=last',
['HTTP_Authorization' => 'Bearer ' . $this->getToken()]
);
$response->assertStatus(404);
$response->assertStatus(200);
$response->assertJson(['url' => null]);
}
/** @test */