Skip to content

Commit

Permalink
cid-3370: Add call to send org when a new installation happens
Browse files Browse the repository at this point in the history
  • Loading branch information
henriq-amaral-leanix committed Dec 19, 2024
1 parent 7f6cdcf commit a626071
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class GitHubScanningService(
return installations
}

private fun fetchAndSendOrganisationsData(
fun fetchAndSendOrganisationsData(
installations: List<Installation>
) {
if (installations.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class WebhookEventService(
Account(installationEventPayload.installation.account.login)
)
gitHubAuthenticationService.refreshTokens()
gitHubScanningService.fetchAndSendOrganisationsData(listOf(installation))
gitHubScanningService.fetchAndSendRepositoriesData(installation).forEach { repository ->
gitHubScanningService.fetchManifestFilesAndSend(installation, repository)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ import io.mockk.every
import io.mockk.just
import io.mockk.runs
import io.mockk.verify
import net.leanix.githubagent.client.GitHubClient
import net.leanix.githubagent.dto.ManifestFileAction
import net.leanix.githubagent.dto.ManifestFileUpdateDto
import net.leanix.githubagent.dto.Organization
import net.leanix.githubagent.shared.MANIFEST_FILE_NAME
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.ActiveProfiles
import java.util.UUID

const val UNSUPPORTED_MANIFEST_EXTENSION = "leanix.yml"

Expand All @@ -32,6 +35,9 @@ class WebhookEventServiceTest {
@MockkBean
private lateinit var gitHubAuthenticationService: GitHubAuthenticationService

@MockkBean
private lateinit var gitHubClient: GitHubClient

@Autowired
private lateinit var webhookEventService: WebhookEventService

Expand Down Expand Up @@ -338,4 +344,34 @@ class WebhookEventServiceTest {

verify(exactly = 6) { cachingService.get("runId") }
}

@Test
fun `should send the org to the backend when an new installation is created`() {
val runId = UUID.randomUUID()
every { cachingService.get("runId") } returnsMany listOf("value", null, runId)
every { cachingService.set("runId", any(), any()) } just runs
every { cachingService.remove("runId") } just runs
every { gitHubClient.getOrganizations(any()) } returns listOf(Organization("testOrganization", 1))

val eventType = "INSTALLATION"
val payload = """{
"action": "created",
"installation": {
"id": 30,
"account": {
"login": "test-org",
"id": 20
}
}
}"""

webhookEventService.consumeWebhookEvent(eventType, payload)

verify {
webSocketService.sendMessage(
"$runId/organizations",
any()
)
}
}
}

0 comments on commit a626071

Please sign in to comment.