From f6222c62537f47e10e2a27bbf046d4272e145f47 Mon Sep 17 00:00:00 2001 From: Zain Fauzan Rofie Azizi Date: Tue, 26 Jun 2018 13:15:42 +0800 Subject: [PATCH] bug fixing --- app/Http/Controllers/ContactController.php | 4 +- app/Http/Controllers/WarehouseController.php | 1 - tests/warehouseTest.php | 164 +++++++------------ 3 files changed, 65 insertions(+), 104 deletions(-) diff --git a/app/Http/Controllers/ContactController.php b/app/Http/Controllers/ContactController.php index 99d0d58..26530e9 100644 --- a/app/Http/Controllers/ContactController.php +++ b/app/Http/Controllers/ContactController.php @@ -9,14 +9,14 @@ use Illuminate\Http\Request; class ContactController extends Controller { /** - * list the company that belongs to user's company only + * * * @param int $id * @return \Illuminate\Http\Response */ public function index() { - $contacts = Contact::where('user_id', Auth::user()->id)->where('id', $id)->first(); + $contacts = Contact::where('user_id', Auth::user()->id)->where('id', $id)->get(); if (!$contacts) { diff --git a/app/Http/Controllers/WarehouseController.php b/app/Http/Controllers/WarehouseController.php index 2cfd5db..923f850 100644 --- a/app/Http/Controllers/WarehouseController.php +++ b/app/Http/Controllers/WarehouseController.php @@ -40,7 +40,6 @@ class WarehouseController extends Controller public function show($id) { $warehouses = DB::table('warehouses') - //->join('id', 'address', 'city', 'zip') ->select('id', 'address', 'city', 'zip', 'state', 'contact_person', 'contact_person_no', 'branch', 'country', 'com_id') ->where('com_id', Auth::user()->company()) ->get(); diff --git a/tests/warehouseTest.php b/tests/warehouseTest.php index a2247c1..f6f683d 100644 --- a/tests/warehouseTest.php +++ b/tests/warehouseTest.php @@ -1,120 +1,82 @@ json('POST', '/api/contacts', ['ff_id' => '14']); + protected $company; + protected $user; - $response - ->assertStatus(201); -// ->assertJson( -// [ -// 'success' => true, -// 'message' => 'Success' -// //'response' => [ -// // 'id' => $contacts->ff_id, -// // ] -// ]); + public function setUp() + { + parent::setUp(); + Artisan::call('db:seed'); + + $this->user = factory(User::class)->create(); + $this->company = $this->user->each(function ($u) { + factory(Company::class)->create([ + 'user_id' => $u->id, + ]); + }); } - - public function testGet() -// { -// $response = $this->json('GET', '/api/contacts'); -// -// $response -// ->assertStatus(200); -// -// } - { - $response = $this->get('/api/contacts'); - - $response->assertStatus(200); - } - -// public function testUPdate() -// { -// -// $response = $this->json('PUT', '/api/warehouse/{war_id}' . $article->id, $payload, $headers) -// ->assertStatus(200) -// ->assertJson([ -// 'id' => 1, -// 'title' => 'Lorem', -// 'body' => 'Ipsum' -// ]); -// } - -// public function testPostWarehouse() -// { -// $response = $this->json('POST', '/api/warehouse', [ -// -// 'address'=> '2d', -// 'city'=>'cj ', -// 'zip'=>' 123', -// 'state' =>' sl', -// 'contact_person' =>'asif ', -// 'contact_person_no' =>'1212122 ', -// 'branch'=>'yap ', -// 'country' =>' ba', -// 'company_id' =>'1212 ' -// -// -// -// -// -// -// ]); -// -// $response -// ->assertStatus(201); -//// ->assertJson([ -//// 'created' => true, -// // ] -// //); -// } - - public function testPutWarehouse() - { - $response = $this->json('PUT', '/api/warehouse/6', [ - - 'address'=> '2g', - 'city'=>'cj ', - 'zip'=>' 123', - 'state' =>' sl', - 'contact_person' =>'tuytguy', - 'contact_person_no' =>'1212122 ', - 'branch'=>'yap ', - 'country' =>' ba', - 'company_id' =>'1212 ' - - - - - - + public function testPost() + { + $response = $this->actingAs($this->user) + ->postJson('/api/warehouse', [ + + 'address'=> 'Testing', + 'city'=>'Testing ', + 'zip'=>' Testing', + 'state' =>'Testing', + 'contact_person' =>'Testing ', + 'contact_person_no' =>'12345 ', + 'branch'=>'Testing ', + 'country' =>' Testing', + 'com_id' =>'99' + ]); - $response - ->assertStatus(200); -// ->assertJson([ -// -// ] -// ); + $response->assertStatus(201); + } + public function testUpdate() + { + + $response = $this->actingAs($this->user) + ->patchJson('/api/warehouse', [ + + 'address' => 'Changed Testing', + 'city' => 'Testing ', + 'zip' => ' Testing', + 'state' => 'Testing', + 'contact_person' => 'Testing ', + 'contact_person_no' => '12345 ', + 'branch' => 'Testing ', + 'country' => ' Testing', + 'com_id' => '99' + + ]); + + $response->assertStatus(201); + + } + + public function testDelete() + { + $this->actingAs($this->user) + ->json('DELETE', '/api/so/99'); + + $response->assertStatus(204); + } }