-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add an endpoint that creates task lists.
- Add an endpoint that reads tasks from a task list.
- Loading branch information
Showing
18 changed files
with
194 additions
and
25 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.motivepick.domain.model | ||
|
||
import org.motivepick.domain.entity.TaskListType | ||
|
||
data class TaskList(val id: Long, val type: TaskListType) |
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,5 @@ | ||
package org.motivepick.domain.view | ||
|
||
import org.motivepick.domain.entity.TaskListType | ||
|
||
data class TaskListView(val id: Long, val type: TaskListType) |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/org/motivepick/exception/ClientErrorException.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,7 @@ | ||
package org.motivepick.exception | ||
|
||
import org.springframework.http.HttpStatus | ||
import org.springframework.web.bind.annotation.ResponseStatus | ||
|
||
@ResponseStatus(HttpStatus.BAD_REQUEST) | ||
open class ClientErrorException(message: String) : RuntimeException(message) |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/org/motivepick/exception/ResourceNotFoundException.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,7 @@ | ||
package org.motivepick.exception | ||
|
||
import org.springframework.http.HttpStatus | ||
import org.springframework.web.bind.annotation.ResponseStatus | ||
|
||
@ResponseStatus(HttpStatus.NOT_FOUND) | ||
class ResourceNotFoundException(message: String) : ClientErrorException(message) |
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/org/motivepick/extensions/TaskListEntityExtensions.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,9 @@ | ||
package org.motivepick.extensions | ||
|
||
import org.motivepick.domain.entity.TaskListEntity | ||
import org.motivepick.domain.model.TaskList | ||
|
||
internal object TaskListEntityExtensions { | ||
|
||
fun TaskListEntity.model(): TaskList = TaskList(this.id, this.type) | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/org/motivepick/extensions/TaskListExtensions.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,9 @@ | ||
package org.motivepick.extensions | ||
|
||
import org.motivepick.domain.model.TaskList | ||
import org.motivepick.domain.view.TaskListView | ||
|
||
internal object TaskListExtensions { | ||
|
||
fun TaskList.view(): TaskListView = TaskListView(this.id, this.type) | ||
} |
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
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
84 changes: 84 additions & 0 deletions
84
src/test/kotlin/org/motivepick/web/TaskListControllerIntegrationTest.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,84 @@ | ||
package org.motivepick.web | ||
|
||
import com.github.springtestdbunit.annotation.DatabaseOperation.DELETE_ALL | ||
import com.github.springtestdbunit.annotation.DatabaseSetup | ||
import com.github.springtestdbunit.annotation.DatabaseTearDown | ||
import com.github.springtestdbunit.annotation.DbUnitConfiguration | ||
import jakarta.servlet.http.Cookie | ||
import org.hamcrest.Matchers.equalTo | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.motivepick.IntegrationTest | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc | ||
import org.springframework.test.context.junit.jupiter.SpringExtension | ||
import org.springframework.test.web.servlet.MockMvc | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.content | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status | ||
|
||
@ExtendWith(SpringExtension::class) | ||
@IntegrationTest(1234567890L) | ||
@DatabaseSetup("/dbunit/tasks.xml") | ||
@DatabaseTearDown("/dbunit/tasks.xml", type = DELETE_ALL) | ||
@DbUnitConfiguration(databaseConnection = ["dbUnitDatabaseConnection"]) | ||
@AutoConfigureMockMvc | ||
class TaskListControllerIntegrationTest { | ||
|
||
@Autowired | ||
private lateinit var mockMvc: MockMvc | ||
|
||
@Test | ||
fun `should create a custom task list if the user exists`() { | ||
val token = readTextFromResource("token.aae47dd3-32f1-415d-8bd8-4dc1086a6d10.txt") | ||
mockMvc | ||
.perform(post("/task-lists").cookie(Cookie("Authorization", token))) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().string(equalTo("{\"id\":1,\"type\":\"CUSTOM\"}"))) | ||
} | ||
|
||
@Test | ||
fun `should respond with 404 if the user does not exist`() { | ||
val token = readTextFromResource("token.c03354bb-0c31-4010-90a1-65582f4c35cf.txt") | ||
mockMvc | ||
.perform(post("/task-lists").cookie(Cookie("Authorization", token))) | ||
.andExpect(status().isNotFound()) | ||
} | ||
|
||
@Test | ||
fun `should read tasks by task list ID`() { | ||
val token = readTextFromResource("token.aae47dd3-32f1-415d-8bd8-4dc1086a6d10.txt") | ||
mockMvc | ||
.perform(get("/task-lists/4").param("offset", "0").param("limit", "1").cookie(Cookie("Authorization", token))) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().string(equalTo("{\"content\":[{\"id\":4,\"name\":\"Test task 3\",\"description\":\"\",\"dueDate\":null,\"closed\":false}],\"page\":{\"size\":1,\"number\":0,\"totalElements\":1,\"totalPages\":1}}"))) | ||
} | ||
|
||
@Test | ||
fun `should read tasks by a predefined task list type`() { | ||
val token = readTextFromResource("token.aae47dd3-32f1-415d-8bd8-4dc1086a6d10.txt") | ||
mockMvc | ||
.perform(get("/task-lists/INBOX").param("offset", "0").param("limit", "1").cookie(Cookie("Authorization", token))) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().string(equalTo("{\"content\":[{\"id\":4,\"name\":\"Test task 3\",\"description\":\"\",\"dueDate\":null,\"closed\":false}],\"page\":{\"size\":1,\"number\":0,\"totalElements\":1,\"totalPages\":1}}"))) | ||
} | ||
|
||
@Test | ||
fun `should return 400 if the task list type is not predefined`() { | ||
val token = readTextFromResource("token.aae47dd3-32f1-415d-8bd8-4dc1086a6d10.txt") | ||
mockMvc | ||
.perform(get("/task-lists/CUSTOM").param("offset", "0").param("limit", "1").cookie(Cookie("Authorization", token))) | ||
.andExpect(status().is4xxClientError()) | ||
} | ||
|
||
@Test | ||
fun `should return 404 if task list does not exist`() { | ||
val token = readTextFromResource("token.aae47dd3-32f1-415d-8bd8-4dc1086a6d10.txt") | ||
mockMvc | ||
.perform(get("/task-lists/1000000").param("offset", "0").param("limit", "1").cookie(Cookie("Authorization", token))) | ||
.andExpect(status().isNotFound()) | ||
} | ||
|
||
private fun readTextFromResource(path: String) = this::class.java.classLoader.getResource(path)?.readText() ?: error("Resource not found: $path") | ||
} |
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
1 change: 1 addition & 0 deletions
1
src/test/resources/token.aae47dd3-32f1-415d-8bd8-4dc1086a6d10.txt
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 @@ | ||
Bearer+eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhYWU0N2RkMy0zMmYxLTQxNWQtOGJkOC00ZGMxMDg2YTZkMTAiLCJzY29wZXMiOlsiUk9MRV9VU0VSIl0sImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3Q6ODA4MCIsImlhdCI6MTcyNDY5MjM4M30.-xmE8jv0gkbRTRRKuhTavgq8rFK7ZcgE2TCNw5BUYZory17yoWly6HxQnyi-OBpQkBerFdHVG_5XIQ_aNJ2L0w |
1 change: 1 addition & 0 deletions
1
src/test/resources/token.c03354bb-0c31-4010-90a1-65582f4c35cf.txt
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 @@ | ||
Bearer+eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJjMDMzNTRiYi0wYzMxLTQwMTAtOTBhMS02NTU4MmY0YzM1Y2YiLCJzY29wZXMiOlsiUk9MRV9VU0VSIl0sImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3Q6ODA4MCIsImlhdCI6MTcyNDcxNjA3Mn0.O4_3Bc_-D-wIVC3W17nsJ7bax2F-xJDze3y3dm-nOLNKjKgkPcdpndJjPuVdrh_OoGp8QVy_m71KuLUQtMyWcw |