mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/izyim-api.git
synced 2026-08-23 14:34:02 +00:00
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:
@@ -99,8 +99,12 @@ class AuthController extends Controller
|
||||
if (!$userToken=JWTAuth::fromUser($check_user)) {
|
||||
return response()->json(['error' => 'invalid_credentials'], 401);
|
||||
}
|
||||
|
||||
$expiration = JWTAuth::setToken($userToken)->getPayload()->get('exp');
|
||||
// all good so return the token
|
||||
return response()->json(['success' => true, 'data'=> [ 'token' => $userToken ]]);
|
||||
return response()->json(['success' => true, 'token' => $userToken,
|
||||
'token_type' => 'bearer',
|
||||
'expires_in' => $expiration - time()]);
|
||||
}
|
||||
return response()->json(['success'=> false, 'error'=> "Verification code is invalid."]);
|
||||
}
|
||||
|
||||
+2
-2
@@ -59,7 +59,7 @@ class Kernel extends HttpKernel
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'jwt.auth' => 'Tymon\JWTAuth\Middleware\GetUserFromToken',
|
||||
'jwt.refresh' => 'Tymon\JWTAuth\Middleware\RefreshToken',
|
||||
'jwt.auth' => \Tymon\JWTAuth\Http\Middleware\Authenticate::class,
|
||||
'jwt.refresh' => \Tymon\JWTAuth\Middleware\RefreshToken::class,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@ use Faker\Generator as Faker;
|
||||
|
||||
$factory->define(App\User::class, function (Faker $faker) {
|
||||
return [
|
||||
'name' => $faker->name,
|
||||
'email' => $faker->unique()->safeEmail,
|
||||
'phone' => $faker->unique()->randomDigit,
|
||||
'password' => '$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm', // secret
|
||||
'remember_token' => str_random(10),
|
||||
'is_verified' => true
|
||||
];
|
||||
});
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ Route::post('verify', 'AuthController@verifyUser');
|
||||
|
||||
Route::group(['middleware' => ['jwt.auth']], function() {
|
||||
Route::get('logout', 'AuthController@logout');
|
||||
Route::put('user', 'AuthController@updateUser');
|
||||
Route::patch('user', 'AuthController@updateUser');
|
||||
Route::get('test', function(Request $request){
|
||||
return response()->json(['user'=> $request->user()]);
|
||||
});
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#!/bin/bash
|
||||
while ! nc -z db 3306; do sleep 3; done
|
||||
php artisan serve --host=0.0.0.0 --port=8000
|
||||
php artisan db:seed && php artisan serve --host=0.0.0.0 --port=8000
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user