Improve query findFollowsByTarget & add tests
This commit is contained in:
@@ -3,6 +3,7 @@ package integration
|
||||
import fr.dcproject.component.citizen.database.CitizenI.Name
|
||||
import fr.dcproject.component.notification.ArticleUpdateNotificationMessage
|
||||
import fr.dcproject.component.notification.NotificationMessage
|
||||
import integration.steps.given.`And follow citizen`
|
||||
import integration.steps.given.`Given I have article update notification`
|
||||
import integration.steps.given.`Given I have article`
|
||||
import integration.steps.given.`Given I have citizen`
|
||||
@@ -50,4 +51,38 @@ class `Notification routes` : BaseTest() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `I can receive article update notification when follow the creator`() {
|
||||
withIntegrationApplication {
|
||||
`Given I have citizen`("Thomas", "Pesquet", id = "1a34191a-9cde-45ba-8ac1-230138a102d3")
|
||||
`Given I have article`(id = "a06cbfb7-3094-4d64-aaa1-7486c0c292f4", createdBy = Name(firstName = "Thomas", lastName = "Pesquet"))
|
||||
`Given I have citizen`("Alan", "Bean") {
|
||||
`And follow citizen`(Name("Thomas", "Pesquet"))
|
||||
}
|
||||
`Given I have article update notification`("a06cbfb7-3094-4d64-aaa1-7486c0c292f4")
|
||||
|
||||
Thread.sleep(1000)
|
||||
|
||||
handleWebSocketConversation(
|
||||
"/notifications",
|
||||
{
|
||||
`authenticated in url as`("Alan", "Bean")
|
||||
}
|
||||
) { incoming, outgoing ->
|
||||
incoming.receive().let {
|
||||
when (it) {
|
||||
is Frame.Text -> NotificationMessage.fromString<ArticleUpdateNotificationMessage>(it.readText()).let { notif ->
|
||||
assertEquals(
|
||||
"a06cbfb7-3094-4d64-aaa1-7486c0c292f4",
|
||||
notif.target.id.toString()
|
||||
)
|
||||
outgoing.send(it)
|
||||
}
|
||||
else -> error(it.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,13 @@ fun Citizen.`And follow citizen`(
|
||||
) {
|
||||
createFollow(this, CitizenRef(citizen.toUUID()))
|
||||
}
|
||||
fun Citizen.`And follow citizen`(
|
||||
name: CitizenI.Name,
|
||||
) {
|
||||
val citizenRepository: CitizenRepository by lazy { GlobalContext.get().get() }
|
||||
val citizen = citizenRepository.findByName(name) ?: error("Citizen not exist")
|
||||
createFollow(this, CitizenRef(citizen.id))
|
||||
}
|
||||
|
||||
fun TestApplicationEngine.`Given I have follow on article`(
|
||||
firstName: String,
|
||||
@@ -41,6 +48,17 @@ fun TestApplicationEngine.`Given I have follow on article`(
|
||||
createFollow(citizen, ArticleRef(article.toUUID()))
|
||||
}
|
||||
|
||||
fun TestApplicationEngine.`Given I have follow on citizen`(
|
||||
firstName: String,
|
||||
lastName: String,
|
||||
target: CitizenI.Name,
|
||||
) {
|
||||
val citizenRepository: CitizenRepository by lazy { GlobalContext.get().get() }
|
||||
val citizen = citizenRepository.findByName(CitizenI.Name(firstName, lastName)) ?: error("Citizen not exist")
|
||||
val targetCitizen = citizenRepository.findByName(target) ?: error("Citizen not exist")
|
||||
createFollow(citizen, CitizenRef(targetCitizen.id))
|
||||
}
|
||||
|
||||
fun TestApplicationEngine.`Given I have follow on constitution`(
|
||||
firstName: String,
|
||||
lastName: String,
|
||||
|
||||
Reference in New Issue
Block a user