Skip to content

Commit 5502400

Browse files
change UserControllerTest.java
1 parent 44f1eb1 commit 5502400

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/test/java/hexlet/code/controller/api/UserControllerTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
@SpringBootTest
3737
@AutoConfigureMockMvc
3838
class UserControllerTest {
39+
private final String url = "/api/users";
3940

4041
@Autowired
4142
private WebApplicationContext wac;
@@ -73,7 +74,7 @@ public void setUp() {
7374

7475
@Test
7576
void testIndex() throws Exception {
76-
var response = mvc.perform(get("/api/users").with(jwt()))
77+
var response = mvc.perform(get(url).with(jwt()))
7778
.andExpect(status().isOk())
7879
.andReturn()
7980
.getResponse();
@@ -88,11 +89,12 @@ void testIndex() throws Exception {
8889

8990
@Test
9091
void testShow() throws Exception {
91-
var request = get("/api/users/{id}", testUser.getId()).with(jwt());
92+
var request = get(url + "/{id}", testUser.getId()).with(jwt());
9293
var result = mvc.perform(request)
9394
.andExpect(status().isOk())
94-
.andReturn();
95-
var body = result.getResponse().getContentAsString();
95+
.andReturn()
96+
.getResponse();
97+
var body = result.getContentAsString();
9698

9799
assertThatJson(body).and(
98100
v -> v.node("firstName").isEqualTo(testUser.getFirstName()),
@@ -105,8 +107,7 @@ void testShow() throws Exception {
105107
void testCreate() throws Exception {
106108
var data = Instancio.of(modelGenerator.getUserModel()).create();
107109

108-
var request = post("/api/users")
109-
.with(token)
110+
var request = post(url)
110111
.contentType(MediaType.APPLICATION_JSON)
111112
.content(om.writeValueAsString(data));
112113

@@ -125,7 +126,7 @@ public void testUpdate() throws Exception {
125126
var data = new HashMap<>();
126127
data.put("firstName", "Mike");
127128

128-
var request = put("/api/users/" + testUser.getId())
129+
var request = put(url + "/{id}", testUser.getId())
129130
.with(token)
130131
.contentType(MediaType.APPLICATION_JSON)
131132
.content(om.writeValueAsString(data));

0 commit comments

Comments
 (0)