diff --git a/src/main/kotlin/net/leanix/githubagent/services/GitHubScanningService.kt b/src/main/kotlin/net/leanix/githubagent/services/GitHubScanningService.kt index 2f86686..34ede51 100644 --- a/src/main/kotlin/net/leanix/githubagent/services/GitHubScanningService.kt +++ b/src/main/kotlin/net/leanix/githubagent/services/GitHubScanningService.kt @@ -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() { @@ -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) { @@ -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++ diff --git a/src/test/kotlin/net/leanix/githubagent/services/GitHubScanningServiceTest.kt b/src/test/kotlin/net/leanix/githubagent/services/GitHubScanningServiceTest.kt index 7f8751e..4d757d6 100644 --- a/src/test/kotlin/net/leanix/githubagent/services/GitHubScanningServiceTest.kt +++ b/src/test/kotlin/net/leanix/githubagent/services/GitHubScanningServiceTest.kt @@ -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 @@ -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()) } + } }