Skip to content

Commit c14d636

Browse files
authored
Merge pull request #18 from companieshouse/Verify_Incoming_Payload_Timestamp
Verify incoming payload timestamp
2 parents aeb3bff + 2f165ed commit c14d636

File tree

6 files changed

+126
-4
lines changed

6 files changed

+126
-4
lines changed

src/itest/java/uk/gov/companieshouse/pscdataapi/steps/PscDataSteps.java

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,16 @@
2020
import static uk.gov.companieshouse.pscdataapi.config.AbstractMongoConfig.mongoDBContainer;
2121

2222
import uk.gov.companieshouse.pscdataapi.config.CucumberContext;
23+
import uk.gov.companieshouse.pscdataapi.models.PscData;
24+
import uk.gov.companieshouse.pscdataapi.models.PscDocument;
2325
import uk.gov.companieshouse.pscdataapi.util.FileReaderUtil;
2426
import uk.gov.companieshouse.pscdataapi.repository.CompanyPscRepository;
2527

28+
import java.io.File;
29+
import java.io.IOException;
2630
import java.util.Collections;
31+
import java.util.NoSuchElementException;
32+
import java.util.Optional;
2733

2834
public class PscDataSteps {
2935
private String contextId;
@@ -55,8 +61,44 @@ public void theApplicationRunning() {
5561
assertThat(restTemplate).isNotNull();
5662
}
5763

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+
5878
@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 {
60102
String data = FileReaderUtil.readFile("src/itest/resources/json/input/" + dataFile + ".json");
61103

62104
HttpHeaders headers = new HttpHeaders();
@@ -88,6 +130,13 @@ public void i_should_receive_status_code(Integer statusCode) {
88130
Assertions.assertThat(expectedStatusCode).isEqualTo(statusCode);
89131
}
90132

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+
91140
@After
92141
public void dbStop(){
93142
mongoDBContainer.stop();

src/itest/resources/features/psc_data.feature

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,15 @@ Feature: Process Psc Data Requests
1010
Examples:
1111
| notificationId | data |
1212
| ZfTs9WeeqpXTqf6dc6FZ4C0H0ZZ | psc_data_api |
13+
14+
Scenario Outline: Processing old psc data information
15+
16+
Given Psc data api service is running
17+
And a psc data record exists with notification id "<notificationId>" and delta_at "<deltaAt>"
18+
When I send a PUT request with payload "<oldData>" file for record with notification Id "<notificationId>"
19+
Then I should receive 201 status code
20+
And a record exists with id "<notificationId>" and delta_at "<deltaAt>"
21+
22+
Examples:
23+
| notificationId | deltaAt | oldData |
24+
| ZfTs9WeeqpXTqf6dc6FZ4C0H0ZZ | 2023-11-20T08:47:45.378Z | psc_data_api_old |
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"_id": "YfTs9WeeqpXTqf6dc6FZ4C0H0ZZ",
3+
"internal_data": {
4+
"created_at" : "2021-11-02T08:47:45",
5+
"updated_at" :"2021-09-14T10:30:16.000Z",
6+
"updated_by" :"CHIPS",
7+
"delta_at" : "2013-11-20T08:47:45.378Z"
8+
},
9+
"external_data": {
10+
"notification_id": "ZfTs9WeeqpXTqf6dc6FZ4C0H0ZZ",
11+
"psc_id" : "ZfTs9WeeqpXTqf6dc6FZ4C0H0ZZ",
12+
"sensitive_data": {
13+
"usual_residential_address" : {
14+
"address_line_1" : "ura_line1",
15+
"address_line_2" : "ura_line2",
16+
"care_of" : "ura_care_of",
17+
"country" : "United Kingdom",
18+
"locality" : "Cardiff",
19+
"po_box" : "ura_po",
20+
"postal_code" : "CF2 1B6",
21+
"premises" : "URA",
22+
"region" : "ura_region"
23+
},
24+
"residential_address_same_as_service_address": true,
25+
"date_of_birth": {
26+
"day": 21,
27+
"year": 1995,
28+
"month": 10
29+
}
30+
},
31+
"data" : {
32+
"service_address" : {
33+
"address_line_1" : "sa_line1",
34+
"address_line_2" : "sa_line2",
35+
"care_of" : "sa_care_of",
36+
"country" : "United Kingdom",
37+
"locality" : "Cardiff",
38+
"po_box" : "sa_po",
39+
"postal_code" : "CF2 1B6",
40+
"premises" : "SA",
41+
"region" : "sa_region"
42+
},
43+
"natures_of_control": [
44+
"part-right-to-share-surplus-assets-75-to-100-percent"
45+
],
46+
"country_of_residence" : "United Kingdom",
47+
"links" : [{
48+
"self" : "/company/34777772/persons-with-significant-control/ZfTs9WeeqpXTqf6dc6FZ4C0H0ZZ"
49+
}],
50+
"nationality" : "British",
51+
"kind" : "individual-person-with-significant-control",
52+
"company_number": "34777772",
53+
"name_elements": {
54+
"title":"Mr.",
55+
"surname" : "JONES",
56+
"forename" : "PHIL",
57+
"middlename" : "tom"
58+
}
59+
}
60+
}
61+
}

src/main/java/uk/gov/companieshouse/pscdataapi/repository/CompanyPscRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
import uk.gov.companieshouse.pscdataapi.models.PscDocument;
77

88
public interface CompanyPscRepository extends MongoRepository<PscDocument, String> {
9-
@Query("{'_id': ?0, 'delta.at':{$gte : { \"$date\" : \"?1\" } }}")
9+
@Query("{'_id': ?0, 'delta_at':{$gte : \"?1\" }}")
1010
List<PscDocument> findUpdatedPsc(String notificationId, String at);
1111
}

src/main/java/uk/gov/companieshouse/pscdataapi/service/CompanyPscService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
public class CompanyPscService {
1919

2020
private final DateTimeFormatter dateTimeFormatter =
21-
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
21+
DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSSSSS");
2222

2323
@Autowired
2424
private Logger logger;

src/test/java/uk/gov/companieshouse/pscdataapi/service/CompanyPscServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void setUp() {
6767
document = new PscDocument();
6868
document.setUpdated(new Updated().setAt(LocalDate.now()));
6969
final DateTimeFormatter dateTimeFormatter =
70-
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
70+
DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSSSSS");
7171
dateString = date.format(dateTimeFormatter);
7272
}
7373

0 commit comments

Comments
 (0)