From ba827bf27d847c2e91f523ccfbcda693f38a45b6 Mon Sep 17 00:00:00 2001 From: Aqeeb Imtiaz Harun Date: Thu, 24 May 2018 12:16:37 +0800 Subject: [PATCH] fixed the issues that were pointed out except the pdf test --- app/Http/Controllers/CompanyController.php | 22 ++++++---------------- config/app.php | 6 ++---- tests/Unit/CompanyTest.php | 11 +++++------ 3 files changed, 13 insertions(+), 26 deletions(-) diff --git a/app/Http/Controllers/CompanyController.php b/app/Http/Controllers/CompanyController.php index 6bc912c..aba4fdc 100644 --- a/app/Http/Controllers/CompanyController.php +++ b/app/Http/Controllers/CompanyController.php @@ -4,7 +4,6 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Company; -//use Image; //only used in companyProfile(), uncomment if using that portion of the code use Illuminate\Support\Facades\Storage; use Validator; @@ -14,7 +13,8 @@ class CompanyController extends Controller { $input = $request->all(); Company::create($input); - return redirect('/'); + return response()->json(['input'=>$input],201); + //return redirect('/'); } public function update(Request $request, $id) @@ -46,7 +46,7 @@ class CompanyController extends Controller $company = Company::find($id);//find the company first if (!$company) { - return response()->json(['message'=>'Document not found'],200); + return response()->json(['message'=>'company for company_prof not found'],200); } //validaating file types $validator = Validator::make($request->all(), [ @@ -54,7 +54,7 @@ class CompanyController extends Controller ]); if($validator->fails()) { - return "failed"; + return response()->json(['message'=>'Incorrect format'],200); } if($file = $request->file('company_profile')) //company profile picture @@ -70,16 +70,6 @@ class CompanyController extends Controller 'company_profile',/*folder name*/ $file, $unique_name. '.' .$ext ); $company->company_profile = $unique_name. '.' .$ext; //update database - // only use the following section of the code if you're omiting the upper portion, also uncomment the Image Library on line 7 & install Intervention Image package - /* - $name = $file->getClientOriginalName(); - $img_file = $request->file('company_profile'); - Image::make($img_file)->resize(300,300)->save(public_path('\company_profile')); - //return $img_file; - // $file->move('uploads/company_profile/', $img_file); - - $input['company_profile'] = $name; - */ } //end if $company->save(); return response()->json(['company'=>$company],200); @@ -90,7 +80,7 @@ class CompanyController extends Controller $company = Company::find($id); //find the company first if (!$company) { - return response()->json(['message'=>'Document not found'],200); + return response()->json(['message'=>'company for reg_cert not found'],200); } //validating file types @@ -98,7 +88,7 @@ class CompanyController extends Controller 'reg_cert' => 'mimes:jpg,jpeg,bmp,png,gif,svg,pdf' ]); if($validator->fails()){ - return "failed"; + return response()->json(['message'=>'Incorrect format'],200); } if($request->hasFile('reg_cert')) //Registration Certificate upload diff --git a/config/app.php b/config/app.php index e5d8c3d..9a8e5b8 100644 --- a/config/app.php +++ b/config/app.php @@ -160,8 +160,7 @@ return [ App\Providers\AuthServiceProvider::class, // App\Providers\BroadcastServiceProvider::class, App\Providers\EventServiceProvider::class, - App\Providers\RouteServiceProvider::class, - Intervention\Image\ImageServiceProvider::class + App\Providers\RouteServiceProvider::class ], /* @@ -214,8 +213,7 @@ return [ 'JWTFactory' => Tymon\JWTAuth\Facades\JWTFactory::class, 'Twilio' => Aloha\Twilio\Support\Laravel\Facade::class, 'Laratrust' => Laratrust\LaratrustFacade::class, - 'auth.password.broker' => Illuminate\Auth\Passwords\TokenRepositoryInterface::class, - 'Image' => Intervention\Image\Facades\Image::class + 'auth.password.broker' => Illuminate\Auth\Passwords\TokenRepositoryInterface::class ], ]; diff --git a/tests/Unit/CompanyTest.php b/tests/Unit/CompanyTest.php index 0e8fb7e..89f4249 100644 --- a/tests/Unit/CompanyTest.php +++ b/tests/Unit/CompanyTest.php @@ -35,13 +35,12 @@ class CompanyTest extends TestCase 'country'=>'testing', 'contact_person'=>'testing', ]); - var_dump($response); - $response->assertStatus(302); //here 302 as the page redirects + $response->assertStatus(201); } public function testPUT() { - $response = $this->json('PUT', '/api/company/9', [ + $response = $this->json('PUT', '/api/company/2', [ 'company_name'=>'changed testing', 'registration_no'=>'testing', 'tax_no'=>'testing', @@ -61,7 +60,7 @@ class CompanyTest extends TestCase { Storage::fake('company_profile'); - $response = $this->json('POST', '/api/company/company_profile/9', [ + $response = $this->json('POST', '/api/company/company_profile/2', [ 'company_profile' => UploadedFile::fake()->image('comp.jpg') ]); dd($response->getContent()); @@ -72,8 +71,8 @@ class CompanyTest extends TestCase { Storage::fake('reg_cert'); - $response = $this->json('POST', '/api/company/reg_cert/9', [ - 'reg_cert' => UploadedFile::fake()->image('reg.pdf') + $response = $this->json('POST', '/api/company/reg_cert/2', [ + 'reg_cert' => UploadedFile::fake()->create('document.pdf')//, $sizeInKilobytes) ]); dd($response->getContent()); $response->assertStatus(200);