mirror of https://github.com/usbharu/Hideout.git
test: Filter APIのテストを一部復活
This commit is contained in:
parent
5cc8267135
commit
cb52248b1c
|
@ -16,7 +16,10 @@
|
|||
|
||||
package dev.usbharu.hideout.core.application.exception
|
||||
|
||||
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
|
||||
|
||||
class PermissionDeniedException : RuntimeException {
|
||||
constructor(principal: Principal) : super("Permission Denied $principal")
|
||||
constructor() : super()
|
||||
constructor(message: String?) : super(message)
|
||||
constructor(message: String?, cause: Throwable?) : super(message, cause)
|
||||
|
|
|
@ -34,7 +34,8 @@ class UserGetFilterApplicationService(private val filterRepository: FilterReposi
|
|||
) {
|
||||
override suspend fun internalExecute(command: GetFilter, principal: LocalUser): Filter {
|
||||
val filter =
|
||||
filterRepository.findByFilterId(FilterId(command.filterId)) ?: throw IllegalArgumentException("Not Found")
|
||||
filterRepository.findByFilterId(FilterId(command.filterId))
|
||||
?: throw IllegalArgumentException("Filter ${command.filterId} not found.")
|
||||
if (filter.userDetailId != principal.userDetailId) {
|
||||
throw PermissionDeniedException()
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ class DeleteFilterV1ApplicationService(private val filterRepository: FilterRepos
|
|||
) {
|
||||
override suspend fun internalExecute(command: DeleteFilterV1, principal: LocalUser) {
|
||||
val filter = filterRepository.findByFilterKeywordId(FilterKeywordId(command.filterKeywordId))
|
||||
?: throw IllegalArgumentException("Filter ${command.filterKeywordId} not found")
|
||||
?: throw IllegalArgumentException("Filter ${command.filterKeywordId} by KeywordId not found")
|
||||
if (principal.userDetailId != filter.userDetailId) {
|
||||
throw PermissionDeniedException()
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ class GetFilterV1ApplicationService(private val filterRepository: FilterReposito
|
|||
?: throw IllegalArgumentException("Filter ${command.filterKeywordId} not found")
|
||||
|
||||
if (filter.userDetailId != principal.userDetailId) {
|
||||
throw PermissionDeniedException()
|
||||
throw PermissionDeniedException(principal)
|
||||
}
|
||||
|
||||
val filterKeyword = filter.filterKeywords.find { it.id.id == command.filterKeywordId }
|
||||
|
|
|
@ -84,6 +84,7 @@ class SpringFilterApi(
|
|||
account -> FilterContext.ACCOUNT
|
||||
}
|
||||
}.toSet()
|
||||
val principal = principalContextHolder.getPrincipal()
|
||||
val filter = userRegisterFilterApplicationService.execute(
|
||||
RegisterFilter(
|
||||
v1FilterPostRequest.phrase,
|
||||
|
@ -91,12 +92,12 @@ class SpringFilterApi(
|
|||
FilterAction.WARN,
|
||||
setOf(RegisterFilterKeyword(v1FilterPostRequest.phrase, filterMode))
|
||||
),
|
||||
principalContextHolder.getPrincipal()
|
||||
principal
|
||||
)
|
||||
return ResponseEntity.ok(
|
||||
getFilterV1ApplicationService.execute(
|
||||
GetFilterV1(filter.filterKeywords.first().id),
|
||||
principalContextHolder.getPrincipal()
|
||||
principal
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -418,7 +418,7 @@ class FilterTest {
|
|||
)
|
||||
}
|
||||
.asyncDispatch()
|
||||
.andExpect { status { isOk() } }
|
||||
.andExpect { status { isNotFound() } }
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -431,7 +431,7 @@ class FilterTest {
|
|||
)
|
||||
}
|
||||
.asyncDispatch()
|
||||
.andExpect { status { isOk() } }
|
||||
.andExpect { status { isNotFound() } }
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -456,7 +456,7 @@ class FilterTest {
|
|||
)
|
||||
}
|
||||
.asyncDispatch()
|
||||
.andExpect { status { isOk() } }
|
||||
.andExpect { status { isNotFound() } }
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -469,7 +469,7 @@ class FilterTest {
|
|||
)
|
||||
}
|
||||
.asyncDispatch()
|
||||
.andExpect { status { isOk() } }
|
||||
.andExpect { status { isNotFound() } }
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -494,7 +494,7 @@ class FilterTest {
|
|||
)
|
||||
}
|
||||
.asyncDispatch()
|
||||
.andExpect { status { isOk() } }
|
||||
.andExpect { status { isNotFound() } }
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -507,7 +507,7 @@ class FilterTest {
|
|||
)
|
||||
}
|
||||
.asyncDispatch()
|
||||
.andExpect { status { isOk() } }
|
||||
.andExpect { status { isNotFound() } }
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -664,6 +664,7 @@ class FilterTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Sql("/sql/filter/test-filter.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
|
||||
fun `apiV1FiltersIdDelete writeで削除できる`() {
|
||||
mockMvc
|
||||
.delete("/api/v1/filters/1") {
|
||||
|
@ -676,6 +677,7 @@ class FilterTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Sql("/sql/filter/test-filter.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
|
||||
fun `apiV1FiltersIdDelete write_filtersで削除できる`() {
|
||||
mockMvc
|
||||
.delete("/api/v1/filters/1") {
|
||||
|
@ -692,11 +694,10 @@ class FilterTest {
|
|||
mockMvc
|
||||
.delete("/api/v1/filters/1") {
|
||||
with(
|
||||
jwt().jwt { it.claim("uid", "1") }.authorities(SimpleGrantedAuthority("SCOPE_write"))
|
||||
jwt().jwt { it.claim("uid", "1") }.authorities(SimpleGrantedAuthority("SCOPE_read"))
|
||||
)
|
||||
}
|
||||
.asyncDispatch()
|
||||
.andExpect { status { isOk() } }
|
||||
.andExpect { status { isForbidden() } }
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -49,7 +49,7 @@ import org.springframework.web.context.WebApplicationContext
|
|||
@SpringBootTest(classes = [SpringApplication::class])
|
||||
@AutoConfigureMockMvc
|
||||
@Transactional
|
||||
@Sql("/sql/actors.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_CLASS)
|
||||
@Sql("/sql/actors.sql", "/sql/userdetail.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_CLASS)
|
||||
@Sql("/sql/posts.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_CLASS)
|
||||
@Sql("/sql/test-custom-emoji.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_CLASS)
|
||||
class StatusTest {
|
||||
|
|
|
@ -37,7 +37,7 @@ import org.springframework.web.context.WebApplicationContext
|
|||
|
||||
@SpringBootTest(classes = [SpringApplication::class])
|
||||
@Transactional
|
||||
@Sql("/sql/actors.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_CLASS)
|
||||
@Sql("/sql/actors.sql", "/sql/userdetail.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_CLASS)
|
||||
class TimelineApiTest {
|
||||
@Autowired
|
||||
private lateinit var context: WebApplicationContext
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
insert into filters (id, user_id, name, context, action)
|
||||
VALUES (1, 1, 'test filter', 'home', 'warn');
|
||||
VALUES (1, 1, 'test filter', 'HOME', 'WARN');
|
||||
insert into filter_keywords(id, filter_id, keyword, mode)
|
||||
VALUES (1, 1, 'hoge', 'NONE')
|
Loading…
Reference in New Issue