Skip to content

Commit

Permalink
CID-2774: Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedlajmileanix committed Sep 3, 2024
1 parent a37dbbf commit 1086ee6
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package net.leanix.githubagent.services

import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import net.leanix.githubagent.client.GitHubClient
import net.leanix.githubagent.config.GitHubEnterpriseProperties
import net.leanix.githubagent.exceptions.UnableToConnectToGitHubEnterpriseException
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Assertions.assertThrows
import org.junit.jupiter.api.BeforeEach
Expand Down Expand Up @@ -54,4 +56,18 @@ class GitHubAuthenticationServiceTest {

assertThrows(IllegalArgumentException::class.java) { githubAuthenticationService.generateAndCacheJwtToken() }
}

@Test
fun `generateJwtToken should send error log when throwing an exception`() {
every { cachingService.get(any()) } returns "dummy-value"
every { cachingService.set(any(), any(), any()) } returns Unit
every { githubEnterpriseProperties.pemFile } returns "valid-private-key.pem"
every { resourceLoader.getResource(any()) } returns ClassPathResource("valid-private-key.pem")
every { gitHubEnterpriseService.verifyJwt(any()) } throws UnableToConnectToGitHubEnterpriseException("")

assertThrows(UnableToConnectToGitHubEnterpriseException::class.java) {
githubAuthenticationService.generateAndCacheJwtToken()
}
verify(exactly = 1) { syncLogService.sendErrorLog("Failed to generate/validate JWT token") }
}
}

0 comments on commit 1086ee6

Please sign in to comment.