@@ -59,6 +59,7 @@ class ArtifactDownloadHandlerTest {
5959 every { gitHubClient.downloadArtifact(any(), any(), any(), any()) } returns Response
6060 .builder()
6161 .request(request)
62+ .status(200 )
6263 .body(readSbomFile()).build()
6364
6465 // when
@@ -104,7 +105,9 @@ class ArtifactDownloadHandlerTest {
104105 every { gitHubClient.downloadArtifact(any(), any(), any(), any()) } returns Response
105106 .builder()
106107 .request(request)
107- .body(readSbomFile()).build()
108+ .body(readSbomFile())
109+ .status(200 )
110+ .build()
108111
109112 // when
110113 artifactDownloadHandler.handleFrame(
@@ -122,6 +125,52 @@ class ArtifactDownloadHandlerTest {
122125 webSocketService.sendMessage(" /artifact" , any())
123126 }
124127 }
128+
129+ @Test
130+ fun `it should receive message from server and not send empty artifact` () {
131+ // given
132+ every { gitHubAuthenticationService.getInstallationToken(any()) } returns " token"
133+ every { gitHubClient.getRunArtifacts(any(), any(), any(), any()) } returns ArtifactsListResponse (
134+ totalCount = 2 ,
135+ artifacts = listOf (
136+ Artifact (
137+ id = 1 ,
138+ name = " leanix-sbom-test-sbom" ,
139+ url = " http://download.url" ,
140+ archiveDownloadUrl = " http://download.url"
141+ ),
142+ Artifact (
143+ id = 2 ,
144+ name = " invalid-name" ,
145+ url = " http://download.url" ,
146+ archiveDownloadUrl = " http://download.url"
147+ )
148+ )
149+ )
150+ val request = mockk<Request >()
151+ every { gitHubClient.downloadArtifact(any(), any(), any(), any()) } returns Response
152+ .builder()
153+ .request(request)
154+ .status(404 )
155+ .build()
156+
157+ // when
158+ artifactDownloadHandler.handleFrame(
159+ StompHeaders (),
160+ ArtifactDownloadDTO (
161+ repositoryName = " repository" ,
162+ repositoryOwner = " leanix" ,
163+ runId = 1 ,
164+ installationId = 1 ,
165+ )
166+ )
167+
168+ // then
169+ verify(exactly = 0 ) {
170+ webSocketService.sendMessage(" /artifact" , any())
171+ }
172+ }
173+
125174 private fun readSbomFile (): ByteArray {
126175 val filePath = Paths .get(" src/test/resources/sbom/leanix-sbom-test-sbom.zip" )
127176 return Files .readAllBytes(filePath)
0 commit comments