generated from leanix/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CID-2744: test for GitHubScanningService
- Loading branch information
1 parent
3feb544
commit 25c722e
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/test/kotlin/net/leanix/githubagent/services/GitHubScanningServiceTest.kt
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,48 @@ | ||
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.dto.Account | ||
import net.leanix.githubagent.dto.Installation | ||
import net.leanix.githubagent.dto.InstallationTokenResponse | ||
import net.leanix.githubagent.dto.Organization | ||
import net.leanix.githubagent.exceptions.JwtTokenNotFound | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.assertThrows | ||
|
||
class GitHubScanningServiceTest { | ||
|
||
private val gitHubClient = mockk<GitHubClient>() | ||
private val cachingService = mockk<CachingService>() | ||
private val webSocketService = mockk<WebSocketService>(relaxUnitFun = true) | ||
private val gitHubScanningService = GitHubScanningService(gitHubClient, cachingService, webSocketService) | ||
|
||
@BeforeEach | ||
fun setup() { | ||
every { cachingService.get(any()) } returns "value" | ||
every { gitHubClient.getInstallations(any()) } returns listOf( | ||
Installation(1, Account("testInstallation")) | ||
) | ||
every { gitHubClient.createInstallationToken(1, any()) } returns | ||
InstallationTokenResponse("testToken", "2024-01-01T00:00:00Z", mapOf(), "all") | ||
every { cachingService.set(any(), any(), any()) } returns Unit | ||
every { gitHubClient.getOrganizations(any()) } returns listOf(Organization("testOrganization", 1)) | ||
} | ||
|
||
@Test | ||
fun `scanGitHubResources should send organizations over WebSocket`() { | ||
gitHubScanningService.scanGitHubResources() | ||
verify { webSocketService.sendMessage("/app/ghe/organizations", any()) } | ||
} | ||
|
||
@Test | ||
fun `scanGitHubResources should throw JwtTokenNotFound when jwtToken is expired`() { | ||
every { cachingService.get("jwtToken") } returns null | ||
assertThrows<JwtTokenNotFound> { | ||
gitHubScanningService.scanGitHubResources() | ||
} | ||
} | ||
} |