Can vote on Comment

This commit is contained in:
2019-10-06 23:50:42 +02:00
parent 646c199292
commit d90d3117d5
6 changed files with 96 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
package feature
import fr.dcproject.entity.Citizen
import fr.dcproject.repository.CommentArticle
import io.cucumber.java8.En
import org.joda.time.DateTime
import org.koin.test.KoinTest
@@ -8,6 +9,7 @@ import org.koin.test.get
import java.util.*
import java.util.concurrent.CompletionException
import fr.dcproject.entity.Article as ArticleEntity
import fr.dcproject.entity.Comment as CommentEntity
import fr.dcproject.entity.User as UserEntity
import fr.dcproject.repository.Article as ArticleRepository
import fr.dcproject.repository.Citizen as CitizenRepository
@@ -49,5 +51,36 @@ class ArticleSteps: En, KoinTest {
)
get<ArticleRepository>().upsert(article)
}
Given("I have comment {string} on article {string}") { commentId: String, articleId: String ->
var citizen = Citizen(
name = Citizen.Name("John", "Doe"),
birthday = DateTime.now(),
user = UserEntity(username = "john-doe", plainPassword = "azerty")
)
try {
get<CitizenRepository>().insertWithUser(citizen)
} catch (e: CompletionException) {
citizen = get<CitizenRepository>().findByUsername("john-doe")!!
}
val article = ArticleEntity(
id = UUID.fromString(articleId),
title = "hello",
content = "bla bla bla",
description = "A super article",
createdBy = citizen
)
get<ArticleRepository>().upsert(article)
val comment = CommentEntity(
id = UUID.fromString(commentId),
createdBy = citizen,
target = article,
content = "hello"
)
get<CommentArticle>().comment(comment)
}
}
}

View File

@@ -36,3 +36,14 @@ Feature: vote Article
Then the response status code should be 200
And the response should contain object:
| [0].note | 1 |
Scenario: Can vote a comment on article
Given I am authenticated as John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd"
And I have comment "ea5c9e87-c99e-4646-a381-2910219e077f" on article "cc9c624e-a27e-42de-af78-ae821c657a68"
When I send a PUT request to "/articles/cc9c624e-a27e-42de-af78-ae821c657a68/comments/ea5c9e87-c99e-4646-a381-2910219e077f/vote" with body:
"""
{
"note": -1
}
"""
Then the response status code should be 201