merged master

This commit is contained in:
Jack Goh
2018-06-20 11:26:23 +08:00
139 changed files with 23187 additions and 400 deletions
+74
View File
@@ -0,0 +1,74 @@
<?php
namespace Tests\Unit;
use Tests\TestCase;
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
{
protected $company;
protected $user;
public function setUp()
{
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 testUpdateCompany()
{
$response = $this->actingAs($this->user)
->patchJson('/api/company', [
'company_name'=>'changed 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(200);
}
public function testUploadCompanyProfile()
{
Storage::fake('company_profile');
$response = $this->actingAs($this->user)
->json('POST', '/api/company/company_profile/', [
'company_profile' => UploadedFile::fake()->image('comp.jpg')
]);
// dd($response->getContent());
$response->assertStatus(200);
}
public function testUploadRegCert()
{
Storage::fake('reg_cert');
$response = $this->actingAs($this->user)
->json('POST', '/api/company/reg_cert/', [
'reg_cert' => UploadedFile::fake()->create('document.pdf')//, $sizeInKilobytes)
]);
$response->assertStatus(200);
}
}
+22
View File
@@ -0,0 +1,22 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
class LoginTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testLogin()
{
$response = $this->json('POST', '/api/login', ['phone' => '0123456789','password' => 'secret']);
$response
->assertStatus(200);
}
}
+64
View File
@@ -0,0 +1,64 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use App\User;
use Artisan;
class RegisterTest extends TestCase
{
protected $user;
public function setUp()
{
parent::setUp();
Artisan::call('db:seed');
$this->user = factory(User::class)->create();
}
public function testVerification()
{
$response = $this->json('POST', '/api/send-verification', ['phone' => '0123456789']);
$response
->assertStatus(200)
->assertJson([
'success' => true,
]);
$response = $this->json('POST', '/api/verify-phone', ['phone' => '0123456789', 'token' => '1234']);
$response
->assertStatus(200)
->assertJson([
'success' => true,
]);
$token = $response->json()['token'];
}
public function testUpdateFFUser()
{
$this->actingAs($this->user)
->patchJson('/api/user', [
'freightforwarder',
'password' => 'updated',
'password_confirmation' => 'updated',
])
->assertSuccessful();
}
public function testUpdateImporterUser()
{
$this->actingAs($this->user)
->patchJson('/api/user', [
'importer',
'password' => 'updated',
'password_confirmation' => 'updated',
])
->assertSuccessful();
}
}
+20
View File
@@ -3,8 +3,28 @@
namespace Tests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Contracts\Auth\Authenticatable as UserContract;
use App\User;
abstract class TestCase extends BaseTestCase
{
use RefreshDatabase;
use CreatesApplication;
protected $user;
public function actingAs(UserContract $user, $driver = null)
{
$this->user = $user;
return $this;
}
public function call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
{
if ($this->user) {
$server['HTTP_AUTHORIZATION'] = 'Bearer ' . \JWTAuth::fromUser($this->user);
}
$server['HTTP_ACCEPT'] = 'application/json';
return parent::call($method, $uri, $parameters, $cookies, $files, $server, $content);
}
}
+84
View File
@@ -0,0 +1,84 @@
<?php
namespace Tests\Unit;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Storage;
use Artisan;
use App\User;
use App\Company;
use App\Deliveryinfo;
class DeliveryinfoTest extends TestCase
{
protected $company;
protected $user;
public function setUp()
{
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,
]);
});
}
// TODO : those test is wrong, please redo later.
// public function testCreate()
// {
// $response = $this->actingAs($this->company)
// ->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'
// ]);
// $response->assertStatus(201);
// }
// public function testPUT()
// {
// $response = $this->actingAs($this->company)
// ->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'
// ]);
// $response->assertStatus(200);
// }
// public function testDELETE()
// {
// $response = $this->json('DELETE', '/api/deliveryinfo');
// $response->assertStatus(204);
// }
}