seed(RolePermissionSeeder::class); } #[Test] public function the_inbox_renders(): void { $call = Call::factory()->create(['project_id' => null]); Application::factory()->count(2)->create(); Application::factory()->forCall($call->id)->create(); Application::factory()->request()->create(); Application::factory()->spam()->create(); $this->actingAs($this->userWithRoles('admin')); $this->get(ApplicationResource::getUrl('index'))->assertSuccessful(); } #[Test] public function a_submission_can_be_opened(): void { $application = Application::factory()->create(); $this->actingAs($this->userWithRoles('admin')); $this->get(ApplicationResource::getUrl('view', ['record' => $application])) ->assertSuccessful() ->assertSee($application->name); } #[Test] public function the_replies_to_a_call_show_on_the_call_itself(): void { $call = Call::factory()->create(['project_id' => null]); Application::factory()->forCall($call->id)->create(); $this->actingAs($this->userWithRoles('admin')); // "Is anybody interested?" is a question you have while looking at the // opening, not while working through the whole inbox. $this->get(CallResource::getUrl('edit', ['record' => $call])) ->assertSuccessful(); } #[Test] public function an_editor_runs_the_calls_so_an_editor_answers_them(): void { $editor = $this->userWithRoles('editor'); $this->assertTrue($editor->can('applications.view_any')); $this->assertTrue($editor->can('applications.update')); } #[Test] public function a_viewer_never_sees_a_strangers_contact_details(): void { $viewer = $this->userWithRoles('viewer'); $this->actingAs($viewer); // Reading the site's content and reading the people who wrote in are // deliberately different rights. $this->assertFalse($viewer->can('applications.view_any')); $this->assertFalse(ApplicationResource::canViewAny()); $this->get(ApplicationResource::getUrl('index'))->assertForbidden(); } #[Test] public function nobody_creates_a_submission_by_hand(): void { $admin = $this->userWithRoles('admin'); $this->actingAs($admin); // They arrive from the public site. A hand-written one would be a // record of a conversation that never happened. $this->assertFalse(ApplicationResource::canCreate()); $this->assertFalse($admin->can('create', Application::class)); } #[Test] public function answering_records_who_answered(): void { $admin = $this->userWithRoles('admin'); $application = Application::factory()->create(); $application->markAs(ApplicationStatus::Contacted, $admin); $application->refresh(); // An inbox worked by several people otherwise turns into two replies // or none. $this->assertSame(ApplicationStatus::Contacted, $application->status); $this->assertSame($admin->id, $application->handled_by); $this->assertNotNull($application->handled_at); } #[Test] public function the_badge_counts_the_people_still_waiting(): void { Application::factory()->count(2)->create(); Application::factory()->handled()->create(); Application::factory()->spam()->create(); $this->actingAs($this->userWithRoles('admin')); $this->assertSame('2', ApplicationResource::getNavigationBadge()); } #[Test] public function a_submission_survives_the_call_it_answered(): void { $call = Call::factory()->create([ 'project_id' => null, 'title' => ['es' => 'Backend'], ]); $application = Application::factory()->forCall($call->id, 'Backend')->create(); $call->delete(); $application->refresh(); // The opening was tidied up; the person who wrote in was not. $this->assertNull($application->call_id); $this->assertSame('Backend', $application->subject()); } }