@@ -5,14 +5,17 @@ import io.mockk.every
55import io.mockk.just
66import io.mockk.runs
77import io.mockk.verify
8+ import net.leanix.githubagent.client.GitHubClient
89import net.leanix.githubagent.dto.ManifestFileAction
910import net.leanix.githubagent.dto.ManifestFileUpdateDto
11+ import net.leanix.githubagent.dto.Organization
1012import net.leanix.githubagent.shared.MANIFEST_FILE_NAME
1113import org.junit.jupiter.api.BeforeEach
1214import org.junit.jupiter.api.Test
1315import org.springframework.beans.factory.annotation.Autowired
1416import org.springframework.boot.test.context.SpringBootTest
1517import org.springframework.test.context.ActiveProfiles
18+ import java.util.UUID
1619
1720const val UNSUPPORTED_MANIFEST_EXTENSION = " leanix.yml"
1821
@@ -32,6 +35,9 @@ class WebhookEventServiceTest {
3235 @MockkBean
3336 private lateinit var gitHubAuthenticationService: GitHubAuthenticationService
3437
38+ @MockkBean
39+ private lateinit var gitHubClient: GitHubClient
40+
3541 @Autowired
3642 private lateinit var webhookEventService: WebhookEventService
3743
@@ -358,4 +364,34 @@ class WebhookEventServiceTest {
358364 webSocketService.sendMessage(any(), any())
359365 }
360366 }
367+
368+ @Test
369+ fun `should send the org to the backend when an new installation is created` () {
370+ val runId = UUID .randomUUID()
371+ every { cachingService.get(" runId" ) } returnsMany listOf (" value" , null , runId)
372+ every { cachingService.set(" runId" , any(), any()) } just runs
373+ every { cachingService.remove(" runId" ) } just runs
374+ every { gitHubClient.getOrganizations(any()) } returns listOf (Organization (" testOrganization" , 1 ))
375+
376+ val eventType = " INSTALLATION"
377+ val payload = """ {
378+ "action": "created",
379+ "installation": {
380+ "id": 30,
381+ "account": {
382+ "login": "test-org",
383+ "id": 20
384+ }
385+ }
386+ }"""
387+
388+ webhookEventService.consumeWebhookEvent(eventType, payload)
389+
390+ verify {
391+ webSocketService.sendMessage(
392+ " $runId /organizations" ,
393+ any()
394+ )
395+ }
396+ }
361397}
0 commit comments