2018-07-14 13:29:16 +03:00
|
|
|
<?php
|
|
|
|
|
2019-12-31 15:49:09 +03:00
|
|
|
namespace Tests\Feature\Sales;
|
2018-07-14 13:29:16 +03:00
|
|
|
|
2019-11-17 15:06:00 +03:00
|
|
|
use App\Jobs\Common\CreateContact;
|
2018-07-14 13:29:16 +03:00
|
|
|
use App\Models\Auth\User;
|
2020-01-07 01:28:05 +03:00
|
|
|
use App\Models\Common\Contact;
|
2018-07-14 13:29:16 +03:00
|
|
|
use Tests\Feature\FeatureTestCase;
|
|
|
|
|
|
|
|
class CustomersTest extends FeatureTestCase
|
|
|
|
{
|
2018-09-29 22:41:17 +03:00
|
|
|
public function testItShouldSeeCustomerListPage()
|
|
|
|
{
|
|
|
|
$this->loginAs()
|
|
|
|
->get(route('customers.index'))
|
|
|
|
->assertStatus(200)
|
|
|
|
->assertSeeText(trans_choice('general.customers', 2));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItShouldSeeCustomerCreatePage()
|
|
|
|
{
|
|
|
|
$this->loginAs()
|
|
|
|
->get(route('customers.create'))
|
|
|
|
->assertStatus(200)
|
|
|
|
->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.customers', 1)]));
|
|
|
|
}
|
2020-01-13 10:55:19 +03:00
|
|
|
|
2020-07-25 17:22:50 +03:00
|
|
|
public function testItShouldCreateCustomer()
|
2018-07-14 13:29:16 +03:00
|
|
|
{
|
2020-07-25 17:22:50 +03:00
|
|
|
$request = $this->getRequest();
|
|
|
|
|
2018-07-14 13:29:16 +03:00
|
|
|
$this->loginAs()
|
2020-07-25 17:22:50 +03:00
|
|
|
->post(route('customers.store'), $request)
|
2019-11-16 10:21:14 +03:00
|
|
|
->assertStatus(200);
|
2018-09-29 17:28:34 +03:00
|
|
|
|
|
|
|
$this->assertFlashLevel('success');
|
2020-07-25 17:22:50 +03:00
|
|
|
|
|
|
|
$this->assertDatabaseHas('contacts', $request);
|
2018-07-14 13:29:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testItShouldCreateCustomerWithUser()
|
|
|
|
{
|
2020-07-25 17:22:50 +03:00
|
|
|
$request = $this->getRequestWithUser();
|
2018-07-14 13:29:16 +03:00
|
|
|
|
|
|
|
$this->loginAs()
|
2020-07-25 17:22:50 +03:00
|
|
|
->post(route('customers.store'), $request)
|
2019-11-16 10:21:14 +03:00
|
|
|
->assertStatus(200);
|
2018-07-14 13:29:16 +03:00
|
|
|
|
2018-09-29 17:28:34 +03:00
|
|
|
$this->assertFlashLevel('success');
|
|
|
|
|
2020-07-25 17:22:50 +03:00
|
|
|
$user = User::where('email', $request['email'])->first();
|
2020-01-13 10:55:19 +03:00
|
|
|
|
2018-07-14 13:29:16 +03:00
|
|
|
$this->assertNotNull($user);
|
2020-07-25 17:22:50 +03:00
|
|
|
$this->assertEquals($request['email'], $user->email);
|
2018-07-14 13:29:16 +03:00
|
|
|
}
|
|
|
|
|
2018-09-29 22:41:17 +03:00
|
|
|
public function testItShouldSeeCustomerDetailPage()
|
2018-07-14 13:29:16 +03:00
|
|
|
{
|
2020-07-25 17:22:50 +03:00
|
|
|
$request = $this->getRequest();
|
|
|
|
|
|
|
|
$customer = $this->dispatch(new CreateContact($request));
|
2018-09-29 17:28:34 +03:00
|
|
|
|
2018-09-29 22:41:17 +03:00
|
|
|
$this->loginAs()
|
2020-01-13 10:55:19 +03:00
|
|
|
->get(route('customers.show', $customer->id))
|
2018-07-14 13:29:16 +03:00
|
|
|
->assertStatus(200)
|
|
|
|
->assertSee($customer->email);
|
|
|
|
}
|
|
|
|
|
2018-09-29 22:41:17 +03:00
|
|
|
public function testItShouldSeeCustomerUpdatePage()
|
2018-07-14 13:29:16 +03:00
|
|
|
{
|
2020-07-25 17:22:50 +03:00
|
|
|
$request = $this->getRequest();
|
|
|
|
|
|
|
|
$customer = $this->dispatch(new CreateContact($request));
|
2018-09-29 17:28:34 +03:00
|
|
|
|
2018-09-29 22:41:17 +03:00
|
|
|
$this->loginAs()
|
2020-01-13 10:55:19 +03:00
|
|
|
->get(route('customers.edit', $customer->id))
|
2018-07-14 13:29:16 +03:00
|
|
|
->assertStatus(200)
|
2020-01-13 10:55:19 +03:00
|
|
|
->assertSee($customer->email);
|
2018-07-14 13:29:16 +03:00
|
|
|
}
|
|
|
|
|
2018-09-29 22:41:17 +03:00
|
|
|
public function testItShouldUpdateCustomer()
|
2018-07-14 13:29:16 +03:00
|
|
|
{
|
2020-01-07 01:28:05 +03:00
|
|
|
$request = $this->getRequest();
|
2018-09-29 17:28:34 +03:00
|
|
|
|
2019-11-17 15:06:00 +03:00
|
|
|
$customer = $this->dispatch(new CreateContact($request));
|
2018-09-29 17:28:34 +03:00
|
|
|
|
2020-03-19 19:00:18 +03:00
|
|
|
$request['email'] = $this->faker->safeEmail;
|
2018-07-14 13:29:16 +03:00
|
|
|
|
2018-09-29 22:41:17 +03:00
|
|
|
$this->loginAs()
|
2018-09-29 17:28:34 +03:00
|
|
|
->patch(route('customers.update', $customer->id), $request)
|
2020-01-13 17:20:28 +03:00
|
|
|
->assertStatus(200)
|
2020-03-19 19:00:18 +03:00
|
|
|
->assertSee($request['email']);
|
2018-09-29 17:28:34 +03:00
|
|
|
|
2018-07-14 13:29:16 +03:00
|
|
|
$this->assertFlashLevel('success');
|
2020-07-25 17:22:50 +03:00
|
|
|
|
|
|
|
$this->assertDatabaseHas('contacts', $request);
|
2018-07-14 13:29:16 +03:00
|
|
|
}
|
|
|
|
|
2018-09-29 22:41:17 +03:00
|
|
|
public function testItShouldDeleteCustomer()
|
2018-07-14 13:29:16 +03:00
|
|
|
{
|
2020-07-25 17:22:50 +03:00
|
|
|
$request = $this->getRequest();
|
|
|
|
|
|
|
|
$customer = $this->dispatch(new CreateContact($request));
|
2018-07-14 13:29:16 +03:00
|
|
|
|
|
|
|
$this->loginAs()
|
|
|
|
->delete(route('customers.destroy', $customer->id))
|
2019-11-16 10:21:14 +03:00
|
|
|
->assertStatus(200);
|
2020-01-13 10:55:19 +03:00
|
|
|
|
2018-07-14 13:29:16 +03:00
|
|
|
$this->assertFlashLevel('success');
|
|
|
|
|
2020-07-25 17:22:50 +03:00
|
|
|
$this->assertSoftDeleted('contacts', $request);
|
|
|
|
|
2018-07-14 13:29:16 +03:00
|
|
|
}
|
|
|
|
|
2018-09-29 22:41:17 +03:00
|
|
|
public function testItShouldNotDeleteCustomerIfHasRelations()
|
2018-07-14 13:29:16 +03:00
|
|
|
{
|
|
|
|
$this->assertTrue(true);
|
|
|
|
//TODO : This will write after done invoice and revenues tests.
|
|
|
|
}
|
|
|
|
|
2020-01-07 01:28:05 +03:00
|
|
|
public function getRequest()
|
|
|
|
{
|
2020-10-14 17:07:59 +03:00
|
|
|
return Contact::factory()->customer()->enabled()->raw();
|
2020-01-07 01:28:05 +03:00
|
|
|
}
|
2018-07-14 13:29:16 +03:00
|
|
|
|
2020-01-07 01:28:05 +03:00
|
|
|
public function getRequestWithUser()
|
2018-07-14 13:29:16 +03:00
|
|
|
{
|
|
|
|
$password = $this->faker->password;
|
|
|
|
|
2020-01-07 01:28:05 +03:00
|
|
|
return $this->getRequest() + [
|
2020-03-04 17:02:16 +03:00
|
|
|
'create_user' => 'true',
|
2019-11-17 15:06:00 +03:00
|
|
|
'locale' => 'en-GB',
|
|
|
|
'password' => $password,
|
2020-01-07 01:28:05 +03:00
|
|
|
'password_confirmation' => $password,
|
2019-11-17 15:06:00 +03:00
|
|
|
];
|
2018-07-14 13:29:16 +03:00
|
|
|
}
|
2019-04-02 18:51:06 +03:00
|
|
|
}
|