mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/izyim-api.git
synced 2026-08-19 04:24:01 +00:00
Merge branch 'master' of gitlab.com:CIEFWorldwideSdnBhd/izyim-api into asif/contact
# Conflicts: # Dockerfile # app/Company.php # app/Http/Controllers/CompanyController.php # app/Http/Kernel.php # app/User.php # composer.json # composer.lock # config/app.php # package-lock.json # routes/api.php # tests/TestCase.php
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -13,14 +13,10 @@ class LoginTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExample()
|
||||
public function testLogin()
|
||||
{
|
||||
$response = $this->json('POST', '/api/login', ['phone' => '01234567899','password' => '123']);
|
||||
|
||||
$response = $this->json('POST', '/api/login', ['phone' => '0123456789','password' => 'secret']);
|
||||
$response
|
||||
->assertStatus(201)
|
||||
->assertJson([
|
||||
'created' => true,
|
||||
]);
|
||||
->assertStatus(200);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,23 +4,61 @@ namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use App\User;
|
||||
use Artisan;
|
||||
|
||||
class RegisterTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* A basic test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRegister()
|
||||
protected $user;
|
||||
public function setUp()
|
||||
{
|
||||
$response = $this->json('POST', '/api/register', ['name' => 'Sally']);
|
||||
|
||||
$response
|
||||
->assertStatus(201)
|
||||
->assertJson([
|
||||
'created' => true,
|
||||
]);
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
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 function headers($user = null)
|
||||
@@ -15,4 +19,20 @@ abstract class TestCase extends BaseTestCase
|
||||
|
||||
return $headers;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user