From 5bf7c4be81a7615119ee2a16e99104de70b22b8b Mon Sep 17 00:00:00 2001 From: Linus Juhlin Date: Tue, 9 Apr 2019 13:02:25 +0900 Subject: [PATCH] Added Contacts Feature test --- tests/Feature/ContactsTest.php | 93 ++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 tests/Feature/ContactsTest.php diff --git a/tests/Feature/ContactsTest.php b/tests/Feature/ContactsTest.php new file mode 100644 index 0000000..8422322 --- /dev/null +++ b/tests/Feature/ContactsTest.php @@ -0,0 +1,93 @@ + 'Acme Corporation']); + + $this->user = factory(User::class)->create([ + 'account_id' => $account->id, + 'first_name' => 'John', + 'last_name' => 'Doe', + 'email' => 'johndoe@example.com', + 'owner' => true, + ]); + } + + public function test_can_view_contacts() + { + $this->user->account->contacts()->saveMany( + factory(Contact::class, 5)->make() + ); + + $this->actingAs($this->user) + ->get('/contacts') + ->assertStatus(200) + ->assertPropCount('contacts.data', 5) + ->assertPropValue('contacts.data', function ($contacts) { + $this->assertEquals( + ['id', 'name', 'phone', 'city', + 'deleted_at', 'organization'], + array_keys($contacts[0]) + ); + }); + } + + public function test_can_search_for_contacts() + { + $this->user->account->contacts()->saveMany( + factory(contact::class, 5)->make() + )->first()->update([ + 'first_name' => 'Greg', + 'last_name' => 'Andersson' + ]); + + $this->actingAs($this->user) + ->get('/contacts?search=Greg') + ->assertStatus(200) + ->assertPropValue('filters.search', 'Greg') + ->assertPropCount('contacts.data', 1) + ->assertPropValue('contacts.data', function ($contacts) { + $this->assertEquals('Greg Andersson', $contacts[0]['name']); + }); + } + + public function test_cannot_view_deleted_contacts() + { + $this->user->account->contacts()->saveMany( + factory(contact::class, 5)->make() + )->first()->delete(); + + $this->actingAs($this->user) + ->get('/contacts') + ->assertStatus(200) + ->assertPropCount('contacts.data', 4); + } + + public function test_can_filter_to_view_deleted_contacts() + { + $this->user->account->contacts()->saveMany( + factory(contact::class, 5)->make() + )->first()->delete(); + + $this->actingAs($this->user) + ->get('/contacts?trashed=with') + ->assertStatus(200) + ->assertPropValue('filters.trashed', 'with') + ->assertPropCount('contacts.data', 5); + } +}