-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinishDayRestApiTest.kt
More file actions
78 lines (71 loc) · 2.71 KB
/
FinishDayRestApiTest.kt
File metadata and controls
78 lines (71 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.dddheroes.heroesofddd.calendar.write.finishday
import com.dddheroes.extensions.webmvc.test.RestAssuredMockMvcTest
import com.dddheroes.heroesofddd.shared.domain.identifiers.GameId
import com.dddheroes.heroesofddd.shared.domain.identifiers.PlayerId
import com.dddheroes.heroesofddd.shared.restapi.Headers
import com.dddheroes.sdk.application.CommandHandlerResult.Failure
import com.dddheroes.sdk.application.CommandHandlerResult.Success
import io.restassured.http.ContentType
import io.restassured.module.mockmvc.kotlin.extensions.Given
import io.restassured.module.mockmvc.kotlin.extensions.Then
import io.restassured.module.mockmvc.kotlin.extensions.When
import org.axonframework.extensions.spring.test.AxonGatewaysMock
import org.axonframework.extensions.spring.test.AxonGatewaysMockTest
import org.hamcrest.Matchers.equalTo
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.HttpStatus
import org.springframework.test.context.TestPropertySource
@RestAssuredMockMvcTest
@AxonGatewaysMockTest
@TestPropertySource(properties = ["slices.calendar.write.finishday.enabled=true"])
internal class FinishDayRestApiTest @Autowired constructor(val gateways: AxonGatewaysMock) {
private val gameId = GameId.random()
private val playerId = PlayerId.random()
@Test
fun `command success - returns 204 No Content`() {
gateways.assumeCommandReturns<FinishDay>(Success)
Given {
pathParam("gameId", gameId.raw)
header(Headers.PLAYER_ID, playerId.raw)
contentType(ContentType.JSON)
body(
"""
{
"month": 1,
"week": 1,
"day": 1
}
"""
)
} When {
async().post("/games/{gameId}/calendar/days/finish")
} Then {
statusCode(HttpStatus.NO_CONTENT.value())
}
}
@Test
fun `command failure - returns 400 Bad Request`() {
gateways.assumeCommandReturns<FinishDay>(Failure("Can only finish current day"))
Given {
pathParam("gameId", gameId.raw)
header(Headers.PLAYER_ID, playerId.raw)
contentType(ContentType.JSON)
body(
"""
{
"month": 1,
"week": 1,
"day": 1
}
"""
)
} When {
async().post("/games/{gameId}/calendar/days/finish")
} Then {
statusCode(HttpStatus.BAD_REQUEST.value())
contentType(ContentType.JSON)
body("message", equalTo("Can only finish current day"))
}
}
}