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
4 changes: 3 additions & 1 deletion app/Notifications/NewPluginAvailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function toMail(object $notifiable): MailMessage
->subject("New Plugin: {$this->plugin->name}")
->greeting('A new plugin is available!')
->line("**{$this->plugin->name}** has just been added to the NativePHP Plugin Marketplace.")
->action('View Plugin', url('/plugins'))
->action('View Plugin', route('plugins.show', $this->plugin->routeParams()))
->line('You can manage your notification preferences in your account settings.');
}

Expand All @@ -48,6 +48,8 @@ public function toArray(object $notifiable): array
'body' => "{$this->plugin->name} has just been added to the NativePHP Plugin Marketplace.",
'plugin_id' => $this->plugin->id,
'plugin_name' => $this->plugin->name,
'action_url' => route('plugins.show', $this->plugin->routeParams()),
'action_label' => 'View Plugin',
];
}
}
4 changes: 3 additions & 1 deletion app/Notifications/PluginApproved.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function toMail(object $notifiable): MailMessage
->subject('Your Plugin Has Been Approved!')
->greeting('Great news!')
->line("Your plugin **{$this->plugin->name}** has been approved and is now listed in the NativePHP Plugin Marketplace.")
->action('View Plugin Marketplace', url('/plugins'))
->action('View Plugin', route('plugins.show', $this->plugin->routeParams()))
->line('Thank you for contributing to the NativePHP ecosystem!');
}

Expand All @@ -51,6 +51,8 @@ public function toArray(object $notifiable): array
'body' => "{$this->plugin->name} is now listed in the NativePHP Plugin Marketplace.",
'plugin_id' => $this->plugin->id,
'plugin_name' => $this->plugin->name,
'action_url' => route('plugins.show', $this->plugin->routeParams()),
'action_label' => 'View Plugin',
];
}
}
4 changes: 3 additions & 1 deletion app/Notifications/PluginRejected.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function toMail(object $notifiable): MailMessage
->line("Unfortunately, your plugin **{$this->plugin->name}** was not approved for the NativePHP Plugin Marketplace.")
->line('**Reason:**')
->line($this->plugin->rejection_reason)
->action('View Your Plugins', route('customer.plugins.index'))
->action('View Plugin', route('customer.plugins.show', $this->plugin->routeParams()))
->line('If you have questions about this decision, please reach out to us.');
}

Expand All @@ -54,6 +54,8 @@ public function toArray(object $notifiable): array
'plugin_id' => $this->plugin->id,
'plugin_name' => $this->plugin->name,
'rejection_reason' => $this->plugin->rejection_reason,
'action_url' => route('customer.plugins.show', $this->plugin->routeParams()),
'action_label' => 'View Plugin',
];
}
}
16 changes: 11 additions & 5 deletions resources/views/livewire/customer/notifications.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="mx-auto max-w-2xl">
<div class="mb-6 flex items-center justify-between">
<div class="mb-6 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
<div>
<flux:heading size="xl">Notifications</flux:heading>
<flux:text>Stay up to date with your account activity.</flux:text>
Expand Down Expand Up @@ -44,13 +44,19 @@
<flux:text class="mt-1">{{ $notification->data['body'] }}</flux:text>
@endif

@if (is_null($notification->read_at))
<div class="mt-2">
<div class="mt-2 flex items-center gap-2">
@if (! empty($notification->data['action_url']))
<flux:button href="{{ $notification->data['action_url'] }}" variant="primary" size="xs">
{{ $notification->data['action_label'] ?? 'View' }}
</flux:button>
@endif

@if (is_null($notification->read_at))
<flux:button wire:click="markAsRead('{{ $notification->id }}')" variant="ghost" size="xs">
Mark as read
</flux:button>
</div>
@endif
@endif
</div>
</div>
</div>
</flux:card>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/livewire/team-manager.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

{{-- Seat Management --}}
<flux:card class="mb-6">
<div class="flex items-center justify-between">
<div class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
<div>
<flux:heading size="lg">Seats</flux:heading>
<flux:text class="mt-1">
Expand Down
13 changes: 13 additions & 0 deletions tests/Feature/Notifications/NewPluginAvailableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ public function test_mail_contains_plugin_name(): void
$this->assertStringContainsString('acme/awesome-plugin', $mail->subject);
}

public function test_mail_action_links_to_plugin_page(): void
{
$user = User::factory()->create();
$plugin = Plugin::factory()->for($user)->create(['name' => 'acme/awesome-plugin']);

$notification = new NewPluginAvailable($plugin);
$mail = $notification->toMail($user);

$this->assertEquals(route('plugins.show', ['vendor' => 'acme', 'package' => 'awesome-plugin']), $mail->actionUrl);
}

