Skip to content

Commit

Permalink
Merge pull request #59 from companieshouse/feature/DSND-2069-fix-tests
Browse files Browse the repository at this point in the history
add missing mappings ans fix tests
  • Loading branch information
JAndrewCH authored Dec 7, 2023
2 parents c40e854 + 49e6ea5 commit 219a566
Show file tree
Hide file tree
Showing 10 changed files with 272 additions and 284 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import uk.gov.companieshouse.api.InternalApiClient;
import uk.gov.companieshouse.api.api.CompanyMetricsApiService;
import uk.gov.companieshouse.pscdataapi.api.ChsKafkaApiService;

/**
Expand All @@ -18,4 +19,7 @@ public abstract class AbstractIntegrationTest extends AbstractMongoConfig {
@MockBean
public ChsKafkaApiService chsKafkaApiService;

@MockBean
public CompanyMetricsApiService companyMetricsApiService;

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import org.assertj.core.api.Assertions;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -63,7 +64,7 @@ public class PscDataSteps {
private ChsKafkaApiService chsKafkaApiService;
@Autowired
private CompanyPscTransformer transformer;
@Autowired
@InjectMocks
private CompanyPscService companyPscService;

@Mock
Expand Down Expand Up @@ -1039,23 +1040,74 @@ public void aGetRequestHasBeenSentForAndForLegalPersonBeneficialOwner(String com
CucumberContext.CONTEXT.set("statusCode", response.getStatusCodeValue());
}

@And("a PSC {string} exists for {string} for List summary")
public void aPSCExistsForForListSummary(String dataFile, String companyNumber) throws JsonProcessingException {
String pscDataFile = FileReaderUtil.readFile("src/itest/resources/json/input/" + dataFile + ".json");
PscData pscData = objectMapper.readValue(pscDataFile, PscData.class);
@And("a PSC exists for {string} for List summary")
public void aPSCExistsForForListSummary(String companyNumber) throws JsonProcessingException {

PscData pscData = new PscData();
PscDocument document1 = new PscDocument();

String notificationId1 = "ZfTs9WeeqpXTqf6dc6FZ4C0H0ZX";
document1.setId(notificationId1);
document1.setCompanyNumber(companyNumber);
document1.setPscId("ZfTs9WeeqpXTqf6dc6FZ4C0H0ZX");
pscData.setEtag("string");
pscData.setName("string");
pscData.setNationality("British");
pscData.setSanctioned(true);
pscData.setKind("corporate-entity-person-with-significant-control");
Links links = new Links();
links.setSelf("/company/34777772/persons-with-significant-control/corporate-entity/ZfTs9WeeqpXTqf6dc6FZ4C0H0ZX");
pscData.setLinks(links);
Address address = new Address();
address.setAddressLine1("ura_line1");
address.setAddressLine2("ura_line2");
address.setCareOf("ura_care_of");
address.setCountry("United Kingdom");
address.setLocality("Cardiff");
address.setPoBox("ura_po");
address.setPostalCode("CF2 1B6");
address.setPremises("URA");
address.setRegion("ura_region");
pscData.setAddress(address);
List<String> list = new ArrayList<>();
list.add("part-right-to-share-surplus-assets-75-to-100-percent");
pscData.setNaturesOfControl(list);
Identification identification = new Identification();
identification.setRegistrationNumber("string");
identification.setPlaceRegistered("string");
identification.setCountryRegistered("string");
identification.setLegalAuthority("string");
identification.setLegalForm("string");
document1.setIdentification(new PscIdentification(identification));

document1.setData(pscData);
mongoTemplate.save(document1);


PscData pscData2 = new PscData();
PscDocument document2 = new PscDocument();

String notificationId2 = "ZfTs9WeeqpXTqf6dc6FZ4C0H0ZVV";
document2.setId(notificationId2);
document2.setCompanyNumber(companyNumber);
document2.setData(pscData);
document2.setPscId("ZfTs9WeeqpXTqf6dc6FZ4C0H0Z0");
pscData2.setEtag("string");
pscData2.setName("string");
pscData2.setNationality("British");
pscData2.setSanctioned(true);
pscData2.setKind("corporate-entity-person-with-significant-control");
Links links2 = new Links();
links2.setSelf("/company/34777772/persons-with-significant-control/corporate-entity/ZfTs9WeeqpXTqf6dc6FZ4C0H0Z0");
pscData2.setLinks(links2);

pscData2.setAddress(address);
pscData2.setNaturesOfControl(list);
document2.setIdentification(new PscIdentification(identification));

document2.setData(pscData2);



mongoTemplate.save(document2);

assertThat(companyPscRepository.getPscByCompanyNumberAndId(companyNumber, notificationId1)).isNotEmpty();
Expand Down Expand Up @@ -1083,13 +1135,13 @@ public void aGetRequestIsSentForForListSummary(String companyNumber) {
CucumberContext.CONTEXT.set("getResponseBody", response.getBody());
}


@And("the Get call response body should match file {string} for List Summary")
public void theGetCallResponseBodyShouldMatchFileForListSummary(String result) throws IOException {
String data = FileCopyUtils.copyToString(new InputStreamReader(
new FileInputStream("src/itest/resources/json/output/" + result + ".json")));
PscList expected = objectMapper.readValue(data, PscList.class);
PscList actual = CucumberContext.CONTEXT.get("getResponseBody");

assertThat(expected.getItemsPerPage()).isEqualTo(actual.getItemsPerPage());
assertThat(expected.getItems()).isEqualTo(actual.getItems());
assertThat(expected.getLinks()).isEqualTo(actual.getLinks());
Expand Down
21 changes: 11 additions & 10 deletions src/itest/resources/features/list_summary.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,40 @@ Feature: Get list summary

Scenario Outline: Processing Psc List GET request successfully
Given Psc data api service is running
And a PSC "<data>" exists for "<company_number>" for List summary
And a PSC exists for "<company_number>" for List summary
And Company Metrics "company_metrics_data" is available for company number "<company_number>"
When a Get request is sent for "<company_number>" for List summary
Then I should receive 200 status code
And the Get call response body should match file "<result>" for List Summary

Examples:
| data | company_number | result |
| get_super_secure | 34777777 | psc_list_output |
| company_number | result |
| 34777777 | psc_list_output |

Scenario Outline: Processing Psc List GET register view request successfully
Given Psc data api service is running
And a PSC "<data>" exists for "<companyNumber>" for List summary
And a PSC exists for "<companyNumber>" for List summary
And Company Metrics "<metricsData>" is available for company number "<companyNumber>"
When a Get request is sent for "<companyNumber>" for List summary
Then I should receive 200 status code
And the Get call response body should match file "<result>" for List Summary

Examples:
| data | metricsData | companyNumber | result |
| get_super_secure | company_metrics_data | 34777777 | psc_list_register_view_output |
| metricsData | companyNumber | result |
| company_metrics_data | 34777777 | psc_list_register_view_output |


Scenario Outline: Processing Psc List GET register view request unsuccessfully
when metrics is unavailable
Given Psc data api service is running
And a PSC "<data>" exists for "<company_number>" for List summary
And a PSC exists for "<company_number>" for List summary
And Company Metrics API is unavailable
When I send a GET statement list request for company number in register view "<company_number>"
Then I should receive 404 status code

Examples:
| data | company_number |
| get_super_secure | 34777777 |
| company_number |
| 34777777 |

Scenario Outline: Processing Psc List GET register view request unsuccessfully
when no company psc statements in public register
Expand All @@ -50,7 +51,7 @@ Feature: Get list summary

Scenario Outline: Get Psc List when sending get request without Eric headers
Given Psc data api service is running
And a PSC "<data>" exists for "<company_number>" for List summary
And a PSC exists for "<company_number>" for List summary
When a Get request is sent for "<company_number>" without ERIC headers for List summary
Then I should receive 401 status code

Expand Down
Loading

0 comments on commit 219a566

Please sign in to comment.