Skip to content

Commit

Permalink
add unit test for delete token
Browse files Browse the repository at this point in the history
Signed-off-by: Swikriti Tripathi <swikriti808@gmail.com>
  • Loading branch information
SwikritiT committed Aug 15, 2023
1 parent 34bb4e5 commit bb7f8f7
Showing 1 changed file with 54 additions and 4 deletions.
58 changes: 54 additions & 4 deletions tests/lib/Service/OpenProjectAPIServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1765,19 +1765,19 @@ public function testProjectFolderHasMultipleAppPassword(): void {
$tokenMock1 = $this->getMockBuilder(IToken::class)->getMock();
$tokenMock1
->method('getName')
->willReturnOnConsecutiveCalls('session');
->willReturn('session');
$tokenMock2 = $this->getMockBuilder(IToken::class)->getMock();
$tokenMock2
->method('getName')
->willReturnOnConsecutiveCalls('test');
->willReturn('test');
$tokenMock3 = $this->getMockBuilder(IToken::class)->getMock();
$tokenMock3
->method('getName')
->willReturnOnConsecutiveCalls('new-token');
->willReturn('new-token');
$tokenMock4 = $this->getMockBuilder(IToken::class)->getMock();
$tokenMock4
->method('getName')
->willReturnOnConsecutiveCalls('OpenProject');
->willReturn('OpenProject');
$tokenProviderMock
->method('getTokenByUser')
->with(Application::OPEN_PROJECT_ENTITIES_NAME)
Expand All @@ -1801,6 +1801,56 @@ public function testProjectFolderHasAppPasswordNegativeCondition(): void {
$this->assertFalse($service->hasAppPassword());
}

public function testProjectFolderDeleteAppPassword(): void {
$tokenProviderMock = $this->getMockBuilder(IProvider::class)->disableOriginalConstructor()
->getMock();
$tokenMock1 = $this->getMockBuilder(IToken::class)->getMock();
$tokenMock1
->method('getName')
->willReturn('session');
$tokenMock1
->method('getId')
->willReturn(1);
$tokenMock2 = $this->getMockBuilder(IToken::class)->getMock();
$tokenMock2
->method('getName')
->willReturn('test');
$tokenMock2
->method('getId')
->willReturn(2);
$tokenMock3 = $this->getMockBuilder(IToken::class)->getMock();
$tokenMock3
->method('getName')
->willReturn('new-token');
$tokenMock3
->method('getId')
->willReturn(3);
$tokenMock4 = $this->getMockBuilder(IToken::class)->getMock();
$tokenMock4
->method('getName')
->willReturn('OpenProject');
$tokenMock4
->method('getId')
->willReturn(4);
$tokenMock5 = $this->getMockBuilder(IToken::class)->getMock();
$tokenMock5
->method('getName')
->willReturn('OpenProject');
$tokenMock5
->method('getId')
->willReturn(5);
$tokenProviderMock
->method('getTokenByUser')
->with(Application::OPEN_PROJECT_ENTITIES_NAME)
->willReturn([$tokenMock1,$tokenMock2,$tokenMock3,$tokenMock4,$tokenMock5]);
$service = $this->getServiceMock(['hasAppPassword'], null, null, null, null, null, null, null, null, $tokenProviderMock);
$service->method('hasAppPassword')->willReturn(true);
$tokenProviderMock->expects($this->exactly(2))
->method('invalidateTokenById')
->withConsecutive([Application::OPEN_PROJECT_ENTITIES_NAME, 4], [Application::OPEN_PROJECT_ENTITIES_NAME, 5]);
$service->deleteAppPassword();
}

public function testLinkWorkPackageToFilePact(): void {
$consumerRequest = new ConsumerRequest();
$consumerRequest
Expand Down

0 comments on commit bb7f8f7

Please sign in to comment.