-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand architecture and core behavior tests #440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <?php | ||
|
|
||
| use Spatie\QueryBuilder\Filters\Filter; | ||
|
|
||
| test('filters test') | ||
| ->expect('Cachet\Filters') | ||
| ->toBeClasses() | ||
| ->toImplement(Filter::class) | ||
| ->toHaveSuffix('Filter'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <?php | ||
|
|
||
| use Laravel\Mcp\Server\Tool; | ||
|
|
||
| test('mcp tools test') | ||
| ->expect('Cachet\Mcp\Tools') | ||
| ->toBeClasses() | ||
| ->toExtend(Tool::class); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?php | ||
|
|
||
| use Cachet\Notifications\VerifySubscriberEmail; | ||
| use Illuminate\Contracts\Queue\ShouldQueue; | ||
| use Illuminate\Notifications\Notification; | ||
|
|
||
| test('notifications test') | ||
| ->expect('Cachet\Notifications') | ||
| ->toBeClasses() | ||
| ->toExtend(Notification::class) | ||
| ->toImplement(ShouldQueue::class) | ||
| ->toHaveSuffix('Notification') | ||
| ->ignoring(VerifySubscriberEmail::class); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <?php | ||
|
|
||
| use Illuminate\Database\Eloquent\Builder; | ||
|
|
||
| test('query builders test') | ||
| ->expect('Cachet\QueryBuilders') | ||
| ->toBeClasses() | ||
| ->toExtend(Builder::class) | ||
| ->toHaveSuffix('Builder'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <?php | ||
|
|
||
| use Cachet\Renderers\BladeRenderer; | ||
| use Cachet\Renderers\Renderer; | ||
| use Cachet\Renderers\TwigRenderer; | ||
|
|
||
| test('renderers test') | ||
| ->expect([ | ||
| BladeRenderer::class, | ||
| TwigRenderer::class, | ||
| ]) | ||
| ->toBeClasses() | ||
| ->toImplement(Renderer::class) | ||
| ->toHaveSuffix('Renderer'); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <?php | ||
|
|
||
| use Spatie\LaravelSettings\Settings; | ||
|
|
||
| test('settings test') | ||
| ->expect('Cachet\Settings') | ||
| ->toBeClasses() | ||
| ->toExtend(Settings::class) | ||
| ->toHaveSuffix('Settings'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| <?php | ||
|
|
||
| use Cachet\Actions\Webhook\DispatchWebhooks; | ||
| use Cachet\Enums\WebhookEventEnum; | ||
| use Cachet\Events\Components\ComponentCreated; | ||
| use Cachet\Models\Component; | ||
| use Cachet\Models\WebhookSubscription; | ||
| use Illuminate\Support\Facades\Queue; | ||
| use Spatie\WebhookServer\CallWebhookJob; | ||
|
|
||
| beforeEach(function () { | ||
| Queue::fake(); | ||
| }); | ||
|
|
||
| it('dispatches matching webhook subscriptions with the event payload', function () { | ||
| $component = Component::factory()->create(); | ||
|
|
||
| $matching = WebhookSubscription::factory() | ||
| ->selectedEvents([WebhookEventEnum::component_created]) | ||
| ->create(); | ||
|
|
||
| WebhookSubscription::factory() | ||
| ->selectedEvents([WebhookEventEnum::component_updated]) | ||
| ->create(); | ||
|
|
||
| app(DispatchWebhooks::class)->handle(new ComponentCreated($component)); | ||
|
|
||
| Queue::assertPushed(CallWebhookJob::class, function (CallWebhookJob $job) use ($component, $matching): bool { | ||
| return $job->webhookUrl === $matching->url | ||
| && $job->payload === [ | ||
| 'event' => WebhookEventEnum::component_created->value, | ||
| 'body' => $component->toArray(), | ||
| ] | ||
| && $job->meta === [ | ||
| 'subscription_id' => $matching->id, | ||
| 'event' => WebhookEventEnum::component_created->value, | ||
| ]; | ||
| }); | ||
|
|
||
| Queue::assertPushed(CallWebhookJob::class, 1); | ||
| }); | ||
|
|
||
| it('dispatches subscriptions configured for all events', function () { | ||
| WebhookSubscription::factory()->allEvents()->create(); | ||
|
|
||
| Component::factory()->create(); | ||
|
|
||
| Queue::assertPushed(CallWebhookJob::class, 1); | ||
| }); | ||
|
|
||
| it('does not dispatch when no subscriptions match the event', function () { | ||
| WebhookSubscription::factory() | ||
| ->selectedEvents([WebhookEventEnum::component_updated]) | ||
| ->create(); | ||
|
|
||
| app(DispatchWebhooks::class)->handle(new ComponentCreated(Component::factory()->create())); | ||
|
|
||
| Queue::assertNothingPushed(); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| <?php | ||
|
|
||
| use Cachet\Data\Casts\FlexibleDateTimeCast; | ||
| use Carbon\Carbon; | ||
| use Spatie\LaravelData\Casts\Uncastable; | ||
| use Spatie\LaravelData\Support\Creation\CreationContext; | ||
| use Spatie\LaravelData\Support\DataProperty; | ||
|
|
||
| it('casts supported date values to carbon', function (mixed $value, string $expected) { | ||
| $result = (new FlexibleDateTimeCast)->cast( | ||
| mock(DataProperty::class), | ||
| $value, | ||
| [], | ||
| mock(CreationContext::class), | ||
| ); | ||
|
|
||
| expect($result) | ||
| ->toBeInstanceOf(Carbon::class) | ||
| ->and($result->toIso8601String())->toBe($expected); | ||
| })->with([ | ||
| 'date time' => [new DateTimeImmutable('2026-08-10T12:30:00+00:00'), '2026-08-10T12:30:00+00:00'], | ||
| 'ISO 8601 string' => ['2026-08-10T13:30:00+01:00', '2026-08-10T12:30:00+00:00'], | ||
| 'timestamp' => [1786365000, '2026-08-10T12:30:00+00:00'], | ||
| ]); | ||
|
|
||
| it('returns uncastable for unsupported or invalid values', function (mixed $value) { | ||
| $result = (new FlexibleDateTimeCast)->cast( | ||
| mock(DataProperty::class), | ||
| $value, | ||
| [], | ||
| mock(CreationContext::class), | ||
| ); | ||
|
|
||
| expect($result)->toBeInstanceOf(Uncastable::class); | ||
| })->with([ | ||
| 'null' => null, | ||
| 'boolean' => true, | ||
| 'array' => [[]], | ||
| 'object' => [new stdClass], | ||
| 'invalid string' => 'not a date', | ||
| ]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| <?php | ||
|
|
||
| use Cachet\Models\Component; | ||
|
|
||
| it('synchronizes metadata while preserving value types', function () { | ||
| $component = Component::factory()->create(); | ||
|
|
||
| $component->syncMeta([ | ||
| 'region' => 'eu-west', | ||
| 'priority' => 3, | ||
| 'enabled' => true, | ||
| 'options' => ['replicas' => 2], | ||
| ]); | ||
|
|
||
| expect($component->metaValues())->toBe([ | ||
| 'region' => 'eu-west', | ||
| 'priority' => 3, | ||
| 'enabled' => true, | ||
| 'options' => ['replicas' => 2], | ||
| ]); | ||
| }); | ||
|
|
||
| it('updates supplied metadata and removes omitted keys', function () { | ||
| $component = Component::factory()->create(); | ||
| $component->syncMeta(['region' => 'eu-west', 'stale' => true]); | ||
|
|
||
| $component->load('meta'); | ||
| $component->syncMeta(['region' => 'us-east']); | ||
|
|
||
| expect($component->relationLoaded('meta'))->toBeFalse() | ||
| ->and($component->metaValues())->toBe(['region' => 'us-east']); | ||
| }); | ||
|
|
||
| it('retains metadata when its owner is soft deleted', function () { | ||
| $component = Component::factory()->create(); | ||
| $component->syncMeta(['region' => 'eu-west']); | ||
| $metaId = $component->meta()->sole()->id; | ||
|
|
||
| $component->delete(); | ||
|
|
||
| $this->assertDatabaseHas('meta', ['id' => $metaId]); | ||
| }); | ||
|
|
||
| it('deletes metadata when its owner is force deleted', function () { | ||
| $component = Component::factory()->create(); | ||
| $component->syncMeta(['region' => 'eu-west']); | ||
| $metaId = $component->meta()->sole()->id; | ||
|
|
||
| $component->forceDelete(); | ||
|
|
||
| $this->assertDatabaseMissing('meta', ['id' => $metaId]); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.