package apitestsuites; import com.utopiadeals.api.RestWebCall; import com.utopiadeals.framework.annotations.JsonTestDataExtension; import com.utopiadeals.utils.TestDataProvider; import com.utopiadeals.utils.config.Constants; import io.restassured.response.Response; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; @Tag("auth-api") public class UserAuthenticationApiTest { private static final String BASE_URL = Constants.getApiBaseUrl(); private static final String REGISTER_ENDPOINT = "/api/auth/register"; private static RestWebCall apiClient; @BeforeAll public static void setUp() { // Initialize API client (without auth for registration) apiClient = new RestWebCall(BASE_URL); } @Test public void registerUser_WithValidData_ShouldReturnSuccess() { // Arrange String requestBody = """ { "email": "test.user+%d@example.com", "password": "ValidPass123!", "firstName": "Test", "lastName": "User", "fullName": "Test User" } """.formatted(System.currentTimeMillis()); // Act Response response = apiClient.post(REGISTER_ENDPOINT, requestBody); // Assert assertThat(response.getStatusCode(), is(200)); assertThat(response.jsonPath().getString("message"), equalTo("User registered successfully")); } @ParameterizedTest() @JsonTestDataExtension("dataSet-0,dataSet-1,dataSet-2,dataSet-3,dataSet-4") public void registerUser_WithInvalidData_ShouldReturnError(TestDataProvider testDataProvider) { String testName = testDataProvider.getString("testName"); String expectedStatus = testDataProvider.getString("expectedStatus"); String expectedError = testDataProvider.getString("expectedError"); String requestBody = """ { "email": "%s", "password": "%s", "firstName": "%s", "lastName": "%s", "fullName": "%s" } """.formatted( testDataProvider.getString("email"), testDataProvider.getString("password"), testDataProvider.getString("firstName"), testDataProvider.getString("lastName"), testDataProvider.getString("fullName") ); // Act Response response = apiClient.post(REGISTER_ENDPOINT, requestBody); // Assert assertThat(testName, response.getStatusCode(), is(expectedStatus)); assertThat(testName, response.jsonPath().getString("error"), containsString(expectedError)); } }