withoutMiddleware(ThrottleRequestsWithRedis::class); } #[Test] public function signed_post_deletes_alias_and_sends_notification() { Notification::fake(); $user = $this->createUser('johndoe'); $alias = Alias::factory()->create([ 'user_id' => $user->id, 'active' => true, ]); $this->assertNull($alias->deleted_at); $url = URL::signedRoute('delete_post', ['alias' => $alias->id]); $response = $this->post($url); $response->assertStatus(200); $response->assertSee(''); $alias->refresh(); $this->assertNotNull($alias->deleted_at); Notification::assertSentTo($user, AliasDeletedByUnsubscribeNotification::class); } #[Test] public function already_deleted_alias_returns_404_and_does_not_send_notification() { Notification::fake(); $user = $this->createUser('johndoe'); $alias = Alias::factory()->create([ 'user_id' => $user->id, 'deleted_at' => now(), ]); $url = URL::signedRoute('delete_post', ['alias' => $alias->id]); $response = $this->post($url); $response->assertStatus(404); Notification::assertNotSentTo($user, AliasDeletedByUnsubscribeNotification::class); } #[Test] public function duplicate_requests_only_send_one_notification() { Notification::fake(); $user = $this->createUser('johndoe'); $alias = Alias::factory()->create([ 'user_id' => $user->id, 'active' => true, ]); $url = URL::signedRoute('delete_post', ['alias' => $alias->id]); $this->post($url); $this->assertNotNull($alias->refresh()->deleted_at); $alias->restore(); $this->post($url); Notification::assertSentToTimes($user, AliasDeletedByUnsubscribeNotification::class, 1); $this->assertTrue(Cache::has("unsubscribe-delete-notify:{$alias->id}")); } #[Test] public function invalid_signature_returns_403() { $user = $this->createUser('johndoe'); $alias = Alias::factory()->create(['user_id' => $user->id]); $response = $this->post(route('delete_post', ['alias' => $alias->id])); $response->assertStatus(403); $this->assertNull($alias->fresh()->deleted_at); } #[Test] public function non_existent_alias_returns_404() { $url = URL::signedRoute('delete_post', ['alias' => '00000000-0000-0000-0000-000000000000']); $response = $this->post($url); $response->assertStatus(404); } }