QA/src/test/java/endpoints/UserEndpoint.java
2025-07-03 01:35:00 +04:00

73 lines
2.7 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package endpoints;
import helpers.PropertyProvider;
import io.qameta.allure.Step;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
import pojo.UserRequest;
import static io.restassured.RestAssured.given;
public class UserEndpoint {
private static final String ENDPOINT = PropertyProvider.getProperty("endpoint.user");
@Step("Создание запроса о информации пользователя")
public static UserRequest addUser() {
return UserRequest.builder()
.id(PropertyProvider.getProperty("test.id"))
.username(PropertyProvider.getProperty("test.username"))
.firstName(PropertyProvider.getProperty("test.firstname"))
.lastName(PropertyProvider.getProperty("test.lastname"))
.email(PropertyProvider.getProperty("test.email"))
.build();
}
@Step("Добавить информацию о пользователе и вернуть его ID")
public static Response addUserId(RequestSpecification spec, UserRequest userRequest) {
return given(spec)
.body(userRequest)
.when()
.post(ENDPOINT)
.then()
.statusCode(200)
.extract().response();
}
@Step("Получить информацию о текущем пользователе")
public static Response getUser(RequestSpecification spec) {
return given(spec)
.when()
.get(ENDPOINT);
}
@Step("Получить информацию о пользователе по ID: {userId}")
public static Response getUserById(RequestSpecification spec, String userId) {
return given(spec)
.pathParam("id", userId)
.when()
.get(ENDPOINT + "/{id}");
}
@Step("Обновить информацию о пользователе: {user}")
public static Response updateUser(RequestSpecification spec, UserRequest userRequest) {
return given(spec)
.body(userRequest)
.when()
.put(ENDPOINT);
}
@Step("Удалить текущего пользователя")
public static Response deleteUser(RequestSpecification spec) {
return given(spec)
.when()
.delete(ENDPOINT);
}
@Step("Удалить пользователя по ID: {userId}")
public static Response deleteUserById(RequestSpecification spec, String userId) {
return given(spec)
.pathParam("id", userId)
.when()
.delete(ENDPOINT + "/{id}");
}
}