Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/register consultant #78

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions src/main/java/apiCalls/actions/RegisterConsultantAndOperator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package apiCalls.actions;

import activesupport.http.RestUtils;
import activesupport.system.Properties;
import apiCalls.Utils.generic.Headers;
import apiCalls.Utils.generic.Utils;
import apiCalls.enums.BusinessType;
import io.restassured.response.ValidatableResponse;
import org.apache.hc.core5.http.HttpException;
import org.apache.http.HttpStatus;
import org.dvsa.testing.lib.url.api.URL;
import org.dvsa.testing.lib.url.utils.EnvironmentType;
import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.Map;

public class RegisterConsultantAndOperator {
private final RegisterUser operatorDetails;
private final RegisterUser consultantDetails;
private final Headers apiHeaders = new Headers();
private final EnvironmentType env;

public RegisterConsultantAndOperator() {
this.env = EnvironmentType.getEnum(Properties.get("env", true));
this.operatorDetails = new RegisterUser();
this.consultantDetails = new RegisterUser();

this.operatorDetails.setBusinessType(BusinessType.LIMITED_COMPANY.asString());
this.consultantDetails.setBusinessType(BusinessType.LIMITED_COMPANY.asString());
}

public RegisterUser getOperatorDetails() {
return operatorDetails;
}

public RegisterUser getConsultantDetails() {
return consultantDetails;
}

@Nonnull
public synchronized ValidatableResponse register() throws HttpException {
String registerResource = URL.build(env, "user/selfserve/register/register-consultant-operator").toString();

Map<String, Object> consultantPayload = buildUserRegistrationDetails(consultantDetails);
Map<String, Object> operatorPayload = buildUserRegistrationDetails(operatorDetails);

Map<String, Object> payload = new HashMap<>();
payload.put("consultantDetails", consultantPayload);
payload.put("operatorDetails", operatorPayload);

ValidatableResponse apiResponse = RestUtils.post(payload, registerResource, apiHeaders.getApiHeader());
Utils.checkHTTPStatusCode(apiResponse, HttpStatus.SC_CREATED);

consultantDetails.setUserId(apiResponse.extract().jsonPath().getString("id.user"));
operatorDetails.setUserId(apiResponse.extract().jsonPath().getString("id.user"));

return apiResponse;
}

private Map<String, Object> buildUserRegistrationDetails(RegisterUser user) {
Map<String, Object> person = new HashMap<>();
person.put("title", user.getTitle());
person.put("forename", user.getForeName());
person.put("familyName", user.getFamilyName());
person.put("birthDate", user.getBirthDate());

Map<String, Object> contactDetails = new HashMap<>();
contactDetails.put("emailAddress", user.getEmailAddress());
contactDetails.put("person", person);

Map<String, Object> registrationDetails = new HashMap<>();
registrationDetails.put("loginId", user.getUserName());
registrationDetails.put("contactDetails", contactDetails);
registrationDetails.put("organisationName", user.getOrganisationName());
registrationDetails.put("businessType", user.getBusinessType());

return registrationDetails;
}
}