2018-07-14 13:26:29 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Common;
|
|
|
|
|
2019-11-17 15:06:00 +03:00
|
|
|
use App\Jobs\Common\CreateItem;
|
2018-07-14 13:26:29 +03:00
|
|
|
use Illuminate\Http\UploadedFile;
|
|
|
|
use Tests\Feature\FeatureTestCase;
|
|
|
|
|
|
|
|
class ItemsTest extends FeatureTestCase
|
|
|
|
{
|
2018-09-29 22:41:17 +03:00
|
|
|
public function testItShouldSeeItemListPage()
|
2018-07-14 13:26:29 +03:00
|
|
|
{
|
2018-09-29 17:28:34 +03:00
|
|
|
$this->loginAs()
|
2018-07-14 13:26:29 +03:00
|
|
|
->get(route('items.index'))
|
|
|
|
->assertStatus(200)
|
2018-09-29 22:41:17 +03:00
|
|
|
->assertSeeText(trans_choice('general.items', 2));
|
2018-07-14 13:26:29 +03:00
|
|
|
}
|
|
|
|
|
2018-09-29 22:41:17 +03:00
|
|
|
public function testItShouldSeeItemCreatePage()
|
2018-07-14 13:26:29 +03:00
|
|
|
{
|
2018-09-29 17:28:34 +03:00
|
|
|
$this->loginAs()
|
2018-07-14 13:26:29 +03:00
|
|
|
->get(route('items.create'))
|
|
|
|
->assertStatus(200)
|
2018-09-29 22:41:17 +03:00
|
|
|
->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.items', 1)]));
|
2018-07-14 13:26:29 +03:00
|
|
|
}
|
|
|
|
|
2018-09-29 22:41:17 +03:00
|
|
|
public function testItShouldCreateItem()
|
2018-07-14 13:26:29 +03:00
|
|
|
{
|
2018-09-29 17:28:34 +03:00
|
|
|
$this->loginAs()
|
|
|
|
->post(route('items.store'), $this->getItemRequest())
|
2019-11-16 10:21:14 +03:00
|
|
|
->assertStatus(200);
|
2018-09-29 17:28:34 +03:00
|
|
|
|
2018-07-14 13:26:29 +03:00
|
|
|
$this->assertFlashLevel('success');
|
|
|
|
}
|
|
|
|
|
2018-09-29 22:41:17 +03:00
|
|
|
public function testItShouldSeeItemUpdatePage()
|
2018-07-14 13:26:29 +03:00
|
|
|
{
|
2019-11-17 15:06:00 +03:00
|
|
|
$item = $this->dispatch(new CreateItem($this->getItemRequest()));
|
2018-07-14 13:26:29 +03:00
|
|
|
|
2018-09-29 17:28:34 +03:00
|
|
|
$this->loginAs()
|
|
|
|
->get(route('items.edit', ['item' => $item->id]))
|
2018-07-14 13:26:29 +03:00
|
|
|
->assertStatus(200)
|
|
|
|
->assertSee($item->name);
|
|
|
|
}
|
|
|
|
|
2018-09-29 22:41:17 +03:00
|
|
|
public function testItShouldUpdateItem()
|
|
|
|
{
|
|
|
|
$request = $this->getItemRequest();
|
|
|
|
|
2019-11-17 15:06:00 +03:00
|
|
|
$item = $this->dispatch(new CreateItem($request));
|
2018-09-29 22:41:17 +03:00
|
|
|
|
2019-11-18 10:54:26 +03:00
|
|
|
$request['name'] = $this->faker->text(15);
|
2018-09-29 22:41:17 +03:00
|
|
|
|
|
|
|
$this->loginAs()
|
|
|
|
->patch(route('items.update', $item->id), $request)
|
2019-11-16 10:21:14 +03:00
|
|
|
->assertStatus(200);
|
2018-09-29 22:41:17 +03:00
|
|
|
|
|
|
|
$this->assertFlashLevel('success');
|
|
|
|
}
|
|
|
|
|
2018-07-14 13:26:29 +03:00
|
|
|
public function testItShouldDeleteItem()
|
|
|
|
{
|
2019-11-17 15:06:00 +03:00
|
|
|
$item = $this->dispatch(new CreateItem($this->getItemRequest()));
|
2018-07-14 13:26:29 +03:00
|
|
|
|
2018-09-29 17:28:34 +03:00
|
|
|
$this->loginAs()
|
2018-07-14 13:26:29 +03:00
|
|
|
->delete(route('items.destroy', ['item' => $item]))
|
2019-11-16 10:21:14 +03:00
|
|
|
->assertStatus(200);
|
2018-07-14 13:26:29 +03:00
|
|
|
|
|
|
|
$this->assertFlashLevel('success');
|
|
|
|
}
|
2018-09-29 17:28:34 +03:00
|
|
|
|
|
|
|
private function getItemRequest()
|
|
|
|
{
|
|
|
|
$picture = UploadedFile::fake()->create('image.jpg');
|
|
|
|
|
|
|
|
return [
|
|
|
|
'company_id' => $this->company->id,
|
2018-09-29 22:41:17 +03:00
|
|
|
'name' => $this->faker->text(15),
|
2018-09-29 17:28:34 +03:00
|
|
|
'picture' => $picture,
|
|
|
|
'description' => $this->faker->text(100),
|
2018-09-29 22:41:17 +03:00
|
|
|
'purchase_price' => $this->faker->randomFloat(2, 10, 20),
|
|
|
|
'sale_price' => $this->faker->randomFloat(2, 10, 20),
|
2019-11-17 15:06:00 +03:00
|
|
|
'category_id' => $this->company->categories()->type('item')->pluck('id')->first(),
|
2018-12-22 14:06:08 +03:00
|
|
|
'tax_id' => '',
|
2018-09-29 17:28:34 +03:00
|
|
|
'enabled' => $this->faker->boolean ? 1 : 0
|
|
|
|
];
|
|
|
|
}
|
2019-04-02 18:51:06 +03:00
|
|
|
}
|