redo deli info testing

This commit is contained in:
Zain Fauzan Rofie Azizi
2018-06-25 16:43:19 +08:00
parent 48e033f436
commit 0a93a6b9fe
5 changed files with 79 additions and 59 deletions
@@ -4,6 +4,8 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Deliveryinfo;
use App\User;
use App\Company;
use Auth;
class DeliveryinfoController extends Controller
@@ -11,6 +13,11 @@ class DeliveryinfoController extends Controller
public function index()
{
$deliveryinfo = Deliveryinfo::where('com_id', Auth::user()->company())->get();
if (!$deliveryinfo)
{
return response()->json(['message'=>'Access Denied!'], 404);
}
return response()->json($deliveryinfo, 200);
}
@@ -23,7 +30,18 @@ class DeliveryinfoController extends Controller
*/
public function show(Deliveryinfo $id)
{
$deliveryinfo = Deliveryinfo::where('com_id', Auth::user()->company())->where('id', $id)->firstOrFail();
$deliveryinfo = Deliveryinfo::where('com_id', Auth::user()->company())->where('id', $id)->first();
if (!$deliveryinfo)
{
return response()->json(['message'=>'Access Denied!'], 404);
}
$deliveryinfos = DB::table('deliveryinfos')
->select('id', 'branch', 'deli_info', 'address', 'city', 'postcode', 'state', 'country', 'contact_person', 'contact_person_no', 'com_id')
->where('com_id', Auth::user()->company())
->get();
return response()->json($deliveryinfo, 200);
}
+17 -17
View File
@@ -23,7 +23,7 @@ class WarehouseController extends Controller
return response()->json(['message'=>'Access Denied!'], 404);
}
$warehouse = Warehouse::all();
//$warehouse = Warehouse::all();
return response()->json($warehouses, 200);
@@ -64,14 +64,14 @@ class WarehouseController extends Controller
$user = Auth::user();
$warehouse = new Warehouse;
$warehouse->address=$request->input('address');
$warehouse->city=$request->input('city');
$warehouse->zip=$request->input('zip');
$warehouse->state=$request->input('state');
$warehouse->contact_person=$request->input('contact_person');
$warehouse->contact_person_no=$request->input('contact_person_no');
$warehouse->branch=$request->input('branch');
$warehouse->country=$request->input('country');
$warehouse->address = $request->input('address');
$warehouse->city = $request->input('city');
$warehouse->zip = $request->input('zip');
$warehouse->state = $request->input('state');
$warehouse->contact_person = $request->input('contact_person');
$warehouse->contact_person_no = $request->input('contact_person_no');
$warehouse->branch = $request->input('branch');
$warehouse->country = $request->input('country');
$warehouse->com_id = $user->company();
$warehouse->save();
@@ -96,14 +96,14 @@ class WarehouseController extends Controller
return response()->json(['message'=>'Access Denied!'], 404);
}
$warehouse->address=$request->input('address');
$warehouse->city=$request->input('city');
$warehouse->zip=$request->input('zip');
$warehouse->state=$request->input('state');
$warehouse->contact_person=$request->input('contact_person');
$warehouse->contact_person_no=$request->input('contact_person_no');
$warehouse->branch=$request->input('branch');
$warehouse->country=$request->input('country');
$warehouse->address = $request->input('address');
$warehouse->city = $request->input('city');
$warehouse->zip = $request->input('zip');
$warehouse->state = $request->input('state');
$warehouse->contact_person = $request->input('contact_person');
$warehouse->contact_person_no = $request->input('contact_person_no');
$warehouse->branch = $request->input('branch');
$warehouse->country = $request->input('country');
$warehouse->com_id = $user->company();
$warehouse->save();
+1 -1
View File
@@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model;
class Warehouse extends Model
{
protected $fillable = ['city', 'address','zip','state','contact_person','contact_person_no','branch','country','comp_id'];
protected $fillable = ['city', 'address','zip','state','contact_person','contact_person_no','branch','country','com_id'];
public function contact(){
+1 -1
View File
@@ -56,7 +56,7 @@ Route::group(['middleware' => ['jwt.auth']], function() {
});
/*Delivery-Info in profile menu*/
Route::get('/deliveryinfo','DeliveryinfoController@index');
Route::get('/deliveryinfo/{com_id}','DeliveryinfoController@index');
Route::get('/deliveryinfo/{com_id}','DeliveryinfoController@show');
Route::post('/deliveryinfo', 'DeliveryinfoController@store');
Route::put('/deliveryinfo/{com_id}', 'DeliveryinfoController@update');
+41 -39
View File
@@ -20,6 +20,7 @@ class DeliveryinfoTest extends TestCase
{
parent::setUp();
Artisan::call('db:seed');
$this->user = factory(User::class)->create();
$this->company = $this->user->each(function ($u) {
factory(Company::class)->create([
@@ -28,57 +29,58 @@ class DeliveryinfoTest extends TestCase
});
}
// TODO : those test is wrong, please redo later.
// TODO : those test is wrong, please redo later.
// REDO the test
// public function testCreate()
// {
public function testPost()
{
// $response = $this->actingAs($this->company)
// ->patchJson('/api/deliveryinfo', [
$response = $this->actingAs($this->user)
->postJson('/api/deliveryinfo', [
// 'branch' => 'Test',
// 'deli_info' => 'Testing',
// 'address' => 'Testing',
// 'city' => 'Test',
// 'postcode' => '12345',
// 'state' => 'Testing',
// 'country' => 'Testing',
// 'contact_person' => 'Testing',
// 'contact_person_no' => '12345'
// ]);
'branch' => 'Testing',
'deli_info' => 'Testing',
'address' => 'Testing',
'city' => 'Testing',
'postcode' => '12345',
'state' => 'Testing',
'country' => 'Testing',
'contact_person' => 'Testing',
'contact_person_no' => '12345'
]);
// $response->assertStatus(201);
// }
$response->assertStatus(201);
}
// public function testPUT()
// {
public function testPut()
{
// $response = $this->actingAs($this->company)
// ->patchJson('/api/deliveryinfo', [
$response = $this->actingAs($this->user)
->patchJson('/api/deliveryinfo', [
// 'branch' => 'Test',
// 'deli_info' => 'Testing',
// 'address' => 'Testing',
// 'city' => 'Test',
// 'postcode' => '12345',
// 'state' => 'Testing',
// 'country' => 'Testing',
// 'contact_person' => 'Testing',
// 'contact_person_no' => '12345'
'branch' => 'ChangedTesting',
'deli_info' => 'Testing',
'address' => 'Testing',
'city' => 'Testing',
'postcode' => '12345',
'state' => 'Testing',
'country' => 'Testing',
'contact_person' => 'Testing',
'contact_person_no' => '12345'
// ]);
]);
// $response->assertStatus(200);
// }
$response->assertStatus(200);
}
// public function testDELETE()
// {
// $response = $this->json('DELETE', '/api/deliveryinfo');
public function testDELETE()
{
$response = $this->json('DELETE', '/api/deliveryinfo');
// $response->assertStatus(204);
// }
$response->assertStatus(204);
}
}