fixed the issues that were pointed out except the pdf test

This commit is contained in:
Aqeeb Imtiaz Harun
2018-05-24 12:16:37 +08:00
parent 2bf4eb2b05
commit ba827bf27d
3 changed files with 13 additions and 26 deletions
+6 -16
View File
@@ -4,7 +4,6 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Company; use App\Company;
//use Image; //only used in companyProfile(), uncomment if using that portion of the code
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Validator; use Validator;
@@ -14,7 +13,8 @@ class CompanyController extends Controller
{ {
$input = $request->all(); $input = $request->all();
Company::create($input); Company::create($input);
return redirect('/'); return response()->json(['input'=>$input],201);
//return redirect('/');
} }
public function update(Request $request, $id) public function update(Request $request, $id)
@@ -46,7 +46,7 @@ class CompanyController extends Controller
$company = Company::find($id);//find the company first $company = Company::find($id);//find the company first
if (!$company) if (!$company)
{ {
return response()->json(['message'=>'Document not found'],200); return response()->json(['message'=>'company for company_prof not found'],200);
} }
//validaating file types //validaating file types
$validator = Validator::make($request->all(), [ $validator = Validator::make($request->all(), [
@@ -54,7 +54,7 @@ class CompanyController extends Controller
]); ]);
if($validator->fails()) if($validator->fails())
{ {
return "failed"; return response()->json(['message'=>'Incorrect format'],200);
} }
if($file = $request->file('company_profile')) //company profile picture 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_profile',/*folder name*/ $file, $unique_name. '.' .$ext
); );
$company->company_profile = $unique_name. '.' .$ext; //update database $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 } //end if
$company->save(); $company->save();
return response()->json(['company'=>$company],200); return response()->json(['company'=>$company],200);
@@ -90,7 +80,7 @@ class CompanyController extends Controller
$company = Company::find($id); //find the company first $company = Company::find($id); //find the company first
if (!$company) if (!$company)
{ {
return response()->json(['message'=>'Document not found'],200); return response()->json(['message'=>'company for reg_cert not found'],200);
} }
//validating file types //validating file types
@@ -98,7 +88,7 @@ class CompanyController extends Controller
'reg_cert' => 'mimes:jpg,jpeg,bmp,png,gif,svg,pdf' 'reg_cert' => 'mimes:jpg,jpeg,bmp,png,gif,svg,pdf'
]); ]);
if($validator->fails()){ if($validator->fails()){
return "failed"; return response()->json(['message'=>'Incorrect format'],200);
} }
if($request->hasFile('reg_cert')) //Registration Certificate upload if($request->hasFile('reg_cert')) //Registration Certificate upload
+2 -4
View File
@@ -160,8 +160,7 @@ return [
App\Providers\AuthServiceProvider::class, App\Providers\AuthServiceProvider::class,
// App\Providers\BroadcastServiceProvider::class, // App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class, App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class, App\Providers\RouteServiceProvider::class
Intervention\Image\ImageServiceProvider::class
], ],
/* /*
@@ -214,8 +213,7 @@ return [
'JWTFactory' => Tymon\JWTAuth\Facades\JWTFactory::class, 'JWTFactory' => Tymon\JWTAuth\Facades\JWTFactory::class,
'Twilio' => Aloha\Twilio\Support\Laravel\Facade::class, 'Twilio' => Aloha\Twilio\Support\Laravel\Facade::class,
'Laratrust' => Laratrust\LaratrustFacade::class, 'Laratrust' => Laratrust\LaratrustFacade::class,
'auth.password.broker' => Illuminate\Auth\Passwords\TokenRepositoryInterface::class, 'auth.password.broker' => Illuminate\Auth\Passwords\TokenRepositoryInterface::class
'Image' => Intervention\Image\Facades\Image::class
], ],
]; ];
+5 -6
View File
@@ -35,13 +35,12 @@ class CompanyTest extends TestCase
'country'=>'testing', 'country'=>'testing',
'contact_person'=>'testing', 'contact_person'=>'testing',
]); ]);
var_dump($response); $response->assertStatus(201);
$response->assertStatus(302); //here 302 as the page redirects
} }
public function testPUT() public function testPUT()
{ {
$response = $this->json('PUT', '/api/company/9', [ $response = $this->json('PUT', '/api/company/2', [
'company_name'=>'changed testing', 'company_name'=>'changed testing',
'registration_no'=>'testing', 'registration_no'=>'testing',
'tax_no'=>'testing', 'tax_no'=>'testing',
@@ -61,7 +60,7 @@ class CompanyTest extends TestCase
{ {
Storage::fake('company_profile'); 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') 'company_profile' => UploadedFile::fake()->image('comp.jpg')
]); ]);
dd($response->getContent()); dd($response->getContent());
@@ -72,8 +71,8 @@ class CompanyTest extends TestCase
{ {
Storage::fake('reg_cert'); Storage::fake('reg_cert');
$response = $this->json('POST', '/api/company/reg_cert/9', [ $response = $this->json('POST', '/api/company/reg_cert/2', [
'reg_cert' => UploadedFile::fake()->image('reg.pdf') 'reg_cert' => UploadedFile::fake()->create('document.pdf')//, $sizeInKilobytes)
]); ]);
dd($response->getContent()); dd($response->getContent());
$response->assertStatus(200); $response->assertStatus(200);