-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add user creation without config endpoint
- Loading branch information
Showing
4 changed files
with
96 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests\User; | ||
|
||
use App\Rules\User\VatsimCid; | ||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class CreateUser extends FormRequest | ||
{ | ||
public function rules() | ||
{ | ||
return [ | ||
'cid' => [ | ||
'required', | ||
new VatsimCid(), | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,15 @@ | |
use App\Models\Notification\Notification; | ||
use App\Models\User\Admin; | ||
use App\Models\User\User; | ||
use App\Models\User\UserStatus; | ||
use App\Providers\AuthServiceProvider; | ||
use Illuminate\Support\Carbon; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class UserControllerTest extends BaseApiTestCase | ||
{ | ||
const USER_CREATE_URI = 'user/1203532'; | ||
const USER_CREATE_NO_CONFIG_URI = 'user'; | ||
const ADMIN_LOGIN_URI = 'admin/login'; | ||
const ADMIN_EMAIL = '[email protected]'; | ||
|
||
|
@@ -29,12 +31,51 @@ public function testItConstructs() | |
} | ||
|
||
public function testItRequiresUserAdminScope() | ||
{ | ||
$this->regenerateAccessToken([], static::$tokenUser); | ||
$this->makeAuthenticatedApiRequest(self::METHOD_POST, self::USER_CREATE_NO_CONFIG_URI, ['cid' => 800001])->assertStatus(403); | ||
} | ||
|
||
public function testCreateUserReturnsCreatedOnSuccess() | ||
{ | ||
$this->makeAuthenticatedApiRequest(self::METHOD_POST, self::USER_CREATE_NO_CONFIG_URI, ['cid' => 800001])->assertStatus(201); | ||
} | ||
|
||
public function testCreateUserReturnsUnprocessableOnInvalidCid() | ||
{ | ||
$this->makeAuthenticatedApiRequest(self::METHOD_POST, self::USER_CREATE_NO_CONFIG_URI, ['cid' => 'abc'])->assertUnprocessable(); | ||
} | ||
|
||
public function testCreateUserReturnsUnprocessableOnNoCid() | ||
{ | ||
$this->makeAuthenticatedApiRequest(self::METHOD_POST, self::USER_CREATE_NO_CONFIG_URI, [])->assertUnprocessable(); | ||
} | ||
|
||
public function testCreateUserReturnsUnprocessableOnAlreadyExists() | ||
{ | ||
$this->makeAuthenticatedApiRequest(self::METHOD_POST, self::USER_CREATE_NO_CONFIG_URI, ['cid' => 800001])->assertStatus(201); | ||
$this->makeAuthenticatedApiRequest(self::METHOD_POST, self::USER_CREATE_NO_CONFIG_URI, ['cid' => 800001])->assertStatus(422); | ||
} | ||
|
||
public function testCreatesUser() | ||
{ | ||
$this->makeAuthenticatedApiRequest(self::METHOD_POST, self::USER_CREATE_NO_CONFIG_URI, ['cid' => 800001])->assertStatus(201); | ||
$this->assertDatabaseHas( | ||
'user', | ||
[ | ||
'id' => 800001, | ||
'status' => UserStatus::ACTIVE | ||
] | ||
); | ||
} | ||
|
||
public function testItRequiresUserAdminScopeWithConfig() | ||
{ | ||
$this->regenerateAccessToken([], static::$tokenUser); | ||
$this->makeAuthenticatedApiRequest(self::METHOD_POST, self::USER_CREATE_URI)->assertStatus(403); | ||
} | ||
|
||
public function testCreateUserReturnsTheCorrectJsonStructure() | ||
public function testCreateWithConfigUserReturnsTheCorrectJsonStructure() | ||
{ | ||
$this->makeAuthenticatedApiRequest(self::METHOD_POST, self::USER_CREATE_URI)->assertJsonStructure( | ||
[ | ||
|
@@ -44,12 +85,12 @@ public function testCreateUserReturnsTheCorrectJsonStructure() | |
); | ||
} | ||
|
||
public function testCreateUserReturnsCreatedOnSuccess() | ||
public function testCreateUserWithConfigReturnsCreatedOnSuccess() | ||
{ | ||
$this->makeAuthenticatedApiRequest(self::METHOD_POST, self::USER_CREATE_URI)->assertStatus(201); | ||
} | ||
|
||
public function testCreateUserReturnsUnprocessableOnAlreadyExists() | ||
public function testCreateUserWithConfigReturnsUnprocessableOnAlreadyExists() | ||
{ | ||
$this->makeAuthenticatedApiRequest(self::METHOD_POST, self::USER_CREATE_URI)->assertStatus(201); | ||
$this->makeAuthenticatedApiRequest(self::METHOD_POST, self::USER_CREATE_URI)->assertStatus(422); | ||
|