Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Http/Controllers/IcsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace TransformStudios\Events\Http\Controllers;

use Carbon\CarbonImmutable;
use Carbon\Exceptions\InvalidFormatException;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
Expand All @@ -25,8 +26,13 @@ class IcsController extends Controller

public function __invoke(Request $request)
{
try {
$date = $request->filled('date') ? CarbonImmutable::parse($request->input('date')) : null;
} catch (InvalidFormatException $e) {
abort(404, 'Event not found');
}

$handle = $request->string('collection', 'events');
$date = $request->has('date') ? CarbonImmutable::parse($request->get('date')) : null;
$eventId = $request->string('event');
$entry = null;

Expand Down
11 changes: 9 additions & 2 deletions tests/Http/Contollers/IcsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
$this->assertStringContainsString('DESCRIPTION:The description', $response->streamedContent());
});

test('throws404 error when event does not occur on date', function () {
test('throws 404 error when event does not occur on date', function () {
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));

$this->get(route('statamic.events.ics.show', [
Expand All @@ -181,11 +181,18 @@
]))->assertStatus(404);
});

test('throws404 error when event does not exist', function () {
test('throws 404 error when event does not exist', function () {
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));

$this->get(route('statamic.events.ics.show', [
'date' => now()->addDay()->toDateString(),
'event' => 'does-not-exist',
]))->assertStatus(404);
});

test('throws 404 error when date is invalid', function () {
$this->get(route('statamic.events.ics.show', [
'date' => 'not-a-date',
'event' => 'the-id',
]))->assertStatus(404);
});
Loading