mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/izyim-api.git
synced 2026-08-19 04:24:01 +00:00
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:
+2
-1
@@ -1,7 +1,8 @@
|
||||
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 docker-php-ext-install pdo pdo_mysql
|
||||
RUN docker-php-ext-install gd
|
||||
WORKDIR /app
|
||||
COPY . /app
|
||||
RUN composer update
|
||||
|
||||
@@ -145,6 +145,12 @@ class AuthController extends Controller
|
||||
// attach role to user
|
||||
$user->attachRole($role);
|
||||
$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.']);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,23 +6,16 @@ use Illuminate\Http\Request;
|
||||
use App\Company;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Validator;
|
||||
use Auth;
|
||||
|
||||
class CompanyController extends Controller
|
||||
{
|
||||
public function store(Request $request)
|
||||
public function update(Request $request)
|
||||
{
|
||||
$input = $request->all();
|
||||
Company::create($input);
|
||||
return response()->json(['input'=>$input],201);
|
||||
//return redirect('/');
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$company = Company::find($id);
|
||||
$company = Company::where("user_id", Auth::user()->id)->first();
|
||||
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');
|
||||
@@ -41,9 +34,9 @@ class CompanyController extends Controller
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}//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)
|
||||
{
|
||||
return response()->json(['message'=>'company for reg_cert not found'],200);
|
||||
return response()->json(['message'=>'Company not found'], 404);
|
||||
}
|
||||
|
||||
//validating file types
|
||||
|
||||
@@ -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
@@ -26,10 +26,10 @@ Route::group(['middleware' => ['jwt.auth']], function() {
|
||||
Route::get('test', function(Request $request){
|
||||
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\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Artisan;
|
||||
use App\User;
|
||||
use App\Company;
|
||||
|
||||
class CompanyTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* A basic test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExample()
|
||||
protected $company;
|
||||
protected $user;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$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', [
|
||||
'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',
|
||||
]);
|
||||
$response->assertStatus(201);
|
||||
}
|
||||
|
||||
public function testPUT()
|
||||
{
|
||||
$response = $this->json('PUT', '/api/company/2', [
|
||||
$response = $this->actingAs($this->user)
|
||||
->patchJson('/api/company', [
|
||||
'company_name'=>'changed testing',
|
||||
'registration_no'=>'testing',
|
||||
'tax_no'=>'testing',
|
||||
@@ -52,29 +43,32 @@ class CompanyTest extends TestCase
|
||||
'state'=>'testing',
|
||||
'country'=>'testing',
|
||||
'contact_person'=>'testing',
|
||||
|
||||
]);
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
|
||||
public function testcompanyProfile()
|
||||
{
|
||||
public function testUploadCompanyProfile()
|
||||
{
|
||||
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')
|
||||
]);
|
||||
dd($response->getContent());
|
||||
// dd($response->getContent());
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
public function testregCert()
|
||||
public function testUploadRegCert()
|
||||
{
|
||||
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)
|
||||
]);
|
||||
dd($response->getContent());
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ class LoginTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExample()
|
||||
public function testLogin()
|
||||
{
|
||||
$response = $this->json('POST', '/api/login', ['phone' => '0123456789','password' => 'secret']);
|
||||
$response
|
||||
|
||||
@@ -26,7 +26,7 @@ class RegisterTest extends TestCase
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$response = $this->json('POST', '/api/verify', ['phone' => '0123456789', 'token' => '1234']);
|
||||
$response = $this->json('POST', '/api/verify-phone', ['phone' => '0123456789', 'token' => '1234']);
|
||||
$response
|
||||
->assertStatus(200)
|
||||
->assertJson([
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user