Skip to content

Commit d32aa64

Browse files
Extend tests, remove unused code (#55)
* Add more tests, remove unused code and unnessary comments * Add test for API endpoint * Add tests for update methods, cache commands, missing parts of Livewire components * Add tests for bookings with custom fields * Remove HasWebsite trait
1 parent 3b23499 commit d32aa64

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+874
-239
lines changed

app/Events/BookingCompleted.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
namespace App\Events;
44

55
use App\Models\Booking;
6-
use Illuminate\Broadcasting\Channel;
76
use Illuminate\Broadcasting\InteractsWithSockets;
8-
use Illuminate\Broadcasting\PrivateChannel;
97
use Illuminate\Foundation\Events\Dispatchable;
108
use Illuminate\Queue\SerializesModels;
119

@@ -23,14 +21,4 @@ class BookingCompleted
2321
public function __construct(public Booking $booking)
2422
{
2523
}
26-
27-
/**
28-
* Get the channels the event should broadcast on.
29-
*
30-
* @return Channel|array
31-
*/
32-
public function broadcastOn()
33-
{
34-
return new PrivateChannel('channel-name');
35-
}
3624
}

app/Http/Controllers/AccountController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public function update(UserRequest $request): RedirectResponse
4141

4242
if ($user->fillAndSave($request->validated())) {
4343
Session::flash('success', __('Saved successfully.'));
44-
return redirect(route('account.edit'));
4544
}
4645

4746
return back();

app/Http/Controllers/BookingOptionController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,9 @@ public function update(Event $event, BookingOption $bookingOption, BookingOption
6060

6161
if ($bookingOption->fillAndSave($request->validated())) {
6262
Session::flash('success', __('Saved successfully.'));
63-
// Slug may have changed, so we need to generate the URL here!
64-
return redirect(route('booking-options.edit', [$event, $bookingOption]));
6563
}
6664

67-
return back();
65+
// Slug may have changed, so we need to generate the URL here!
66+
return redirect(route('booking-options.edit', [$event, $bookingOption]));
6867
}
6968
}

app/Http/Controllers/DocumentController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ public function update(DocumentRequest $request, Document $document): RedirectRe
103103

104104
if ($document->fillAndSave($request->validated())) {
105105
Session::flash('success', __('Saved successfully.'));
106-
return redirect(route('documents.edit', $document));
107106
}
108107

109108
return back();
@@ -115,9 +114,8 @@ public function destroy(Document $document): RedirectResponse
115114

116115
if ($document->delete()) {
117116
Session::flash('success', __('Deleted successfully.'));
118-
return redirect($document->reference->getRoute());
119117
}
120118

121-
return back();
119+
return redirect($document->reference->getRoute());
122120
}
123121
}

app/Http/Controllers/DocumentReviewController.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ public function store(DocumentReviewRequest $request, Document $document): Redir
3535
$review->user()->associate(Auth::user());
3636
if ($review->fillAndSave($validated) && $document->save()) {
3737
Session::flash('success', __('Saved comment successfully.'));
38-
return redirect($document->getRouteForComments());
3938
}
4039

41-
return back();
40+
return redirect($document->getRouteForComments());
4241
}
4342

4443
public function update(DocumentReviewRequest $request, Document $document, DocumentReview $review): RedirectResponse
@@ -47,9 +46,8 @@ public function update(DocumentReviewRequest $request, Document $document, Docum
4746

4847
if ($review->fillAndSave($request->validated())) {
4948
Session::flash('success', __('Saved comment successfully.'));
50-
return redirect($document->getRouteForComments());
5149
}
5250

53-
return back();
51+
return redirect($document->getRouteForComments());
5452
}
5553
}

app/Http/Controllers/EventController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,10 @@ public function update(Event $event, EventRequest $request): RedirectResponse
114114

115115
if ($event->fillAndSave($request->validated())) {
116116
Session::flash('success', __('Saved successfully.'));
117-
// Slug may have changed, so we need to generate the URL here!
118-
return redirect(route('events.edit', $event));
119117
}
120118

121-
return back();
119+
// Slug may have changed, so we need to generate the URL here!
120+
return redirect(route('events.edit', $event));
122121
}
123122

124123
private function formValues(array $values = []): array

app/Http/Controllers/EventSeriesController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,10 @@ public function update(EventSeries $eventSeries, EventSeriesRequest $request): R
111111

112112
if ($eventSeries->fillAndSave($request->validated())) {
113113
Session::flash('success', __('Saved successfully.'));
114-
// Slug may have changed, so we need to generate the URL here!
115-
return redirect(route('event-series.edit', $eventSeries));
116114
}
117115

