From ee54a91454808a5ba7fa30400cf9cc915e3b4162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berkay=20G=C3=BCre?= Date: Sat, 14 Jul 2018 13:26:29 +0300 Subject: [PATCH] adds ItemsTest --- tests/Feature/Common/ItemsTest.php | 77 ++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 tests/Feature/Common/ItemsTest.php diff --git a/tests/Feature/Common/ItemsTest.php b/tests/Feature/Common/ItemsTest.php new file mode 100644 index 000000000..6510c3ebf --- /dev/null +++ b/tests/Feature/Common/ItemsTest.php @@ -0,0 +1,77 @@ +loginAs() + ->get(route('items.index')) + ->assertStatus(200) + ->assertSee('Items'); + } + + public function testItShouldBeShowCreateItemPage() + { + $this + ->loginAs() + ->get(route('items.create')) + ->assertStatus(200) + ->assertSee('New Item'); + } + + public function testItShouldStoreAnItem() + { + $picture = UploadedFile::fake()->create('image.jpg'); + + $item = [ + 'name' => $this->faker->title, + 'sku' => $this->faker->languageCode, + 'picture' => $picture, + 'description' => $this->faker->text(100), + 'purchase_price' => $this->faker->randomFloat(2,10,20), + 'sale_price' => $this->faker->randomFloat(2,10,20), + 'quantity' => $this->faker->randomNumber(2), + 'category_id' => $this->company->categories()->first()->id, + 'tax_id' => $this->company->taxes()->first()->id, + 'enabled' => $this->faker->boolean ? 1 : 0 + ]; + + $this + ->loginAs() + ->post(route('items.store'), $item) + ->assertStatus(302) + ->assertRedirect(route('items.index')); + $this->assertFlashLevel('success'); + } + + public function testItShouldEditItem() + { + $item = factory(Item::class)->create(); + + $this + ->loginAs() + ->get(route('items.edit', ['item' => $item])) + ->assertStatus(200) + ->assertSee($item->name); + } + + public function testItShouldDeleteItem() + { + $item = factory(Item::class)->create(); + + $this + ->loginAs() + ->delete(route('items.destroy', ['item' => $item])) + ->assertStatus(302) + ->assertRedirect(route('items.index')); + + $this->assertFlashLevel('success'); + } +} \ No newline at end of file