added auto seed on dockerup

updated jwt kernel from getuserfromtoken to autenticate
updated verify response from data.token to token
updated user factory
changed routes for update user profile to from PUT to PATCH
added register with actingAs user
added test update freightforwarder user
added test update importer user
This commit is contained in:
jack
2018-05-23 11:15:38 +08:00
parent f333b68dff
commit 587234f205
7 changed files with 69 additions and 17 deletions
+38 -10
View File
@@ -4,16 +4,20 @@ 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 testSendVerification()
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
@@ -21,16 +25,40 @@ class RegisterTest extends TestCase
->assertJson([
'success' => true,
]);
}
public function testVerify()
{
$response = $this->json('POST', '/api/verify', ['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);
}
}