-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: while fetching response, fetch is as CustomerResponse
Changes id to customerId
- Loading branch information
1 parent
11a727b
commit b86ee1f
Showing
8 changed files
with
74 additions
and
19 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,19 @@ | |
|
||
import static com.example.paymentservice.utils.AppConstants.PROFILE_TEST; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import com.example.paymentservice.entities.Customer; | ||
import com.example.paymentservice.exception.CustomerNotFoundException; | ||
import com.example.paymentservice.model.query.FindCustomersQuery; | ||
import com.example.paymentservice.model.request.CustomerRequest; | ||
import com.example.paymentservice.model.response.CustomerResponse; | ||
import com.example.paymentservice.model.response.PagedResult; | ||
import com.example.paymentservice.services.CustomerService; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
@@ -22,6 +28,7 @@ | |
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageImpl; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.zalando.problem.jackson.ProblemModule; | ||
|
@@ -73,4 +80,46 @@ void shouldFetchAllCustomers() throws Exception { | |
.andExpect(jsonPath("$.hasNext", is(false))) | ||
.andExpect(jsonPath("$.hasPrevious", is(false))); | ||
} | ||
|
||
@Test | ||
void shouldUpdateCustomer() throws Exception { | ||
|
||
CustomerRequest customerRequest = | ||
new CustomerRequest( | ||
"customerUpdatedName", "[email protected]", "junitAddress", 100); | ||
|
||
given(customerService.updateCustomer(eq(1L), any(CustomerRequest.class))) | ||
.willReturn( | ||
new CustomerResponse( | ||
1L, | ||
"customerUpdatedName", | ||
"[email protected]", | ||
"junitAddress", | ||
100)); | ||
|
||
this.mockMvc | ||
.perform( | ||
put("/api/customers/{id}", 1L) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(objectMapper.writeValueAsString(customerRequest))) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.customerId", is(1L), Long.class)); | ||
} | ||
|
||
@Test | ||
void shouldReturn404WhenUpdatingNonExistingCustomer() throws Exception { | ||
Long orderId = 1L; | ||
CustomerRequest customerRequest = | ||
new CustomerRequest( | ||
"customerUpdatedName", "[email protected]", "junitAddress", 100); | ||
given(customerService.updateCustomer(eq(1L), any(CustomerRequest.class))) | ||
.willThrow(new CustomerNotFoundException(1L)); | ||
|
||
this.mockMvc | ||
.perform( | ||
put("/api/customers/{id}", 1L) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(objectMapper.writeValueAsString(customerRequest))) | ||
.andExpect(status().isNotFound()); | ||
} | ||
} |