-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from craigatk/info-message
(feature) Can display messages on test report dashboard
- Loading branch information
Showing
20 changed files
with
400 additions
and
115 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
server/server-api/src/main/kotlin/projektor/server/api/messages/Messages.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package projektor.server.api.messages | ||
|
||
data class Messages(val messages: List<String>) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
server/server-app/src/main/kotlin/projektor/message/MessageConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package projektor.message | ||
|
||
import io.ktor.config.ApplicationConfig | ||
import io.ktor.util.KtorExperimentalAPI | ||
|
||
@KtorExperimentalAPI | ||
data class MessageConfig(val globalMessages: List<String>) { | ||
|
||
companion object { | ||
fun createMessageConfig(applicationConfig: ApplicationConfig): MessageConfig { | ||
val messageString = applicationConfig.propertyOrNull("ktor.message.global")?.getString() | ||
val messages = messageString?.let { it.split("|") } ?: listOf() | ||
|
||
return MessageConfig(messages) | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
server/server-app/src/main/kotlin/projektor/message/MessageService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package projektor.message | ||
|
||
import io.ktor.util.KtorExperimentalAPI | ||
import projektor.server.api.PublicId | ||
import projektor.server.api.messages.Messages | ||
|
||
@KtorExperimentalAPI | ||
class MessageService(private val messageConfig: MessageConfig) { | ||
|
||
fun getTestRunMessages(publicId: PublicId): Messages { | ||
return Messages(messageConfig.globalMessages) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
server/server-app/src/main/kotlin/projektor/route/MessageRoutes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package projektor.route | ||
|
||
import io.ktor.application.call | ||
import io.ktor.http.HttpStatusCode | ||
import io.ktor.response.respond | ||
import io.ktor.routing.Route | ||
import io.ktor.routing.get | ||
import io.ktor.util.KtorExperimentalAPI | ||
import io.ktor.util.getOrFail | ||
import projektor.message.MessageService | ||
import projektor.server.api.PublicId | ||
|
||
@KtorExperimentalAPI | ||
fun Route.messages(messageService: MessageService) { | ||
get("/run/{publicId}/messages") { | ||
val publicId = call.parameters.getOrFail("publicId") | ||
|
||
call.respond(HttpStatusCode.OK, messageService.getTestRunMessages(PublicId(publicId))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,4 +49,8 @@ ktor { | |
environment = ${?METRICS_INFLUXDB_ENV} | ||
} | ||
} | ||
|
||
message { | ||
global = ${?GLOBAL_MESSAGES} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
server/server-app/src/test/kotlin/projektor/message/MessageApplicationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package projektor.message | ||
|
||
import io.ktor.http.HttpMethod | ||
import io.ktor.http.HttpStatusCode | ||
import io.ktor.server.testing.handleRequest | ||
import io.ktor.server.testing.withTestApplication | ||
import io.ktor.util.KtorExperimentalAPI | ||
import kotlin.test.assertNotNull | ||
import org.junit.jupiter.api.Test | ||
import projektor.ApplicationTestCase | ||
import projektor.incomingresults.randomPublicId | ||
import projektor.server.api.messages.Messages | ||
import strikt.api.expectThat | ||
import strikt.assertions.contains | ||
import strikt.assertions.hasSize | ||
import strikt.assertions.isEqualTo | ||
|
||
@KtorExperimentalAPI | ||
class MessageApplicationTest : ApplicationTestCase() { | ||
|
||
@Test | ||
fun `when single global message should return it`() { | ||
val publicId = randomPublicId() | ||
|
||
globalMessages = "Here is a global message" | ||
|
||
withTestApplication(::createTestApplication) { | ||
handleRequest(HttpMethod.Get, "/run/$publicId/messages") | ||
.apply { | ||
expectThat(response.status()).isEqualTo(HttpStatusCode.OK) | ||
|
||
val messagesResponse = objectMapper.readValue(response.content, Messages::class.java) | ||
assertNotNull(messagesResponse) | ||
|
||
expectThat(messagesResponse.messages) | ||
.hasSize(1) | ||
.contains("Here is a global message") | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun `when two global messages should return them`() { | ||
val publicId = randomPublicId() | ||
|
||
globalMessages = "First global message|Second global message" | ||
|
||
withTestApplication(::createTestApplication) { | ||
handleRequest(HttpMethod.Get, "/run/$publicId/messages") | ||
.apply { | ||
expectThat(response.status()).isEqualTo(HttpStatusCode.OK) | ||
|
||
val messagesResponse = objectMapper.readValue(response.content, Messages::class.java) | ||
assertNotNull(messagesResponse) | ||
|
||
expectThat(messagesResponse.messages) | ||
.hasSize(2) | ||
.contains("First global message") | ||
.contains("Second global message") | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun `when no messages should return empty list`() { | ||
val publicId = randomPublicId() | ||
|
||
globalMessages = null | ||
|
||
withTestApplication(::createTestApplication) { | ||
handleRequest(HttpMethod.Get, "/run/$publicId/messages") | ||
.apply { | ||
expectThat(response.status()).isEqualTo(HttpStatusCode.OK) | ||
|
||
val messagesResponse = objectMapper.readValue(response.content, Messages::class.java) | ||
assertNotNull(messagesResponse) | ||
|
||
expectThat(messagesResponse.messages) | ||
.hasSize(0) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "messages": [] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "messages": ["Here is one message"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/// <reference types="Cypress" /> | ||
|
||
context("test run messages", () => { | ||
it("when one messages should show it on dashboard page", () => { | ||
const publicId = "12345"; | ||
|
||
cy.server(); | ||
|
||
cy.route( | ||
"GET", | ||
`run/${publicId}/summary`, | ||
"fixture:one_passing/test_run_summary.json" | ||
); | ||
cy.route("GET", `run/${publicId}`, "fixture:one_passing/test_run.json"); | ||
|
||
cy.route( | ||
"GET", | ||
`run/${publicId}/messages`, | ||
"fixture:messages/one_message.json" | ||
); | ||
|
||
cy.visit(`http://localhost:1234/tests/${publicId}`); | ||
|
||
cy.getByTestId("test-run-message-1").should( | ||
"contain", | ||
"Here is one message" | ||
); | ||
}); | ||
|
||
it("when no messages should not display any dashboard page", () => { | ||
const publicId = "12345"; | ||
|
||
cy.server(); | ||
|
||
cy.route( | ||
"GET", | ||
`run/${publicId}/summary`, | ||
"fixture:one_passing/test_run_summary.json" | ||
); | ||
cy.route("GET", `run/${publicId}`, "fixture:one_passing/test_run.json"); | ||
|
||
cy.route( | ||
"GET", | ||
`run/${publicId}/messages`, | ||
"fixture:messages/no_messages.json" | ||
); | ||
|
||
cy.visit(`http://localhost:1234/tests/${publicId}`); | ||
|
||
cy.testIdShouldExist("test-run-messages"); | ||
|
||
cy.testIdShouldNotExist("test-run-message-1"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.