-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Vinzenz Rosenkranz <[email protected]>
- Loading branch information
Showing
1 changed file
with
95 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -386,7 +386,8 @@ public function testPatchUserEndpoint() | |
'email' => '[email protected]', | ||
'name' => 'Admin Updated', | ||
'nickname' => 'admin1', | ||
'phonenumber' => '+43 123 1234' | ||
'phonenumber' => '+43 123 1234', | ||
'orcid' => '0000-0002-1694-233X' | ||
]); | ||
|
||
$user = User::find(1); | ||
|
@@ -405,15 +406,89 @@ public function testPatchUserEndpoint() | |
'avatar_url' => null, | ||
'metadata' => [ | ||
'phonenumber' => '+43 123 1234', | ||
'orcid' => '0000-0002-1694-233X', | ||
], | ||
]); | ||
|
||
$this->assertEquals('Admin Updated', $user->name); | ||
$this->assertEquals('admin1', $user->nickname); | ||
$this->assertEquals('[email protected]', $user->email); | ||
$this->assertEquals('+43 123 1234', $user->metadata['phonenumber']); | ||
$this->assertEquals('0000-0002-1694-233X', $user->metadata['orcid']); | ||
$this->assertNull($user->avatar); | ||
$this->assertNull($user->avatar_url); | ||
|
||
// Test update metadata | ||
$this->refreshToken($response); | ||
|
||
$response = $this->withHeaders([ | ||
'Authorization' => "Bearer $this->token" | ||
]) | ||
->patch('/api/v1/user/1', [ | ||
'orcid' => '0000-0001-5109-3700' | ||
]); | ||
|
||
$response->assertStatus(200); | ||
$user = User::find(1); | ||
$this->assertEquals('0000-0001-5109-3700', $user->metadata['orcid']); | ||
|
||
} | ||
|
||
/** | ||
* Test patching user with wrong orcid | ||
* | ||
* @return void | ||
*/ | ||
public function testPatchUserWrongOrcidEndpoint() | ||
{ | ||
$user = User::find(1); | ||
|
||
$response = $this->withHeaders([ | ||
'Authorization' => "Bearer $this->token" | ||
]) | ||
->json('patch', '/api/v1/user/1', [ | ||
'orcid' => '0000-0002-1694-2338' | ||
]); | ||
|
||
$response->assertStatus(422); | ||
} | ||
|
||
/** | ||
* Test patching user with wrong orcid | ||
* | ||
* @return void | ||
*/ | ||
public function testPatchUserAnotherWrongOrcidEndpoint() | ||
{ | ||
$user = User::find(1); | ||
|
||
$response = $this->withHeaders([ | ||
'Authorization' => "Bearer $this->token" | ||
]) | ||
->json('patch', '/api/v1/user/1', [ | ||
'orcid' => '0000-0002-1694233X' | ||
]); | ||
|
||
$response->assertStatus(422); | ||
} | ||
|
||
/** | ||
* Test patching user with wrong orcid | ||
* | ||
* @return void | ||
*/ | ||
public function testPatchUserAnotherSecondWrongOrcidEndpoint() | ||
{ | ||
$user = User::find(1); | ||
|
||
$response = $this->withHeaders([ | ||
'Authorization' => "Bearer $this->token" | ||
]) | ||
->json('patch', '/api/v1/user/1', [ | ||
'orcid' => '0000-0002-1694-23aX' | ||
]); | ||
|
||
$response->assertStatus(422); | ||
} | ||
|
||
/** | ||
|
@@ -488,7 +563,7 @@ public function testPatchRoleWithoutDataEndpoint() | |
} | ||
|
||
/** | ||
* Test deleting user (id=1). | ||
* Test deleting and restoring a user (id=1). | ||
* | ||
* @return void | ||
*/ | ||
|
@@ -513,6 +588,22 @@ public function testDeleteUserEndpoint() | |
$this->assertEquals(1, $cnt); | ||
$cnt = User::withoutTrashed()->count(); | ||
$this->assertEquals(0, $cnt); | ||
$user = User::find(1); | ||
$this->assertNotNull($user->deleted_at); | ||
|
||
|
||
// Test restore | ||
$this->refreshToken($response); | ||
|
||
$response = $this->withHeaders([ | ||
'Authorization' => "Bearer $this->token" | ||
]) | ||
->patch('/api/v1/user/restore/1'); | ||
|
||
$user = User::find(1); | ||
$this->assertNull($user->deleted_at); | ||
|
||
$response->assertStatus(204); | ||
} | ||
|
||
/** | ||
|
@@ -651,6 +742,7 @@ public function testPermissions() | |
['url' => '/role', 'error' => 'You do not have the permission to add roles', 'verb' => 'post'], | ||
['url' => '/user/1', 'error' => 'You do not have the permission to set user roles', 'verb' => 'patch'], | ||
['url' => '/role/1', 'error' => 'You do not have the permission to set role permissions', 'verb' => 'patch'], | ||
['url' => '/user/restore/1', 'error' => 'You do not have the permission to delete users', 'verb' => 'patch'], | ||
['url' => '/user/1', 'error' => 'You do not have the permission to delete users', 'verb' => 'delete'], | ||
['url' => '/role/1', 'error' => 'You do not have the permission to delete roles', 'verb' => 'delete'], | ||
['url' => '/user/1/avatar', 'error' => 'You do not have the permission to delete users', 'verb' => 'delete'], | ||
|
@@ -681,6 +773,7 @@ public function testExceptions() | |
$calls = [ | ||
['url' => '/user/99', 'error' => 'This user does not exist', 'verb' => 'patch'], | ||
['url' => '/role/99', 'error' => 'This role does not exist', 'verb' => 'patch'], | ||
['url' => '/user/restore/99', 'error' => 'This user does not exist', 'verb' => 'patch'], | ||
]; | ||
|
||
foreach($calls as $c) { | ||
|