118-
return back();
116+
// Slug may have changed, so we need to generate the URL here!
117+
return redirect(route('event-series.edit', $eventSeries));
119118
}
120119

121120
private function formValues(array $values = []): array

app/Models/Document.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function getRoute(): string
117117

118118
public function getRouteForComments(): string
119119
{
120-
return $this->getRoute().'#comments';
120+
return $this->getRoute() . '#comments';
121121
}
122122

123123
public function scopeSearchTitleAndDescription(Builder $query, string ...$searchTerms): Builder

app/Models/Event.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use App\Models\Traits\HasNameAndDescription;
1111
use App\Models\Traits\HasResponsibleUsers;
1212
use App\Models\Traits\HasSlugForRouting;
13-
use App\Models\Traits\HasWebsite;
1413
use App\Options\Ability;
1514
use App\Options\EventType;
1615
use App\Options\FilterValue;
@@ -36,6 +35,7 @@
3635
* @property Visibility $visibility
3736
* @property ?Carbon $started_at
3837
* @property ?Carbon $finished_at
38+
* @property ?string $website_url
3939
*
4040
* @property-read Collection|BookingOption[] $bookingOptions {@see Event::bookingOptions()}
4141
* @property-read Collection|Booking[] $bookings {@see Event::bookings()}
@@ -55,7 +55,6 @@ class Event extends Model
5555
use HasNameAndDescription;
5656
use HasResponsibleUsers;
5757
use HasSlugForRouting;
58-
use HasWebsite;
5958

