Skip to content

Commit

Permalink
feat: add Register Consultant action
Browse files Browse the repository at this point in the history
  • Loading branch information
sr4850 committed Nov 21, 2024
1 parent 6a80f5f commit ff31ca1
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.dvsa.testing.framework</groupId>
<artifactId>vol-api-calls</artifactId>
<version>2.7.1</version>
<version>2.7.1A</version>


<properties>
Expand Down
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;
}
}

0 comments on commit ff31ca1

Please sign in to comment.