1
1
package com.runetopic.topics
2
2
3
3
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
4
+ import com.runetopic.TestEnvironment
5
+ import com.runetopic.TestEnvironment.TEST_KEY
4
6
import com.runetopic.api.topics.Topic
5
7
import com.runetopic.api.topics.TopicStorage
6
8
import com.runetopic.module
@@ -25,28 +27,28 @@ import kotlin.test.assertNotEquals
25
27
class TopicControllerTest {
26
28
27
29
@BeforeTest
28
- fun `clear topic storage` () = withTestApplication(Application ::module ) {
30
+ fun `clear topic storage` () = withTestApplication(TestEnvironment ) {
29
31
with (application.inject<TopicStorage >()) { value.storage.clear() }
30
32
}
31
33
32
34
@Test
33
- fun `test not authorized` () = withTestApplication(Application ::module ) {
35
+ fun `test not authorized` () = withTestApplication(TestEnvironment ) {
34
36
with (handleRequest(HttpMethod .Get , " /api/topics" )) {
35
37
assertEquals(HttpStatusCode .Unauthorized , response.status())
36
38
}
37
39
}
38
40
39
41
@Test
40
- fun `test get topics empty` () = withTestApplication(Application ::module ) {
42
+ fun `test get topics empty` () = withTestApplication(TestEnvironment ) {
41
43
with (handleRequest(HttpMethod .Get , " /api/topics" ) {
42
- addHeader(" Authorization" , " Bearer ${loginToken(" test" )} " )
44
+ addHeader(" Authorization" , " Bearer ${loginToken(" test" , TEST_KEY )} " )
43
45
}) {
44
46
assertEquals(HttpStatusCode .NotFound , response.status())
45
47
}
46
48
}
47
49
48
50
@Test
49
- fun `test post npc` () = withTestApplication(Application ::module ) {
51
+ fun `test post npc` () = withTestApplication(TestEnvironment ) {
50
52
val topic = mockk<Topic >()
51
53
every { topic.id } returns UUID .randomUUID()
52
54
every { topic.title } returns " Test Title"
@@ -55,7 +57,7 @@ class TopicControllerTest {
55
57
every { topic.private } returns false
56
58
57
59
with (handleRequest(HttpMethod .Post , " /api/topics" ) {
58
- addHeader(" Authorization" , " Bearer ${loginToken(" test" )} " )
60
+ addHeader(" Authorization" , " Bearer ${loginToken(" test" , TEST_KEY )} " )
59
61
addHeader(HttpHeaders .ContentType , " application/json" )
60
62
setBody(jacksonObjectMapper().writeValueAsString(topic))
61
63
}) {
@@ -66,7 +68,7 @@ class TopicControllerTest {
66
68
}
67
69
68
70
@Test
69
- fun `test get topics` () = withTestApplication(Application ::module ) {
71
+ fun `test get topics` () = withTestApplication(TestEnvironment ) {
70
72
val topic = mockk<Topic >()
71
73
every { topic.id } returns UUID .randomUUID()
72
74
every { topic.title } returns " Test Title"
@@ -75,7 +77,7 @@ class TopicControllerTest {
75
77
every { topic.private } returns false
76
78
77
79
with (handleRequest(HttpMethod .Post , " /api/topics" ) {
78
- addHeader(" Authorization" , " Bearer ${loginToken(" test" )} " )
80
+ addHeader(" Authorization" , " Bearer ${loginToken(" test" , TEST_KEY )} " )
79
81
addHeader(HttpHeaders .ContentType , " application/json" )
80
82
setBody(jacksonObjectMapper().writeValueAsString(topic))
81
83
}) {
@@ -85,7 +87,7 @@ class TopicControllerTest {
85
87
confirmVerified()
86
88
87
89
with (handleRequest(HttpMethod .Get , " /api/topics/${topic.id} " ) {
88
- addHeader(" Authorization" , " Bearer ${loginToken(" test" )} " )
90
+ addHeader(" Authorization" , " Bearer ${loginToken(" test" , TEST_KEY )} " )
89
91
}) {
90
92
assertEquals(jacksonObjectMapper().readValue(response.content, Topic ::class .java), topic)
91
93
assertEquals(HttpStatusCode .OK , response.status())
@@ -95,7 +97,7 @@ class TopicControllerTest {
95
97
confirmVerified()
96
98
97
99
with (handleRequest(HttpMethod .Put , " /api/topics/${topic.id} " ) {
98
- addHeader(" Authorization" , " Bearer ${loginToken(" test" )} " )
100
+ addHeader(" Authorization" , " Bearer ${loginToken(" test" , TEST_KEY )} " )
99
101
addHeader(HttpHeaders .ContentType , " application/json" )
100
102
setBody(
101
103
jacksonObjectMapper().writeValueAsString(
0 commit comments