Skip to content

Commit

Permalink
CID-2744: add test for getting ghe repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedlajmileanix committed Jul 23, 2024
1 parent 99bfb85 commit 927ec58
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class GitHubScanningService(
private val webSocketService: WebSocketService,
private val gitHubGraphQLService: GitHubGraphQLService
) {
companion object {
const val WS_ORGANIZATIONS_TOPIC = "/app/ghe/organizations"
const val WS_REPOSITORIES_TOPIC = "/app/ghe/repositories"
}
private val logger = LoggerFactory.getLogger(GitHubScanningService::class.java)

fun scanGitHubResources() {
Expand Down Expand Up @@ -60,7 +64,7 @@ class GitHubScanningService(
OrganizationDto(organization.id, organization.nodeId, organization.login, false)
}
}
webSocketService.sendMessage("/app/ghe/organizations", organizations)
webSocketService.sendMessage(WS_ORGANIZATIONS_TOPIC, organizations)
}

private fun fetchAndBroadcastRepositoriesData(installation: Installation) {
Expand All @@ -73,7 +77,7 @@ class GitHubScanningService(
token = installationToken,
cursor = cursor
)
webSocketService.sendMessage("/app/ghe/repositories", repositoriesPage.repositories)
webSocketService.sendMessage(WS_REPOSITORIES_TOPIC, repositoriesPage.repositories)
cursor = repositoriesPage.cursor
totalRepos += repositoriesPage.repositories.size
page++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import net.leanix.githubagent.dto.Installation
import net.leanix.githubagent.dto.InstallationTokenResponse
import net.leanix.githubagent.dto.Organization
import net.leanix.githubagent.dto.PagedRepositories
import net.leanix.githubagent.dto.RepositoryDto
import net.leanix.githubagent.dto.RepositoryOrganizationDto
import net.leanix.githubagent.exceptions.JwtTokenNotFound
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -57,4 +59,26 @@ class GitHubScanningServiceTest {
gitHubScanningService.scanGitHubResources()
}
}

@Test
fun `scanGitHubResources should send repositories over WebSocket`() {
every { gitHubGraphQLService.getRepositories(any(), any()) } returns PagedRepositories(
repositories = listOf(
RepositoryDto(
id = "repo1",
name = "TestRepo",
description = "A test repository",
url = "https://github.com/testRepo",
organization = RepositoryOrganizationDto(id = "org1", name = "TestOrg"),
languages = listOf("Kotlin", "Java"),
topics = listOf("test", "example"),
manifest = "dependencies { implementation 'com.example:example-lib:1.0.0' }"
)
),
hasNextPage = false,
cursor = null
)
gitHubScanningService.scanGitHubResources()
verify { webSocketService.sendMessage(eq("/app/ghe/repositories"), any()) }
}
}

0 comments on commit 927ec58

Please sign in to comment.