11package io.openfuture.state.controller
22
33import io.openfuture.state.entity.Account
4+ import io.openfuture.state.exception.NotFoundException
45import io.openfuture.state.service.AccountService
56import io.openfuture.state.service.WalletService
67import io.openfuture.state.util.any
@@ -38,6 +39,27 @@ class AccountControllerTest : BaseControllerTest() {
3839 .andExpect(status().isOk)
3940 }
4041
42+ @Test
43+ fun create_WhenAccountRequestAddressIsEmpty_ShouldReturnUnprocessableEntityStatus () {
44+ val requestBody = """
45+ {
46+ "webHook": "",
47+ "integrations": [
48+ {
49+ "address": "",
50+ "blockchainId": 1
51+
52+ }
53+ ]
54+ }
55+ """ .trimIndent()
56+
57+ mockMvc.perform(post(" /api/accounts" )
58+ .contentType(MediaType .APPLICATION_JSON )
59+ .content(requestBody))
60+ .andExpect(status().isBadRequest)
61+ }
62+
4163 @Test
4264 fun getAccountByIdTest () {
4365 val account = createDummyAccount().apply { id = 1 }
@@ -48,6 +70,15 @@ class AccountControllerTest : BaseControllerTest() {
4870 .andExpect(status().isOk)
4971 }
5072
73+ @Test
74+ fun get_WhenAccountIsNotPresented_ShouldReturnNotFoundStatus () {
75+
76+ given(accountService.get(any(Long ::class .java))).willThrow(NotFoundException (" Account with id 1 not found" ))
77+
78+ mockMvc.perform(get(" /api/accounts/1" ))
79+ .andExpect(status().isNotFound)
80+ }
81+
5182 @Test
5283 fun updateAccountWebHookTest () {
5384 val requestBody = readResource(" updateAccountWebHookRequest.json" , javaClass)
@@ -62,6 +93,21 @@ class AccountControllerTest : BaseControllerTest() {
6293 .andExpect(status().isOk)
6394 }
6495
96+ @Test
97+ fun update_WithInvalidUpdateRequest_ShouldReturnBadRequestStatus () {
98+ val requestBody = """
99+ {
100+ "id": 1,
101+ "webHook": ""
102+ }
103+ """ .trimIndent()
104+
105+ mockMvc.perform(put(" /api/accounts" )
106+ .contentType(MediaType .APPLICATION_JSON )
107+ .content(requestBody))
108+ .andExpect(status().isBadRequest)
109+ }
110+
65111 @Test
66112 fun deleteAccountTest () {
67113 val accountId = 1L
@@ -73,4 +119,12 @@ class AccountControllerTest : BaseControllerTest() {
73119 .andExpect(status().isOk)
74120 }
75121
122+ @Test
123+ fun delete_WhenAccountIsNotPresented_ShouldReturn_NotFoundStatus () {
124+ given(accountService.delete(1L )).willThrow(NotFoundException (" Account with id 1 not found" ))
125+
126+ mockMvc.perform(delete(" /api/accounts/1" ))
127+ .andExpect(status().isNotFound)
128+ }
129+
76130}
0 commit comments