Skip to content

Commit

Permalink
Updated integration tests to fit the new error response style
Browse files Browse the repository at this point in the history
  • Loading branch information
egorsivenko committed Apr 19, 2024
1 parent 080aeef commit 647d6a9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.linkurlshorter.urlshortener.auth.dto.AuthRequest;
import com.linkurlshorter.urlshortener.user.ChangeUserEmailRequest;
import com.linkurlshorter.urlshortener.user.ChangeUserPasswordRequest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -74,8 +72,7 @@ void loginFailedWhenUserDoesNotExistTest() throws Exception {
.content(objectMapper.writeValueAsString(authRequest)))
.andExpect(MockMvcResultMatchers.status().is4xxClientError())
.andExpect(MockMvcResultMatchers.jsonPath("$.statusCode").value(401))
.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Authentication failed!"))
.andExpect(MockMvcResultMatchers.jsonPath("$.exceptionMessage").value("No user by provided email found"));
.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("No user by provided email found"));
}

/**
Expand All @@ -91,8 +88,7 @@ void loginFailedWhenPasswordDoesNotMatchTest() throws Exception {
.content(objectMapper.writeValueAsString(authRequest)))
.andExpect(MockMvcResultMatchers.status().is4xxClientError())
.andExpect(MockMvcResultMatchers.jsonPath("$.statusCode").value(401))
.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Bad Credentials!"))
.andExpect(MockMvcResultMatchers.jsonPath("$.exceptionMessage").value("Bad credentials"));
.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Bad credentials"));
}

/**
Expand All @@ -110,8 +106,7 @@ void loginFailedWhenInvalidPasswordGivenTest(String password) throws Exception {
.content(objectMapper.writeValueAsString(authRequest)))
.andExpect(status().is4xxClientError())
.andExpect(MockMvcResultMatchers.jsonPath("$.statusCode").value(400))
.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Validation failed!"))
.andExpect(MockMvcResultMatchers.jsonPath("$.exceptionMessage").value("Password " +
.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Password " +
"must be at least 8 characters long and contain at least one digit, one uppercase letter, " +
"and one lowercase letter. No spaces are allowed."));
}
Expand All @@ -136,9 +131,7 @@ void loginFailedWhenInvalidEmailGivenTest(String email) throws Exception {
.content(objectMapper.writeValueAsString(authRequest)))
.andExpect(status().is4xxClientError())
.andExpect(MockMvcResultMatchers.jsonPath("$.statusCode").value(400))
.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Validation failed!"))
.andExpect(MockMvcResultMatchers.jsonPath("$.exceptionMessage")
.value("Email address entered incorrectly!"));
.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Email address entered incorrectly!"));
}

/**
Expand All @@ -156,8 +149,7 @@ void registerFailedWhenInvalidPasswordGivenTest(String password) throws Exceptio
.content(objectMapper.writeValueAsString(authRequest)))
.andExpect(status().is4xxClientError())
.andExpect(MockMvcResultMatchers.jsonPath("$.statusCode").value(400))
.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Validation failed!"))
.andExpect(MockMvcResultMatchers.jsonPath("$.exceptionMessage").value("Password " +
.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Password " +
"must be at least 8 characters long and contain at least one digit, one uppercase letter, " +
"and one lowercase letter. No spaces are allowed."));
}
Expand All @@ -182,8 +174,6 @@ void registerFailedWhenInvalidEmailGivenTest(String email) throws Exception {
.content(objectMapper.writeValueAsString(authRequest)))
.andExpect(status().is4xxClientError())
.andExpect(MockMvcResultMatchers.jsonPath("$.statusCode").value(400))
.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Validation failed!"))
.andExpect(MockMvcResultMatchers.jsonPath("$.exceptionMessage")
.value("Email address entered incorrectly!"));
.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Email address entered incorrectly!"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;


import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
Expand Down Expand Up @@ -106,8 +104,7 @@ void changePasswordFailedWhenInvalidPasswordGivenTest(String password) throws Ex
.content(objectMapper.writeValueAsString(request)))
.andExpect(status().is4xxClientError())
.andExpect(MockMvcResultMatchers.jsonPath("$.statusCode").value(400))
.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Validation failed!"))
.andExpect(MockMvcResultMatchers.jsonPath("$.exceptionMessage").value("Password " +
.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Password " +
"must be at least 8 characters long and contain at least one digit, one uppercase letter, " +
"and one lowercase letter. No spaces are allowed."));
}
Expand Down Expand Up @@ -158,8 +155,7 @@ void changeEmailFailedWhenInvalidEmailGivenTest(String email) throws Exception {
.content(objectMapper.writeValueAsString(request)))
.andExpect(status().is4xxClientError())
.andExpect(MockMvcResultMatchers.jsonPath("$.statusCode").value(400))
.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Validation failed!"))
.andExpect(MockMvcResultMatchers.jsonPath("$.exceptionMessage")
.andExpect(MockMvcResultMatchers.jsonPath("$.message")
.value("Email address entered incorrectly!"));
}
}

0 comments on commit 647d6a9

Please sign in to comment.