updated docker to fix faker image error

updated on user phone verification, create a company profile
removed company store function
updated company with user relationship
added company factory
moved company routes into authenticated routes
updated company test
renamed "verify" routes to "verify-phone"
This commit is contained in:
jack
2018-05-28 17:14:09 +08:00
parent ff4e7764d5
commit c64c526d98
10 changed files with 114 additions and 78 deletions
+2 -1
View File
@@ -1,7 +1,8 @@
FROM php:7 FROM php:7
RUN apt-get update -y && apt-get install -y openssl zip unzip git netcat RUN apt-get update -y && apt-get install -y openssl zip unzip git netcat libpng-dev
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN docker-php-ext-install pdo pdo_mysql RUN docker-php-ext-install pdo pdo_mysql
RUN docker-php-ext-install gd
WORKDIR /app WORKDIR /app
COPY . /app COPY . /app
RUN composer update RUN composer update
+6
View File
@@ -145,6 +145,12 @@ class AuthController extends Controller
// attach role to user // attach role to user
$user->attachRole($role); $user->attachRole($role);
$user->update(['name' => $name, 'password' => Hash::make($password)]); $user->update(['name' => $name, 'password' => Hash::make($password)]);
// TODO : create company for user
$company = new Company;
$company->user = $user;
$company->save();
return response()->json(['success'=> true, 'message'=> 'Profile updated.']); return response()->json(['success'=> true, 'message'=> 'Profile updated.']);
} }
+9 -16
View File
@@ -6,23 +6,16 @@ use Illuminate\Http\Request;
use App\Company; use App\Company;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Validator; use Validator;
use Auth;
class CompanyController extends Controller class CompanyController extends Controller
{ {
public function store(Request $request) public function update(Request $request)
{ {
$input = $request->all(); $company = Company::where("user_id", Auth::user()->id)->first();
Company::create($input);
return response()->json(['input'=>$input],201);
//return redirect('/');
}
public function update(Request $request, $id)
{
$company = Company::find($id);
if (!$company) if (!$company)
{ {
return response()->json(['message'=>'company not found'],200); return response()->json(['message'=>'company not found'], 404);
} }
$company->company_name=$request->input('company_name'); $company->company_name=$request->input('company_name');
@@ -41,9 +34,9 @@ class CompanyController extends Controller
return response()->json(['company'=>$company],200); return response()->json(['company'=>$company],200);
} }
public function companyProfile(Request $request, $id) public function companyProfile(Request $request)
{ {
$company = Company::find($id);//find the company first $company = Company::where("user_id", Auth::user()->id)->first();
if (!$company) if (!$company)
{ {
return response()->json(['message'=>'company for company_prof not found'],200); return response()->json(['message'=>'company for company_prof not found'],200);
@@ -75,12 +68,12 @@ class CompanyController extends Controller
return response()->json(['company'=>$company],200); return response()->json(['company'=>$company],200);
}//end of companyProfile() }//end of companyProfile()
public function regCert(Request $request, $id) public function regCert(Request $request)
{ {
$company = Company::find($id); //find the company first $company = Company::where("user_id", Auth::user()->id)->first();
if (!$company) if (!$company)
{ {
return response()->json(['message'=>'company for reg_cert not found'],200); return response()->json(['message'=>'Company not found'], 404);
} }
//validating file types //validating file types
+30
View File
@@ -0,0 +1,30 @@
<?php
use Faker\Generator as Faker;
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| This directory should contain each of the model factory definitions for
| your application. Factories provide a convenient way to generate new
| model instances for testing / seeding your application's database.
|
*/
// Manually creating the relationship tree.
$factory->define(App\Company::class, function (Faker $faker) {
return [
'company_name'=>'testing',
'registration_no'=>'testing',
'tax_no'=>'testing',
'tel_no'=>'12345',
'fax'=>'12345',
'address'=>'testing',
'city'=>'testing',
'postcode'=>'testing',
'state'=>'testing',
'country'=>'testing',
'contact_person'=>'testing'
];
});
@@ -0,0 +1,31 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddUserToCompanyTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('companies', function (Blueprint $table) {
$table->unsignedInteger('user_id');
$table->foreign('user_id')->references('id')->on('users');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
+5 -5
View File
@@ -26,10 +26,10 @@ Route::group(['middleware' => ['jwt.auth']], function() {
Route::get('test', function(Request $request){ Route::get('test', function(Request $request){
return response()->json(['user'=> $request->user()]); return response()->json(['user'=> $request->user()]);
}); });
/* Company */
Route::patch('/company', 'CompanyController@update'); //update company information
Route::post('/company/company_profile/', 'CompanyController@companyProfile');//upload company profile picture
Route::post('/company/reg_cert/', 'CompanyController@regCert'); //upload registration certificaate
}); });
/* Company */
Route::post('/company', 'CompanyController@store'); //store company information
Route::put('/company/{company}', 'CompanyController@update'); //update company information
Route::post('/company/company_profile/{companyID}', 'CompanyController@companyProfile');//upload company profile picture
Route::post('/company/reg_cert/{companyID}', 'CompanyController@regCert'); //upload registration certificaate
@@ -7,40 +7,31 @@ use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile; use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Artisan;
use App\User;
use App\Company;
class CompanyTest extends TestCase class CompanyTest extends TestCase
{ {
/** protected $company;
* A basic test example. protected $user;
*
* @return void public function setUp()
*/
public function testExample()
{ {
$this->assertTrue(true); 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 testPOST() public function testUpdateCompany()
{ {
$response = $this->json('POST', '/api/company', [ $response = $this->actingAs($this->user)
'company_name'=>'testing', ->patchJson('/api/company', [
'registration_no'=>'testing',
'tax_no'=>'testing',
'tel_no'=>'12345',
'fax'=>'12345',
'address'=>'testing',
'city'=>'testing',
'postcode'=>'testing',
'state'=>'testing',
'country'=>'testing',
'contact_person'=>'testing',
]);
$response->assertStatus(201);
}
public function testPUT()
{
$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',
@@ -52,29 +43,32 @@ class CompanyTest extends TestCase
'state'=>'testing', 'state'=>'testing',
'country'=>'testing', 'country'=>'testing',
'contact_person'=>'testing', 'contact_person'=>'testing',
]); ]);
$response->assertStatus(200); $response->assertStatus(200);
} }
public function testcompanyProfile() public function testUploadCompanyProfile()
{ {
Storage::fake('company_profile'); Storage::fake('company_profile');
$response = $this->json('POST', '/api/company/company_profile/2', [ $response = $this->actingAs($this->user)
->json('POST', '/api/company/company_profile/', [
'company_profile' => UploadedFile::fake()->image('comp.jpg') 'company_profile' => UploadedFile::fake()->image('comp.jpg')
]); ]);
dd($response->getContent()); // dd($response->getContent());
$response->assertStatus(200); $response->assertStatus(200);
} }
public function testregCert() public function testUploadRegCert()
{ {
Storage::fake('reg_cert'); Storage::fake('reg_cert');
$response = $this->json('POST', '/api/company/reg_cert/2', [ $response = $this->actingAs($this->user)
->json('POST', '/api/company/reg_cert/', [
'reg_cert' => UploadedFile::fake()->create('document.pdf')//, $sizeInKilobytes) 'reg_cert' => UploadedFile::fake()->create('document.pdf')//, $sizeInKilobytes)
]); ]);
dd($response->getContent());
$response->assertStatus(200); $response->assertStatus(200);
} }
} }
+1 -1
View File
@@ -13,7 +13,7 @@ class LoginTest extends TestCase
* *
* @return void * @return void
*/ */
public function testExample() public function testLogin()
{ {
$response = $this->json('POST', '/api/login', ['phone' => '0123456789','password' => 'secret']); $response = $this->json('POST', '/api/login', ['phone' => '0123456789','password' => 'secret']);
$response $response
+1 -1
View File
@@ -26,7 +26,7 @@ class RegisterTest extends TestCase
'success' => true, 'success' => true,
]); ]);
$response = $this->json('POST', '/api/verify', ['phone' => '0123456789', 'token' => '1234']); $response = $this->json('POST', '/api/verify-phone', ['phone' => '0123456789', 'token' => '1234']);
$response $response
->assertStatus(200) ->assertStatus(200)
->assertJson([ ->assertJson([
-19
View File
@@ -1,19 +0,0 @@
<?php
namespace Tests\Unit;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testBasicTest()
{
$this->assertTrue(true);
}
}