public function test_database_notification_contains_plugin_data(): void
{
$user = User::factory()->create();
Expand All @@ -100,6 +111,8 @@ public function test_database_notification_contains_plugin_data(): void
$this->assertEquals($plugin->id, $data['plugin_id']);
$this->assertEquals('acme/awesome-plugin', $data['plugin_name']);
$this->assertStringContainsString('acme/awesome-plugin', $data['title']);
$this->assertEquals(route('plugins.show', ['vendor' => 'acme', 'package' => 'awesome-plugin']), $data['action_url']);
$this->assertEquals('View Plugin', $data['action_label']);
}

public function test_new_users_receive_new_plugin_notifications_by_default(): void
Expand Down
58 changes: 58 additions & 0 deletions tests/Feature/Notifications/PluginApprovedTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Tests\Feature\Notifications;

use App\Models\Plugin;
use App\Models\User;
use App\Notifications\PluginApproved;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class PluginApprovedTest extends TestCase
{
use RefreshDatabase;

public function test_mail_action_links_to_plugin_page(): void
{
$user = User::factory()->create();
$plugin = Plugin::factory()->for($user)->create(['name' => 'acme/awesome-plugin']);

$notification = new PluginApproved($plugin);
$mail = $notification->toMail($user);

$this->assertEquals(route('plugins.show', ['vendor' => 'acme', 'package' => 'awesome-plugin']), $mail->actionUrl);
}

public function test_database_notification_contains_action_url(): void
{
$user = User::factory()->create();
$plugin = Plugin::factory()->for($user)->create(['name' => 'acme/awesome-plugin']);

$notification = new PluginApproved($plugin);
$data = $notification->toArray($user);

$this->assertEquals(route('plugins.show', ['vendor' => 'acme', 'package' => 'awesome-plugin']), $data['action_url']);
$this->assertEquals('View Plugin', $data['action_label']);
}

public function test_mail_contains_plugin_name(): void
{
$user = User::factory()->create();
$plugin = Plugin::factory()->for($user)->create(['name' => 'acme/awesome-plugin']);

$notification = new PluginApproved($plugin);
$mail = $notification->toMail($user);

$this->assertStringContainsString('acme/awesome-plugin', $mail->render()->toHtml());
}

public function test_via_returns_mail_and_database(): void
{
$user = User::factory()->create();
$plugin = Plugin::factory()->for($user)->create();

$notification = new PluginApproved($plugin);

$this->assertEquals(['mail', 'database'], $notification->via($user));
}
}
75 changes: 75 additions & 0 deletions tests/Feature/Notifications/PluginRejectedTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace Tests\Feature\Notifications;

use App\Models\Plugin;
use App\Models\User;
use App\Notifications\PluginRejected;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class PluginRejectedTest extends TestCase
{
use RefreshDatabase;

public function test_mail_action_links_to_dashboard_plugin_page(): void
{
$user = User::factory()->create();
$plugin = Plugin::factory()->for($user)->create(['name' => 'acme/awesome-plugin']);

$notification = new PluginRejected($plugin);
$mail = $notification->toMail($user);

$this->assertEquals(route('customer.plugins.show', ['vendor' => 'acme', 'package' => 'awesome-plugin']), $mail->actionUrl);
}

public function test_database_notification_contains_action_url(): void
{
$user = User::factory()->create();
$plugin = Plugin::factory()->for($user)->create(['name' => 'acme/awesome-plugin']);

$notification = new PluginRejected($plugin);
$data = $notification->toArray($user);

$this->assertEquals(route('customer.plugins.show', ['vendor' => 'acme', 'package' => 'awesome-plugin']), $data['action_url']);
$this->assertEquals('View Plugin', $data['action_label']);
}

public function test_mail_contains_rejection_reason(): void
{
$user = User::factory()->create();
$plugin = Plugin::factory()->for($user)->create([
'name' => 'acme/awesome-plugin',
'rejection_reason' => 'Missing license file',
]);

$notification = new PluginRejected($plugin);
$rendered = $notification->toMail($user)->render()->toHtml();

$this->assertStringContainsString('Missing license file', $rendered);
}

public function test_database_notification_contains_rejection_reason(): void
{
$user = User::factory()->create();
$plugin = Plugin::factory()->for($user)->create([
'name' => 'acme/awesome-plugin',
'rejection_reason' => 'Missing license file',
]);

$notification = new PluginRejected($plugin);
$data = $notification->toArray($user);

$this->assertEquals('Missing license file', $data['rejection_reason']);
}

public function test_via_returns_mail_and_database(): void
{
$user = User::factory()->create();
$plugin = Plugin::factory()->for($user)->create();

$notification = new PluginRejected($plugin);

$this->assertEquals(['mail', 'database'], $notification->via($user));
}
}
Loading