Skip to content

Commit d427844

Browse files
committed
add Impersonation Token test
1 parent 8ac1f5c commit d427844

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

lib/Gitlab/Api/Users.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public function email($id)
260260
*/
261261
public function userImpersonationTokens($user_id)
262262
{
263-
return $this->get('users/'.$this->encodePath($user_id).'/impersonation_tokens/');
263+
return $this->get('users/'.$this->encodePath($user_id).'/impersonation_tokens');
264264
}
265265

266266
/**

test/Gitlab/Tests/Api/UsersTest.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,77 @@ public function shouldGetSpecificUserEmail()
406406
$this->assertEquals($expectedArray, $api->email(1));
407407
}
408408

409+
/**
410+
* @test
411+
*/
412+
public function shouldGetCurrentUserImpersonationTokens()
413+
{
414+
$expectedArray = array(
415+
array('id' => 1, 'name' => 'A Name', 'revoked' => false),
416+
array('id' => 2, 'name' => 'A Name', 'revoked' => false),
417+
);
418+
419+
$api = $this->getApiMock();
420+
$api->expects($this->once())
421+
->method('get')
422+
->with('users/1/impersonation_tokens')
423+
->will($this->returnValue($expectedArray))
424+
;
425+
426+
$this->assertEquals($expectedArray, $api->userImpersonationTokens(1));
427+
}
428+
429+
/**
430+
* @test
431+
*/
432+
public function shouldGetUserImpersonationToken()
433+
{
434+
$expectedArray = array('id' => 2, 'name' => 'name');
435+
436+
$api = $this->getApiMock();
437+
$api->expects($this->once())
438+
->method('get')
439+
->with('users/1/impersonation_tokens/1')
440+
->will($this->returnValue($expectedArray))
441+
;
442+
443+
$this->assertEquals($expectedArray, $api->userImpersonationToken(1, 1));
444+
}
445+
446+
/**
447+
* @test
448+
*/
449+
public function shouldCreateImpersonationTokenForUser()
450+
{
451+
$expectedArray = array('id' => 1, 'name' => 'name');
452+
453+
$api = $this->getApiMock();
454+
$api->expects($this->once())
455+
->method('post')
456+
->with('users/1/impersonation_tokens', array('name' => 'name', 'scopes' => ['api'] ,'expires_at' => null))
457+
->will($this->returnValue($expectedArray))
458+
;
459+
460+
$this->assertEquals($expectedArray, $api->createImpersonationToken(1, 'name', ['api']));
461+
}
462+
463+
/**
464+
* @test
465+
*/
466+
public function shouldDeleteImpersonationTokenForUser()
467+
{
468+
$expectedBool = true;
469+
470+
$api = $this->getApiMock();
471+
$api->expects($this->once())
472+
->method('delete')
473+
->with('users/1/impersonation_tokens/1')
474+
->will($this->returnValue($expectedBool))
475+
;
476+
477+
$this->assertEquals($expectedBool, $api->removeImpersonationToken(1, 1));
478+
}
479+
409480
protected function getApiClass()
410481
{
411482
return 'Gitlab\Api\Users';

0 commit comments

Comments
 (0)