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
|
|
|
|
2018-07-14 13:29:16 +03:00
|
|
|
public function testItShouldCreateOnlyCustomerWithoutUser()
|
|
|
|
{
|
|
|
|
$this->loginAs()
|
2020-01-07 01:28:05 +03:00
|
|
|
->post(route('customers.store'), $this->getRequest())
|
2019-11-16 10:21:14 +03:00
|
|
|
->assertStatus(200);
|
2018-09-29 17:28:34 +03:00
|
|
|
|
|
|
|
$this->assertFlashLevel('success');
|
2018-07-14 13:29:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testItShouldCreateCustomerWithUser()
|
|
|
|
{
|
2020-01-07 01:28:05 +03:00
|
|
|
$customer = $this->getRequestWithUser();
|
2018-07-14 13:29:16 +03:00
|
|
|
|
|
|
|
$this->loginAs()
|
2018-09-29 17:28:34 +03:00
|
|
|
->post(route('customers.store'), $customer)
|
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');
|
|
|
|
|
|
|
|
$user = User::where('email', $customer['email'])->first();
|
2020-01-13 10:55:19 +03:00
|
|
|
|
2018-07-14 13:29:16 +03:00
|
|
|
$this->assertNotNull($user);
|
2018-09-29 17:28:34 +03:00
|
|
|
$this->assertEquals($customer['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-01-07 01:28:05 +03:00
|
|
|
$customer = $this->dispatch(new CreateContact($this->getRequest()));
|
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-01-07 01:28:05 +03:00
|
|
|
$customer = $this->dispatch(new CreateContact($this->getRequest()));
|
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
|
|
|
|
|
|
|
$request['name'] = $this->faker->name;
|
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)
|
2019-11-16 10:21:14 +03:00
|
|
|
->assertStatus(200);
|
2018-09-29 17:28:34 +03:00
|
|
|
|
2018-07-14 13:29:16 +03:00
|
|
|
$this->assertFlashLevel('success');
|
|
|
|
}
|
|
|
|
|
2018-09-29 22:41:17 +03:00
|
|
|
public function testItShouldDeleteCustomer()
|
2018-07-14 13:29:16 +03:00
|
|
|
{
|
2020-01-07 01:28:05 +03:00
|
|
|
$customer = $this->dispatch(new CreateContact($this->getRequest()));
|
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');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
return factory(Contact::class)->states('customer', 'enabled')->raw();
|
|
|
|
}
|
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() + [
|
2019-11-17 15:06:00 +03:00
|
|
|
'create_user' => 1,
|
|
|
|
'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
|
|
|
}
|