pingcrm/tests/Feature/OrganizationsTest.php

118 lines
3.9 KiB
PHP
Raw Normal View History

2019-04-08 10:40:13 -03:00
<?php
namespace Tests\Feature;
2020-09-08 19:45:49 -03:00
use App\Models\Account;
use App\Models\User;
2019-04-08 10:40:13 -03:00
use Illuminate\Foundation\Testing\RefreshDatabase;
2020-07-29 11:58:25 -03:00
use Tests\TestCase;
2019-04-08 10:40:13 -03:00
class OrganizationsTest 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-08 10:40:13 -03:00
'first_name' => 'John',
'last_name' => 'Doe',
'email' => 'johndoe@example.com',
'owner' => true,
]);
$this->user->account->organizations()->createMany([
[
'name' => 'Apple',
'email' => 'info@apple.com',
'phone' => '647-943-4400',
'address' => '1600-120 Bremner Blvd',
'city' => 'Toronto',
'region' => 'ON',
'country' => 'CA',
'postal_code' => 'M5J 0A8',
], [
'name' => 'Microsoft',
'email' => 'info@microsoft.com',
'phone' => '877-568-2495',
'address' => 'One Microsoft Way',
'city' => 'Redmond',
'region' => 'WA',
'country' => 'US',
'postal_code' => '98052',
],
]);
2019-04-08 10:40:13 -03:00
}
public function test_can_view_organizations()
{
$this->actingAs($this->user)
->get('/organizations')
->assertInertia(fn ($assert) => $assert
->component('Organizations/Index')
->has('organizations.data', 2)
->has('organizations.data.0', fn ($assert) => $assert
->where('id', 1)
->where('name', 'Apple')
->where('phone', '647-943-4400')
->where('city', 'Toronto')
->where('deleted_at', null)
)
->has('organizations.data.1', fn ($assert) => $assert
->where('id', 2)
->where('name', 'Microsoft')
->where('phone', '877-568-2495')
->where('city', 'Redmond')
->where('deleted_at', null)
)
);
2019-04-08 10:40:13 -03:00
}
public function test_can_search_for_organizations()
{
$this->actingAs($this->user)
->get('/organizations?search=Apple')
->assertInertia(fn ($assert) => $assert
->component('Organizations/Index')
->where('filters.search', 'Apple')
->has('organizations.data', 1)
->has('organizations.data.0', fn ($assert) => $assert
->where('id', 1)
->where('name', 'Apple')
->where('phone', '647-943-4400')
->where('city', 'Toronto')
->where('deleted_at', null)
)
);
2019-04-08 10:40:13 -03:00
}
public function test_cannot_view_deleted_organizations()
{
$this->user->account->organizations()->firstWhere('name', 'Microsoft')->delete();
2019-04-08 10:40:13 -03:00
$this->actingAs($this->user)
->get('/organizations')
->assertInertia(fn ($assert) => $assert
->component('Organizations/Index')
->has('organizations.data', 1)
->where('organizations.data.0.name', 'Apple')
);
2019-04-08 10:40:13 -03:00
}
public function test_can_filter_to_view_deleted_organizations()
{
$this->user->account->organizations()->firstWhere('name', 'Microsoft')->delete();
2019-04-08 10:40:13 -03:00
$this->actingAs($this->user)
->get('/organizations?trashed=with')
->assertInertia(fn ($assert) => $assert
->component('Organizations/Index')
->has('organizations.data', 2)
->where('organizations.data.0.name', 'Apple')
->where('organizations.data.1.name', 'Microsoft')
);
2019-04-08 10:40:13 -03:00
}
}