6059
/**
6160
* The attributes that are mass assignable.

app/Models/FormField.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Options\FormElementType;
66
use Illuminate\Database\Eloquent\Casts\Attribute;
77
use Illuminate\Database\Eloquent\Collection;
8+
use Illuminate\Database\Eloquent\Factories\HasFactory;
89
use Illuminate\Database\Eloquent\Model;
910
use Illuminate\Database\Eloquent\Relations\BelongsTo;
1011
use Illuminate\Database\Eloquent\Relations\HasMany;
@@ -29,6 +30,8 @@
2930
*/
3031
class FormField extends Model
3132
{
33+
use HasFactory;
34+
3235
protected $casts = [
3336
'sort' => 'integer',
3437
'type' => FormElementType::class,

app/Models/Location.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use App\Models\QueryBuilder\SortOptions;
77
use App\Models\Traits\FiltersByRelationExistence;
88
use App\Models\Traits\HasAddress;
9-
use App\Models\Traits\HasWebsite;
109
use Illuminate\Database\Eloquent\Builder;
1110
use Illuminate\Database\Eloquent\Casts\Attribute;
1211
use Illuminate\Database\Eloquent\Collection;
@@ -18,6 +17,7 @@
1817
/**
1918
* @property-read int $id
2019
* @property string $name
20+
* @property ?string $website_url
2121
*
2222
* @property-read string[] $fullAddressBlock {@see Location::fullAddressBlock()}
2323
* @property-read string $nameOrAddress {@see Location::nameOrAddress()}
@@ -31,7 +31,6 @@ class Location extends Model
3131
use FiltersByRelationExistence;
3232
use HasAddress;
3333
use HasFactory;
34-
use HasWebsite;
3534

3635
/**
3736
* The attributes that are mass assignable.

app/Models/Organization.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use App\Models\Traits\HasDocuments;
88
use App\Models\Traits\HasLocation;
99
use App\Models\Traits\HasResponsibleUsers;
10-
use App\Models\Traits\HasWebsite;
1110
use App\Options\Ability;
1211
use App\Options\ActiveStatus;
1312
use App\Options\FilterValue;
@@ -25,6 +24,7 @@
2524
* @property ActiveStatus $status
2625
* @property ?string $register_entry
2726
* @property ?string $representatives
27+
* @property ?string $website_url
2828
*
2929
* @property Collection|Event[] $events {@see Organization::events()}
3030
* @property ?Organization $parentOrganization {@see Organization::parentOrganization()}
@@ -36,7 +36,6 @@ class Organization extends Model
3636
use HasFactory;
3737
use HasLocation;
3838
use HasResponsibleUsers;
39-
use HasWebsite;
4039

4140
/**
4241
* The attributes that are mass assignable.

app/Models/Traits/HasResponsibleUsers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Illuminate\Support\Facades\Auth;
1111

1212
/**
13-
* @property-read $responsibleUsers {@see self::responsibleUsers()}
13+
* @property-read Collection|User[] $responsibleUsers {@see self::responsibleUsers()}
1414
*
1515
* @mixin Model
1616
*/

app/Models/Traits/HasWebsite.php

Lines changed: 0 additions & 14 deletions
This file was deleted.

app/Notifications/BookingConfirmation.php

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,8 @@ class BookingConfirmation extends Notification
1111
{
1212
use Queueable;
1313

14-
/**
15-
* Create a new notification instance.
16-
*
17-
* @return void
18-
*/
19-
public function __construct(private Booking $booking)
20-
{
21-
}
22-
23-
/**
24-
* Get the notification's delivery channels.
25-
*
26-
* @return array
27-
*/
28-
public function via($notifiable)
14+
public function __construct(private readonly Booking $booking)
2915
{
30-
return ['mail'];
3116
}
3217

3318
/**
@@ -63,13 +48,8 @@ public function toMail($notifiable)
6348
return $mail;
6449
}
6550

66-
/**
67-
* Get the array representation of the notification.
68-
*
69-
* @return array
70-
*/
71-
public function toArray($notifiable)
51+
public function via($notifiable)
7252
{
73-
return $this->booking->toArray();
53+
return ['mail'];
7454
}
7555
}

app/Options/FormElementType.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,12 @@ public function isStatic(): bool
4747
{
4848
return $this === self::Headline;
4949
}
50+
51+
/**
52+
* @return static[]
53+
*/
54+
public static function casesForFields(): array
55+
{
56+
return self::casesFiltered(static fn (self $case) => $case->isFormField());
57+
}
5058
}

app/Options/Traits/NamedOption.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ abstract public function getTranslatedName(): string;
2020
public static function casesExcept(array|self $exceptions): array
2121
{
2222
$exceptionValues = is_array($exceptions)
23-
? array_map(fn (self $case) => $case->value, $exceptions)
23+
? array_map(static fn (self $case) => $case->value, $exceptions)
2424
: [$exceptions->value];
2525

26-
return self::casesFiltered(fn (self $case) => in_array($case, $exceptionValues, true));
26+
return self::casesFiltered(static fn (self $case) => !in_array($case->value, $exceptionValues, true));
2727
}
2828

2929
/**
@@ -33,7 +33,7 @@ public static function casesExcept(array|self $exceptions): array
3333
*/
3434
public static function casesFiltered(Closure $closure): array
3535
{
36-
return array_filter(self::cases(), fn (self $case) => $closure($case));
36+
return array_filter(self::cases(), static fn (self $case) => $closure($case));
3737
}
3838

3939
public static function exists(int|string $value): bool

database/factories/BookingFactory.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111
*/
1212
class BookingFactory extends Factory
1313
{
14-
/**
15-
* Define the model's default state.
16-
*
17-
* @return array<string, mixed>
18-
*/
1914
public function definition(): array
2015
{
2116
$firstName = fake()->firstName();

database/factories/BookingOptionFactory.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,20 @@
66
use App\Options\BookingRestriction;
77
use Carbon\Carbon;
88
use Illuminate\Database\Eloquent\Factories\Factory;
9+
use Illuminate\Support\Str;
910

1011
/**
1112
* @extends Factory<BookingOption>
1213
*/
1314
class BookingOptionFactory extends Factory
1415
{
15-
/**
16-
* Define the model's default state.
17-
*
18-
* @return array<string, mixed>
19-
*/
2016
public function definition(): array
2117
{
18+
$name = __('Booking option') . ' #' . $this->faker->unique()->randomNumber();
19+
2220
return [
23-
'name' => __('Booking option') . ' #' . $this->faker->unique()->randomNumber(),
21+
'name' => $name,
22+
'slug' => Str::slug($name),
2423
'description' => $this->faker->sentences(2, true),
2524
'available_from' => $this->faker->dateTimeBetween('-30 years', '-1 day'),
2625
'available_until' => $this->faker->dateTimeBetween('+1 day', '+30 days'),

database/factories/DocumentFactory.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
*/
1313
class DocumentFactory extends Factory
1414
{
15-
/**
16-
* Define the model's default state.
17-
*
18-
* @return array<string, mixed>
19-
*/
2015
public function definition(): array
2116
{
2217
return [

database/factories/DocumentReviewFactory.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111
*/
1212
class DocumentReviewFactory extends Factory
1313
{
14-
/**
15-
* Define the model's default state.
16-
*
17-
* @return array<string, mixed>
18-
*/
1914
public function definition(): array
2015
{
2116
return [

0 commit comments

Comments
 (0)