-
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 : persist phoneNumber and make endpoint as saveOrRetrieve (#765)
* feat : persist phoneNumber and make endpoint as saveOrRetrieve * fix : issue with Integrationtests * fix : Integration Tests Issue * feat : send phone number as response * adds negative test case
- Loading branch information
1 parent
d351233
commit 0755a56
Showing
13 changed files
with
127 additions
and
17 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
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 |
---|---|---|
|
@@ -37,6 +37,7 @@ void setUp() { | |
new Customer() | ||
.setName("First Customer") | ||
.setEmail("[email protected]") | ||
.setPhone("1234567890") | ||
.setAddress("First Address") | ||
.setAmountAvailable(100) | ||
.setAmountReserved(10)); | ||
|
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 |
---|---|---|
|
@@ -38,18 +38,21 @@ void setUp() { | |
new Customer() | ||
.setName("First Customer") | ||
.setEmail("[email protected]") | ||
.setPhone("9876543210") | ||
.setAddress("First Address") | ||
.setAmountAvailable(100) | ||
.setAmountReserved(0), | ||
new Customer() | ||
.setName("Second Customer") | ||
.setEmail("[email protected]") | ||
.setPhone("9876543210") | ||
.setAddress("Second Address") | ||
.setAmountAvailable(100) | ||
.setAmountReserved(0), | ||
new Customer() | ||
.setName("Third Customer") | ||
.setEmail("[email protected]") | ||
.setPhone("9876543210") | ||
.setAddress("Third Address") | ||
.setAmountAvailable(100) | ||
.setAmountReserved(0)); | ||
|
@@ -83,6 +86,7 @@ void shouldFindCustomerById() throws Exception { | |
.andExpect(jsonPath("$.customerId", is(customer.getId()), Long.class)) | ||
.andExpect(jsonPath("$.name", is(customer.getName()))) | ||
.andExpect(jsonPath("$.email", is(customer.getEmail()))) | ||
.andExpect(jsonPath("$.phone", is(customer.getPhone()))) | ||
.andExpect(jsonPath("$.address", is(customer.getAddress()))) | ||
.andExpect(jsonPath("$.amountAvailable", is(customer.getAmountAvailable()))); | ||
} | ||
|
@@ -116,6 +120,7 @@ void shouldFindCustomerByName() throws Exception { | |
.andExpect(jsonPath("$.customerId", is(customer.getId()), Long.class)) | ||
.andExpect(jsonPath("$.name", is(customer.getName()))) | ||
.andExpect(jsonPath("$.email", is(customer.getEmail()))) | ||
.andExpect(jsonPath("$.phone", is(customer.getPhone()))) | ||
.andExpect(jsonPath("$.address", is(customer.getAddress()))) | ||
.andExpect(jsonPath("$.amountAvailable", is(customer.getAmountAvailable()))); | ||
} | ||
|
@@ -124,7 +129,11 @@ void shouldFindCustomerByName() throws Exception { | |
void shouldCreateNewCustomer() throws Exception { | ||
CustomerRequest customerRequest = | ||
new CustomerRequest( | ||
"New Customer", "[email protected]", "First Address", 10_000); | ||
"New Customer", | ||
"[email protected]", | ||
"1234567890", | ||
"First Address", | ||
10_000); | ||
this.mockMvc | ||
.perform( | ||
post("/api/customers") | ||
|
@@ -135,13 +144,39 @@ void shouldCreateNewCustomer() throws Exception { | |
.andExpect(jsonPath("$.customerId", notNullValue(Long.class))) | ||
.andExpect(jsonPath("$.name", is(customerRequest.name()))) | ||
.andExpect(jsonPath("$.email", is(customerRequest.email()))) | ||
.andExpect(jsonPath("$.phone", is(customerRequest.phone()))) | ||
.andExpect(jsonPath("$.address", is(customerRequest.address()))) | ||
.andExpect(jsonPath("$.amountAvailable", is(customerRequest.amountAvailable()))); | ||
} | ||
|
||
@Test | ||
void shouldReturnWithNoErrorCreatingExistingCustomer() throws Exception { | ||
Customer customer = customerList.getFirst(); | ||
CustomerRequest customerRequest = | ||
new CustomerRequest( | ||
customer.getName(), | ||
customer.getEmail(), | ||
customer.getPhone(), | ||
customer.getAddress(), | ||
customer.getAmountAvailable()); | ||
this.mockMvc | ||
.perform( | ||
post("/api/customers") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(objectMapper.writeValueAsString(customerRequest))) | ||
.andExpect(status().isCreated()) | ||
.andExpect(header().exists(HttpHeaders.LOCATION)) | ||
.andExpect(jsonPath("$.customerId", notNullValue(Long.class))) | ||
.andExpect(jsonPath("$.name", is(customerRequest.name()))) | ||
.andExpect(jsonPath("$.email", is(customerRequest.email()))) | ||
.andExpect(jsonPath("$.phone", is(customerRequest.phone()))) | ||
.andExpect(jsonPath("$.address", is(customerRequest.address()))) | ||
.andExpect(jsonPath("$.amountAvailable", is(customerRequest.amountAvailable()))); | ||
} | ||
|
||
@Test | ||
void shouldReturn400WhenCreateNewCustomerWithoutNameAndEmail() throws Exception { | ||
CustomerRequest customer = new CustomerRequest(null, null, null, 0); | ||
CustomerRequest customer = new CustomerRequest(null, null, null, null, 0); | ||
|
||
this.mockMvc | ||
.perform( | ||
|
@@ -159,7 +194,7 @@ void shouldReturn400WhenCreateNewCustomerWithoutNameAndEmail() throws Exception | |
is("https://zalando.github.io/problem/constraint-violation"))) | ||
.andExpect(jsonPath("$.title", is("Constraint Violation"))) | ||
.andExpect(jsonPath("$.status", is(400))) | ||
.andExpect(jsonPath("$.violations", hasSize(3))) | ||
.andExpect(jsonPath("$.violations", hasSize(4))) | ||
.andExpect(jsonPath("$.violations[0].field", is("amountAvailable"))) | ||
.andExpect( | ||
jsonPath( | ||
|
@@ -176,7 +211,8 @@ void shouldReturn400WhenCreateNewCustomerWithoutNameAndEmail() throws Exception | |
void shouldUpdateCustomer() throws Exception { | ||
Long customerId = customerList.getFirst().getId(); | ||
CustomerRequest customerRequest = | ||
new CustomerRequest("Updated text", "[email protected]", "First Address", 500); | ||
new CustomerRequest( | ||
"Updated text", "[email protected]", "1234567890", "First Address", 500); | ||
|
||
this.mockMvc | ||
.perform( | ||
|
@@ -188,6 +224,7 @@ void shouldUpdateCustomer() throws Exception { | |
.andExpect(jsonPath("$.name", is(customerRequest.name()))) | ||
.andExpect(jsonPath("$.email", is(customerRequest.email()))) | ||
.andExpect(jsonPath("$.address", is(customerRequest.address()))) | ||
.andExpect(jsonPath("$.phone", is(customerRequest.phone()))) | ||
.andExpect(jsonPath("$.amountAvailable", is(customerRequest.amountAvailable()))); | ||
} | ||
|
||
|
@@ -196,7 +233,11 @@ void shouldReturn404WhenUpdatingNonExistingCustomer() throws Exception { | |
long customerId = customerList.getFirst().getId() + 99_999; | ||
CustomerRequest customerRequest = | ||
new CustomerRequest( | ||
"Updated text", "[email protected]", "First Address", 10_000); | ||
"Updated text", | ||
"[email protected]", | ||
"1234567890", | ||
"First Address", | ||
10_000); | ||
|
||
this.mockMvc | ||
.perform( | ||
|
@@ -227,6 +268,7 @@ void shouldDeleteCustomer() throws Exception { | |
.andExpect(jsonPath("$.name", is(customer.getName()))) | ||
.andExpect(jsonPath("$.email", is(customer.getEmail()))) | ||
.andExpect(jsonPath("$.address", is(customer.getAddress()))) | ||
.andExpect(jsonPath("$.phone", is(customer.getPhone()))) | ||
.andExpect(jsonPath("$.amountAvailable", is(customer.getAmountAvailable()))); | ||
} | ||
|
||
|
Oops, something went wrong.