Skip to content

Commit f8bf26b

Browse files
authored
feat(cucumberPutUser): add cucumber scenario for put user endpoint (#81)
1 parent 2a6b5f2 commit f8bf26b

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

src/test/java/feature/SpringIntegrationTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,12 @@ protected void executeDelete(String path) {
5252
String url = "http://localhost:" + port + path;
5353
latestResponse = restTemplate.exchange(url, HttpMethod.DELETE, HttpEntity.EMPTY, String.class);
5454
}
55+
56+
protected void executePut(String path, Object payload) {
57+
String url = "http://localhost:" + port + path;
58+
HttpHeaders headers = new HttpHeaders();
59+
headers.setContentType(MediaType.APPLICATION_JSON);
60+
HttpEntity<Object> request = new HttpEntity<>(payload, headers);
61+
latestResponse = restTemplate.exchange(url, HttpMethod.PUT, request, String.class);
62+
}
5563
}

src/test/java/feature/StepDefinition.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,31 @@ public void theClientCallToDeleteTheCreatedUser() {
100100
executeDelete("/random-users/" + createdUserId);
101101
}
102102

103+
@Given("a valid user payload for update")
104+
public void aValidUserPayloadForUpdate() {
105+
payload = new UserRequest(
106+
"male",
107+
"John",
108+
"Doe",
109+
"Mr",
110+
"john.doe@example.com",
111+
"0611111111",
112+
"john.jpg",
113+
"US"
114+
);
115+
}
116+
117+
@When("the client call to PUT the created user")
118+
public void theClientCallToPutTheCreatedUser() {
119+
assertNotNull(createdUserId, "No user was created before this step");
120+
executePut("/random-users/" + createdUserId, payload);
121+
}
122+
123+
@When("the client call to PUT \\/random-users\\/{int}")
124+
public void theClientCallToPutRandomUser(int id) {
125+
executePut("/random-users/" + id, payload);
126+
}
127+
103128
@And("the response contains a list of users")
104129
public void theResponseContainsAListOfUsers() throws Exception {
105130
JsonNode body = objectMapper.readTree(latestResponse.getBody());
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Feature: Update user endpoint
2+
3+
Scenario: Update a user by ID after creation
4+
Given a valid user payload for creation
5+
When the client call to POST /random-users
6+
Then the response status should be 201
7+
And the user profile
8+
| id | <generated_id> |
9+
| firstname | Emma |
10+
Given a valid user payload for update
11+
When the client call to PUT the created user
12+
Then the response status should be 200
13+
And the user profile
14+
| firstname | John |
15+
| lastname | Doe |
16+
17+
Scenario: Update a user that does not exist
18+
Given a valid user payload for update
19+
When the client call to PUT /random-users/999999
20+
Then the response status should be 404
21+

0 commit comments

Comments
 (0)