@@ -5,7 +5,7 @@ import chaiHttp from "chai-http";
55
66import CompanyOfficersService from "../../../src/services/company-officers/service" ;
77import { RequestClient , HttpResponse } from "../../../src/http" ;
8- import { CompanyOfficersResource } from "../../../src/services/company-officers/types" ;
8+ import { CompanyOfficerResource , CompanyOfficersResource } from "../../../src/services/company-officers/types" ;
99const expect = chai . expect ;
1010
1111const requestClient = new RequestClient ( { baseUrl : "URL-NOT-USED" , oauthToken : "TOKEN-NOT-USED" } ) ;
@@ -183,4 +183,105 @@ describe("company-officers", () => {
183183 await companyOfficers . getCompanyOfficers ( "123" , 10 , 2 , true , "resigned_on" ) ;
184184 expect ( spy . calledWith ( "/company/123/officers?page_size=10&page_index=2®ister_view=true&order_by=resigned_on" ) ) . to . equal ( true ) ;
185185 } ) ;
186+
187+ it ( "maps the company field data correctly for specific appointment" , async ( ) => {
188+ const mockResponseBody : CompanyOfficerResource = ( {
189+ appointed_on : ( new Date ( ) ) . toISOString ( ) ,
190+ occupation : "director" ,
191+ country_of_residence : "United Kingdom" ,
192+ nationality : "British" ,
193+ resigned_on : ( new Date ( ) ) . toISOString ( ) ,
194+ name : "Some Director" ,
195+ officer_role : "director" ,
196+ responsibilities : "Determining the company’s strategic objectives and policies" ,
197+ address : {
198+ address_line_1 : "123 Street" ,
199+ address_line_2 : "Some area" ,
200+ care_of : "Some council" ,
201+ country : "United Kingdom" ,
202+ locality : "Wales" ,
203+ po_box : "123" ,
204+ postal_code : "SW1" ,
205+ premises : "some premises" ,
206+ region : "South"
207+ } ,
208+ date_of_birth : {
209+ day : "15" ,
210+ month : "4" ,
211+ year : "1996"
212+ } ,
213+ former_names : [
214+ {
215+ forenames : "Fore" ,
216+ surname : "Sur"
217+ }
218+ ] ,
219+ identification : {
220+ identification_type : "some identification type" ,
221+ legal_authority : "some legal auth" ,
222+ legal_form : "some legal form" ,
223+ place_registered : "some place" ,
224+ registration_number : "some reg"
225+ } ,
226+ contact_details : {
227+ contact_name : "Firstname Surname"
228+ } ,
229+ links : {
230+ self : "appointmentIdabc" ,
231+ officer : {
232+ appointments : "company/123/appointments/abc"
233+ }
234+ }
235+
236+ } ) ;
237+
238+ const mockGetResponse = {
239+ status : 200 ,
240+ body : mockResponseBody
241+ } ;
242+
243+ const mockRequest = sinon . stub ( requestClient , "httpGet" ) . resolves ( mockGetResponse ) ;
244+ const companyOfficers : CompanyOfficersService = new CompanyOfficersService ( requestClient ) ;
245+ const data = await companyOfficers . getCompanyAppointment ( "123" , "abc" ) ;
246+
247+ expect ( data . httpStatusCode ) . to . equal ( 200 ) ;
248+
249+ expect ( data . resource . appointedOn ) . to . equal ( mockResponseBody . appointed_on ) ;
250+ expect ( data . resource . countryOfResidence ) . to . equal ( mockResponseBody . country_of_residence ) ;
251+ expect ( data . resource . nationality ) . to . equal ( mockResponseBody . nationality ) ;
252+ expect ( data . resource . occupation ) . to . equal ( mockResponseBody . occupation ) ;
253+ expect ( data . resource . resignedOn ) . to . equal ( mockResponseBody . resigned_on ) ;
254+ expect ( data . resource . name ) . to . equal ( mockResponseBody . name ) ;
255+ expect ( data . resource . officerRole ) . to . equal ( mockResponseBody . officer_role ) ;
256+ expect ( data . resource . responsibilities ) . to . equal ( mockResponseBody . responsibilities ) ;
257+
258+ expect ( data . resource . address . addressLine1 ) . to . equal ( mockResponseBody . address . address_line_1 ) ;
259+ expect ( data . resource . address . addressLine2 ) . to . equal ( mockResponseBody . address . address_line_2 ) ;
260+ expect ( data . resource . address . careOf ) . to . equal ( mockResponseBody . address . care_of ) ;
261+ expect ( data . resource . address . country ) . to . equal ( mockResponseBody . address . country ) ;
262+ expect ( data . resource . address . locality ) . to . equal ( mockResponseBody . address . locality ) ;
263+ expect ( data . resource . address . poBox ) . to . equal ( mockResponseBody . address . po_box ) ;
264+ expect ( data . resource . address . postalCode ) . to . equal ( mockResponseBody . address . postal_code ) ;
265+ expect ( data . resource . address . premises ) . to . equal ( mockResponseBody . address . premises ) ;
266+ expect ( data . resource . address . region ) . to . equal ( mockResponseBody . address . region ) ;
267+
268+ expect ( data . resource . dateOfBirth . day ) . to . equal ( mockResponseBody . date_of_birth . day ) ;
269+ expect ( data . resource . dateOfBirth . month ) . to . equal ( mockResponseBody . date_of_birth . month ) ;
270+ expect ( data . resource . dateOfBirth . year ) . to . equal ( mockResponseBody . date_of_birth . year ) ;
271+
272+ expect ( data . resource . formerNames . length ) . to . equal ( mockResponseBody . former_names . length ) ;
273+ expect ( data . resource . formerNames [ 0 ] . forenames ) . to . equal ( mockResponseBody . former_names [ 0 ] . forenames ) ;
274+ expect ( data . resource . formerNames [ 0 ] . surname ) . to . equal ( mockResponseBody . former_names [ 0 ] . surname ) ;
275+
276+ expect ( data . resource . identification . identificationType ) . to . equal ( mockResponseBody . identification . identification_type ) ;
277+ expect ( data . resource . identification . legalAuthority ) . to . equal ( mockResponseBody . identification . legal_authority ) ;
278+ expect ( data . resource . identification . legalForm ) . to . equal ( mockResponseBody . identification . legal_form ) ;
279+ expect ( data . resource . identification . placeRegistered ) . to . equal ( mockResponseBody . identification . place_registered ) ;
280+ expect ( data . resource . identification . registrationNumber ) . to . equal ( mockResponseBody . identification . registration_number ) ;
281+
282+ expect ( data . resource . contactDetails . contactName ) . to . equal ( mockResponseBody . contact_details . contact_name ) ;
283+
284+ expect ( data . resource . links . officer . appointments ) . to . equal ( mockResponseBody . links . officer . appointments ) ;
285+ expect ( data . resource . links . self ) . to . equal ( mockResponseBody . links . self ) ;
286+ } ) ;
186287} ) ;
0 commit comments