|
20 | 20 | import static uk.gov.companieshouse.pscdataapi.config.AbstractMongoConfig.mongoDBContainer; |
21 | 21 |
|
22 | 22 | import uk.gov.companieshouse.pscdataapi.config.CucumberContext; |
| 23 | +import uk.gov.companieshouse.pscdataapi.models.PscData; |
| 24 | +import uk.gov.companieshouse.pscdataapi.models.PscDocument; |
23 | 25 | import uk.gov.companieshouse.pscdataapi.util.FileReaderUtil; |
24 | 26 | import uk.gov.companieshouse.pscdataapi.repository.CompanyPscRepository; |
25 | 27 |
|
| 28 | +import java.io.File; |
| 29 | +import java.io.IOException; |
26 | 30 | import java.util.Collections; |
| 31 | +import java.util.NoSuchElementException; |
| 32 | +import java.util.Optional; |
27 | 33 |
|
28 | 34 | public class PscDataSteps { |
29 | 35 | private String contextId; |
@@ -55,8 +61,44 @@ public void theApplicationRunning() { |
55 | 61 | assertThat(restTemplate).isNotNull(); |
56 | 62 | } |
57 | 63 |
|
| 64 | + @Given("a psc data record exists with notification id {string} and delta_at {string}") |
| 65 | + public void psc_record_exists_for_company_and_id_with_delta_at(String notifcationId, String deltaAt) throws IOException { |
| 66 | + String pscDataFile = FileReaderUtil.readFile("src/itest/resources/json/input/psc_data_api.json"); |
| 67 | + PscData pscData = objectMapper.readValue(pscDataFile, PscData.class); |
| 68 | + |
| 69 | + PscDocument document = new PscDocument(); |
| 70 | + document.setId(notifcationId); |
| 71 | + document.setCompanyNumber(COMPANY_NUMBER); |
| 72 | + document.setData(pscData); |
| 73 | + document.setDeltaAt(deltaAt); |
| 74 | + mongoTemplate.save(document); |
| 75 | + assertThat(companyPscRepository.findById(notifcationId)).isNotEmpty(); |
| 76 | + } |
| 77 | + |
58 | 78 | @When("I send a PUT request with payload {string} file with notification id {string}") |
59 | | - public void i_send_psc_statement_put_request_with_payload(String dataFile, String notificationId) { |
| 79 | + public void i_send_psc_record_put_request_with_payload(String dataFile, String notificationId) { |
| 80 | + String data = FileReaderUtil.readFile("src/itest/resources/json/input/" + dataFile + ".json"); |
| 81 | + |
| 82 | + HttpHeaders headers = new HttpHeaders(); |
| 83 | + headers.setContentType(MediaType.APPLICATION_JSON); |
| 84 | + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); |
| 85 | + |
| 86 | + this.contextId = "5234234234"; |
| 87 | + CucumberContext.CONTEXT.set("contextId", this.contextId); |
| 88 | + headers.set("x-request-id", this.contextId); |
| 89 | + headers.set("ERIC-Identity", "TEST-IDENTITY"); |
| 90 | + headers.set("ERIC-Identity-Type", "key"); |
| 91 | + headers.set("ERIC-Authorised-Key-Roles", "*"); |
| 92 | + |
| 93 | + HttpEntity request = new HttpEntity(data, headers); |
| 94 | + String uri = "/company/{company_number}/persons-with-significant-control/{notfication_id}/full_record"; |
| 95 | + ResponseEntity<Void> response = restTemplate.exchange(uri, HttpMethod.PUT, request, Void.class, COMPANY_NUMBER, notificationId); |
| 96 | + |
| 97 | + CucumberContext.CONTEXT.set("statusCode", response.getStatusCodeValue()); |
| 98 | + } |
| 99 | + |
| 100 | + @When("I send a PUT request with payload {string} file for record with notification Id {string}") |
| 101 | + public void i_send_psc_data_put_request_with_payload(String dataFile, String notificationId) throws IOException { |
60 | 102 | String data = FileReaderUtil.readFile("src/itest/resources/json/input/" + dataFile + ".json"); |
61 | 103 |
|
62 | 104 | HttpHeaders headers = new HttpHeaders(); |
@@ -88,6 +130,13 @@ public void i_should_receive_status_code(Integer statusCode) { |
88 | 130 | Assertions.assertThat(expectedStatusCode).isEqualTo(statusCode); |
89 | 131 | } |
90 | 132 |
|
| 133 | + @When("a record exists with id {string} and delta_at {string}") |
| 134 | + public void psc_record_exists(String notificationId, String deltaAt) throws NoSuchElementException { |
| 135 | + Assertions.assertThat(companyPscRepository.existsById(notificationId)).isTrue(); |
| 136 | + Optional<PscDocument> document = companyPscRepository.findById(notificationId); |
| 137 | + Assertions.assertThat(companyPscRepository.findById(notificationId).get().getDeltaAt()).isEqualTo(deltaAt); |
| 138 | + } |
| 139 | + |
91 | 140 | @After |
92 | 141 | public void dbStop(){ |
93 | 142 | mongoDBContainer.stop(); |
|
0 commit comments