@@ -37,9 +37,11 @@ class CompanyPscFullRecordGetControllerTest {
3737 private static final String MOCK_COMPANY_NUMBER = "1234567" ;
3838 private static final String MOCK_NOTIFICATION_ID = "123456789" ;
3939 private static final String ERIC_IDENTITY = "Test-Identity" ;
40- private static final String ERIC_IDENTITY_TYPE = "key" ;
40+ private static final String ERIC_IDENTITY_TYPE_API_KEY = "key" ;
41+ private static final String ERIC_IDENTITY_TYPE_OAUTH2 = "oauth2" ;
4142 private static final String ERIC_PRIVILEGES = "*" ;
4243 private static final String ERIC_AUTH_SENSITIVE = "sensitive-data" ;
44+ private static final String ERIC_AUTHORISED_TOKEN_PERMISSIONS_HEADER = "company_pscs=readprotected user_profile=read" ;
4345
4446 private static final String GET_INDIVIDUAL_FULL_RECORD_URL = String .format (
4547 "/company/%s/persons-with-significant-control/individual/%s/full_record" , MOCK_COMPANY_NUMBER ,
@@ -58,8 +60,8 @@ void contextLoads() {
5860 }
5961
6062 @ Test
61- @ DisplayName ("Should return 200 status with full record data" )
62- void getIndividualPSC () throws Exception {
63+ @ DisplayName ("Should return 200 status with full record data when eric_identity_type=key " )
64+ void getIndividualPSCWithApiKey () throws Exception {
6365 when (companyPscService .getIndividualFullRecord (MOCK_COMPANY_NUMBER , MOCK_NOTIFICATION_ID )).thenReturn (
6466 createFullRecord ());
6567
@@ -105,7 +107,7 @@ void getIndividualPSC() throws Exception {
105107 """ ;
106108
107109 mockMvc .perform (get (GET_INDIVIDUAL_FULL_RECORD_URL ).header ("ERIC-Identity" , ERIC_IDENTITY )
108- .header ("ERIC-Identity-Type" , ERIC_IDENTITY_TYPE )
110+ .header ("ERIC-Identity-Type" , ERIC_IDENTITY_TYPE_API_KEY )
109111 .contentType (APPLICATION_JSON )
110112 .header ("x-request-id" , X_REQUEST_ID )
111113 .header ("ERIC-Authorised-Key-Roles" , ERIC_PRIVILEGES )
@@ -114,6 +116,64 @@ void getIndividualPSC() throws Exception {
114116 .andExpect (content ().json (expectedData , true ));
115117 }
116118
119+ @ Test
120+ @ DisplayName ("Should return 200 status with full record data when eric_identity_type=oauth2" )
121+ void getIndividualPSCWithOauth2 () throws Exception {
122+ when (companyPscService .getIndividualFullRecord (MOCK_COMPANY_NUMBER , MOCK_NOTIFICATION_ID )).thenReturn (
123+ createFullRecord ());
124+
125+ final String expectedData = """
126+ {
127+ "kind": "individual-person-with-significant-control",
128+ "date_of_birth": {
129+ "day": 1,
130+ "month": 2,
131+ "year": 2000
132+ },
133+ "name": "Andy Bob Smith",
134+ "name_elements": {
135+ "surname": "Smith",
136+ "forename": "Andy",
137+ "middle_name": "Bob"
138+ },
139+ "links": {
140+ "self": "/company/123/persons-with-significant-control/456"
141+ },
142+ "nationality": "British",
143+ "service_address": {
144+ "address_line_1": "addressLine1",
145+ "postal_code": "CF12 3AB",
146+ "premises": "1"
147+ },
148+ "natures_of_control": [
149+ "nature of my control"
150+ ],
151+ "usual_residential_address": {
152+ "address_line_1": "Home street",
153+ "postal_code": "AB12 3CD",
154+ "premises": "Cottage"
155+ },
156+ "residential_address_same_as_service_address": false,
157+ "verification_state": {
158+ "verification_status": "VERIFIED",
159+ "verification_start_date": "2025-01-10",
160+ "verification_statement_due_date": "2025-02-05"
161+ }
162+ }
163+ """ ;
164+
165+ mockMvc .perform (get (GET_INDIVIDUAL_FULL_RECORD_URL ).header ("ERIC-Identity" , ERIC_IDENTITY )
166+ .header ("ERIC-Identity-Type" , ERIC_IDENTITY_TYPE_OAUTH2 )
167+ .contentType (APPLICATION_JSON )
168+ .header ("x-request-id" , X_REQUEST_ID )
169+ .header ("ERIC-Authorised-Key-Roles" , ERIC_PRIVILEGES )
170+ .header ("ERIC-Authorised-Key-Privileges" , ERIC_AUTH_SENSITIVE )
171+ .header ("ERIC-Authorised-Token-Permissions" , ERIC_AUTHORISED_TOKEN_PERMISSIONS_HEADER )).andExpect (status ().isOk ())
172+ .andDo (print ())
173+ .andExpect (content ().json (expectedData , true ));
174+ }
175+
176+
117177 @ Test
118178 @ DisplayName ("Should return 404 when Individual PSC not found" )
119179 void shouldReturn404WhenIndividualPscNotFound () throws Exception {
@@ -122,7 +182,7 @@ void shouldReturn404WhenIndividualPscNotFound() throws Exception {
122182 "Individual PSC document not found in Mongo with id " + MOCK_NOTIFICATION_ID ));
123183
124184 mockMvc .perform (get (GET_INDIVIDUAL_FULL_RECORD_URL ).header ("ERIC-Identity" , ERIC_IDENTITY )
125- .header ("ERIC-Identity-Type" , ERIC_IDENTITY_TYPE )
185+ .header ("ERIC-Identity-Type" , ERIC_IDENTITY_TYPE_API_KEY )
126186 .contentType (APPLICATION_JSON )
127187 .header ("x-request-id" , X_REQUEST_ID )
128188 .header ("ERIC-Authorised-Key-Roles" , ERIC_PRIVILEGES )
0 commit comments