Skip to content

Commit

Permalink
CID-2744: test for GitHubScanningService
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedlajmileanix committed Jul 16, 2024
1 parent 3feb544 commit 25c722e
Showing 1 changed file with 48 additions and 0 deletions.
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()
}
}
}

0 comments on commit 25c722e

Please sign in to comment.