pingcrm/tests/Feature/ContactsTest.php

133 lines
4.6 KiB
PHP
Raw Normal View History

2019-04-09 01:02:25 -03:00
<?php
namespace Tests\Feature;
2020-09-08 19:45:49 -03:00
use App\Models\Account;
use App\Models\User;
2019-04-09 01:02:25 -03:00
use Illuminate\Foundation\Testing\RefreshDatabase;
2020-07-29 11:58:25 -03:00
use Tests\TestCase;
2019-04-09 01:02:25 -03:00
class ContactsTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
$this->user = User::factory()->create([
'account_id' => Account::create(['name' => 'Acme Corporation'])->id,
2019-04-09 01:02:25 -03:00
'first_name' => 'John',
'last_name' => 'Doe',
'email' => 'johndoe@example.com',
'owner' => true,
]);
$organization = $this->user->account->organizations()->create(['name' => 'Example Organization Inc.']);
$this->user->account->contacts()->createMany([
[
'organization_id' => $organization->id,
'first_name' => 'Martin',
'last_name' => 'Abbott',
'email' => 'martin.abbott@example.com',
'phone' => '555-111-2222',
'address' => '330 Glenda Shore',
'city' => 'Murphyland',
'region' => 'Tennessee',
'country' => 'US',
'postal_code' => '57851',
], [
'organization_id' => $organization->id,
'first_name' => 'Lynn',
'last_name' => 'Kub',
'email' => 'lynn.kub@example.com',
'phone' => '555-333-4444',
'address' => '199 Connelly Turnpike',
'city' => 'Woodstock',
'region' => 'Colorado',
'country' => 'US',
'postal_code' => '11623',
],
]);
2019-04-09 01:02:25 -03:00
}
public function test_can_view_contacts()
{
$this->actingAs($this->user)
->get('/contacts')
->assertInertia(fn ($assert) => $assert
->component('Contacts/Index')
->has('contacts.data', 2)
->has('contacts.data.0', fn ($assert) => $assert
->where('id', 1)
->where('name', 'Martin Abbott')
->where('phone', '555-111-2222')
->where('city', 'Murphyland')
->where('deleted_at', null)
->has('organization', fn ($assert) => $assert
->where('name', 'Example Organization Inc.')
)
)
->has('contacts.data.1', fn ($assert) => $assert
->where('id', 2)
->where('name', 'Lynn Kub')
->where('phone', '555-333-4444')
->where('city', 'Woodstock')
->where('deleted_at', null)
->has('organization', fn ($assert) => $assert
->where('name', 'Example Organization Inc.')
)
)
);
2019-04-09 01:02:25 -03:00
}
public function test_can_search_for_contacts()
{
$this->actingAs($this->user)
->get('/contacts?search=Martin')
->assertInertia(fn ($assert) => $assert
->component('Contacts/Index')
->where('filters.search', 'Martin')
->has('contacts.data', 1)
->has('contacts.data.0', fn ($assert) => $assert
->where('id', 1)
->where('name', 'Martin Abbott')
->where('phone', '555-111-2222')
->where('city', 'Murphyland')
->where('deleted_at', null)
->has('organization', fn ($assert) => $assert
->where('name', 'Example Organization Inc.')
)
)
);
2019-04-09 01:02:25 -03:00
}
public function test_cannot_view_deleted_contacts()
{
$this->user->account->contacts()->firstWhere('first_name', 'Martin')->delete();
2019-04-09 01:02:25 -03:00
$this->actingAs($this->user)
->get('/contacts')
->assertInertia(fn ($assert) => $assert
->component('Contacts/Index')
->has('contacts.data', 1)
->where('contacts.data.0.name', 'Lynn Kub')
);
2019-04-09 01:02:25 -03:00
}
public function test_can_filter_to_view_deleted_contacts()
{
$this->user->account->contacts()->firstWhere('first_name', 'Martin')->delete();
2019-04-09 01:02:25 -03:00
$this->actingAs($this->user)
->get('/contacts?trashed=with')
->assertInertia(fn ($assert) => $assert
->component('Contacts/Index')
->has('contacts.data', 2)
->where('contacts.data.0.name', 'Martin Abbott')
->where('contacts.data.1.name', 'Lynn Kub')
);
2019-04-09 01:02:25 -03:00
}
}