11import chai from "chai" ;
22import sinon from "sinon" ;
33
4- import { EnhancedSearchService } from "../../../../src/services/search/enhanced -search" ;
4+ import { AdvancedSearchService } from "../../../../src/services/search/advanced -search" ;
55import { RequestClient } from "../../../../src/http" ;
6- import { CompaniesResource } from "../../../../src/services/search/enhanced -search/types" ;
6+ import { CompaniesResource } from "../../../../src/services/search/advanced -search/types" ;
77import Resource from "../../../../src/services/resource" ;
88
99const expect = chai . expect ;
@@ -29,8 +29,12 @@ const mockResponseBody : CompaniesResource = ({
2929 locality : "cardiff" ,
3030 postal_code : "cf5 6rb" ,
3131 premises : "premises" ,
32+ region : "region" ,
3233 country : "country"
33- }
34+ } ,
35+ sic_codes : [
36+ "999999"
37+ ]
3438 } ,
3539 items : [
3640 {
@@ -50,22 +54,32 @@ const mockResponseBody : CompaniesResource = ({
5054 locality : "cardiff" ,
5155 postal_code : "cf5 6rb" ,
5256 premises : "premises" ,
57+ region : "region" ,
5358 country : "country"
54- }
59+ } ,
60+ sic_codes : [
61+ "999999"
62+ ]
5563 }
5664 ] ,
5765 kind : "kind" ,
5866 hits : 1
5967} )
6068
6169const mockRequestId = "fdskfhsdoifhsffsif" ;
62- const testCompanyName = "TEST COMPANY NAME" ;
70+ const testCompanyNameIncludes = "INCLUDES" ;
71+ const testCompanyNameExcludes = "EXCLUDES"
6372const testLocation = "TEST LOCATION" ;
64- const testIncorporatedFrom = " TEST INCORPORATED FROM" ;
65- const testIncorporatedTo = " TEST INCORPORATED TO" ;
66- const searchType = "enhanced" ;
73+ const testIncorporatedFrom = "TEST INCORPORATED FROM" ;
74+ const testIncorporatedTo = "TEST INCORPORATED TO" ;
75+ const testSicCodes = "999999" ;
76+ const testCompanyStatus = "TEST COMPANY STATUS" ;
77+ const testCompanyType = "TEST COMPANY TYPE" ;
78+ const testDissolvedFrom = "TEST DISSOLVED FROM" ;
79+ const testDissolvedTo = "TEST DISSOLVED TO" ;
80+ const searchType = "advanced" ;
6781
68- describe ( "create an enhanced search GET" , ( ) => {
82+ describe ( "create an advanced search GET" , ( ) => {
6983 beforeEach ( ( ) => {
7084 sinon . reset ( ) ;
7185 sinon . restore ( ) ;
@@ -84,22 +98,24 @@ describe("create an enhanced search GET", () => {
8498 } ;
8599
86100 const mockRequest = sinon . stub ( requestClient , "httpGet" ) . resolves ( mockGetRequest ) ;
87- const search : EnhancedSearchService = new EnhancedSearchService ( requestClient ) ;
88- const data : Resource < CompaniesResource > = await search . getCompanies ( testCompanyName , testLocation , testIncorporatedFrom , testIncorporatedTo , mockRequestId ) ;
101+ const search : AdvancedSearchService = new AdvancedSearchService ( requestClient ) ;
102+ const data : Resource < CompaniesResource > = await search . getCompanies ( testCompanyNameIncludes , testCompanyNameExcludes , testLocation , testIncorporatedFrom ,
103+ testIncorporatedTo , testSicCodes , testCompanyStatus , testCompanyType , testDissolvedFrom , testDissolvedTo , mockRequestId ) ;
89104
90105 expect ( data . httpStatusCode ) . to . equal ( 401 ) ;
91106 expect ( data . resource ) . to . be . undefined ;
92107 } ) ;
93108
94- it ( "returns enhanced search results correctly" , async ( ) => {
109+ it ( "returns advanced search results correctly" , async ( ) => {
95110 const mockGetRequest = {
96111 status : 200 ,
97112 body : mockResponseBody
98113 } ;
99114
100115 const mockRequest = sinon . stub ( requestClient , "httpGet" ) . resolves ( mockGetRequest ) ;
101- const search : EnhancedSearchService = new EnhancedSearchService ( requestClient ) ;
102- const data : Resource < CompaniesResource > = await search . getCompanies ( testCompanyName , testLocation , testIncorporatedFrom , testIncorporatedTo , mockRequestId ) ;
116+ const search : AdvancedSearchService = new AdvancedSearchService ( requestClient ) ;
117+ const data : Resource < CompaniesResource > = await search . getCompanies ( testCompanyNameIncludes , testCompanyNameExcludes , testLocation , testIncorporatedFrom ,
118+ testIncorporatedTo , testSicCodes , testCompanyStatus , testCompanyNameIncludes , testDissolvedFrom , testDissolvedTo , mockRequestId ) ;
103119 const item = data . resource . items [ 0 ] ;
104120 const mockItem = mockResponseBody . items [ 0 ] ;
105121
@@ -119,9 +135,11 @@ describe("create an enhanced search GET", () => {
119135 expect ( data . resource . top_hit . registered_office_address . postal_code ) . to . equal ( mockResponseBody . top_hit . registered_office_address . postal_code ) ;
120136 expect ( data . resource . top_hit . registered_office_address . premises ) . to . equal ( mockResponseBody . top_hit . registered_office_address . premises ) ;
121137 expect ( data . resource . top_hit . registered_office_address . country ) . to . equal ( mockResponseBody . top_hit . registered_office_address . country ) ;
138+ expect ( data . resource . top_hit . sic_codes ) . to . equal ( mockResponseBody . top_hit . sic_codes ) ;
122139 expect ( item . company_name ) . to . equal ( mockItem . company_name ) ;
123140 expect ( item . company_number ) . to . equal ( mockItem . company_number ) ;
124141 expect ( item . company_status ) . to . equal ( mockItem . company_status ) ;
142+ expect ( item . company_type ) . to . equal ( mockItem . company_type ) ;
125143 expect ( item . kind ) . to . equal ( mockItem . kind ) ;
126144 expect ( item . links . company_profile ) . to . equal ( mockItem . links . company_profile ) ;
127145 expect ( item . date_of_cessation ) . to . equal ( mockItem . date_of_cessation ) ;
@@ -131,6 +149,7 @@ describe("create an enhanced search GET", () => {
131149 expect ( item . registered_office_address . locality ) . to . equal ( mockItem . registered_office_address . locality ) ;
132150 expect ( item . registered_office_address . postal_code ) . to . equal ( mockItem . registered_office_address . postal_code ) ;
133151 expect ( item . registered_office_address . premises ) . to . equal ( mockItem . registered_office_address . premises ) ;
152+ expect ( item . sic_codes ) . to . equal ( mockItem . sic_codes ) ;
134153 expect ( data . resource . kind ) . to . equal ( mockResponseBody . kind ) ;
135154 expect ( data . resource . hits ) . to . equal ( mockResponseBody . hits ) ;
136155 } ) ;
0 commit comments