@@ -21,7 +21,8 @@ const mockResponseBody : CompaniesResource = ({
2121 company_status : "active" ,
2222 corporate_name : "corporate name" ,
2323 record_type : "record type" ,
24- ordered_alpha_key : "ordered alpha key"
24+ ordered_alpha_key : "ordered alpha key" ,
25+ ordered_alpha_key_with_id : "COMPANY:00000000"
2526 } ,
2627 links : {
2728 self : "/company/FC022000"
@@ -32,6 +33,9 @@ const mockResponseBody : CompaniesResource = ({
3233
3334const mockRequestId = "fdskfhsdoifhsffsif" ;
3435const testCompanyName = "TEST COMPANY NAME" ;
36+ const searchBefore = "TESTCOMPANYTOP:00000000" ;
37+ const searchAfter = "TESTCOMPANYBOTTOM:00000000" ;
38+ const size = 20 ;
3539
3640describe ( "create a alphabetical search GET" , ( ) => {
3741 beforeEach ( ( ) => {
@@ -53,7 +57,7 @@ describe("create a alphabetical search GET", () => {
5357
5458 const mockRequest = sinon . stub ( requestClient , "httpGet" ) . resolves ( mockGetRequest ) ;
5559 const search : AlphabeticalSearchService = new AlphabeticalSearchService ( requestClient ) ;
56- const data : Resource < CompaniesResource > = await search . getCompanies ( testCompanyName , mockRequestId ) ;
60+ const data : Resource < CompaniesResource > = await search . getCompanies ( testCompanyName , mockRequestId , null , null , null ) ;
5761
5862 expect ( data . httpStatusCode ) . to . equal ( 401 ) ;
5963 expect ( data . resource ) . to . be . undefined ;
@@ -67,7 +71,51 @@ describe("create a alphabetical search GET", () => {
6771
6872 const mockRequest = sinon . stub ( requestClient , "httpGet" ) . resolves ( mockGetRequest ) ;
6973 const search : AlphabeticalSearchService = new AlphabeticalSearchService ( requestClient ) ;
70- const data : Resource < CompaniesResource > = await search . getCompanies ( testCompanyName , mockRequestId ) ;
74+ const data : Resource < CompaniesResource > = await search . getCompanies ( testCompanyName , mockRequestId , null , null , null ) ;
75+
76+ expect ( data . httpStatusCode ) . to . equal ( 200 ) ;
77+ expect ( data . resource . topHit ) . to . equal ( mockResponseBody . topHit ) ;
78+ expect ( data . resource . results [ 0 ] . ID ) . to . equal ( mockResponseBody . results [ 0 ] . ID ) ;
79+ expect ( data . resource . results [ 0 ] . company_type ) . to . equal ( mockResponseBody . results [ 0 ] . company_type )
80+ expect ( data . resource . results [ 0 ] . items . company_number ) . to . equal ( mockResponseBody . results [ 0 ] . items . company_number ) ;
81+ expect ( data . resource . results [ 0 ] . items . company_status ) . to . equal ( mockResponseBody . results [ 0 ] . items . company_status ) ;
82+ expect ( data . resource . results [ 0 ] . items . corporate_name ) . to . equal ( mockResponseBody . results [ 0 ] . items . corporate_name ) ;
83+ expect ( data . resource . results [ 0 ] . items . record_type ) . to . equal ( mockResponseBody . results [ 0 ] . items . record_type ) ;
84+ expect ( data . resource . results [ 0 ] . items . ordered_alpha_key ) . to . equal ( mockResponseBody . results [ 0 ] . items . ordered_alpha_key ) ;
85+ expect ( data . resource . results [ 0 ] . links ) . to . equal ( mockResponseBody . results [ 0 ] . links ) ;
86+ } ) ;
87+
88+ it ( "returns alphabetical search results correctly when searching previous results" , async ( ) => {
89+ const mockGetRequest = {
90+ status : 200 ,
91+ body : mockResponseBody
92+ } ;
93+
94+ const mockRequest = sinon . stub ( requestClient , "httpGet" ) . resolves ( mockGetRequest ) ;
95+ const search : AlphabeticalSearchService = new AlphabeticalSearchService ( requestClient ) ;
96+ const data : Resource < CompaniesResource > = await search . getCompanies ( testCompanyName , mockRequestId , searchBefore , null , size ) ;
97+
98+ expect ( data . httpStatusCode ) . to . equal ( 200 ) ;
99+ expect ( data . resource . topHit ) . to . equal ( mockResponseBody . topHit ) ;
100+ expect ( data . resource . results [ 0 ] . ID ) . to . equal ( mockResponseBody . results [ 0 ] . ID ) ;
101+ expect ( data . resource . results [ 0 ] . company_type ) . to . equal ( mockResponseBody . results [ 0 ] . company_type )
102+ expect ( data . resource . results [ 0 ] . items . company_number ) . to . equal ( mockResponseBody . results [ 0 ] . items . company_number ) ;
103+ expect ( data . resource . results [ 0 ] . items . company_status ) . to . equal ( mockResponseBody . results [ 0 ] . items . company_status ) ;
104+ expect ( data . resource . results [ 0 ] . items . corporate_name ) . to . equal ( mockResponseBody . results [ 0 ] . items . corporate_name ) ;
105+ expect ( data . resource . results [ 0 ] . items . record_type ) . to . equal ( mockResponseBody . results [ 0 ] . items . record_type ) ;
106+ expect ( data . resource . results [ 0 ] . items . ordered_alpha_key ) . to . equal ( mockResponseBody . results [ 0 ] . items . ordered_alpha_key ) ;
107+ expect ( data . resource . results [ 0 ] . links ) . to . equal ( mockResponseBody . results [ 0 ] . links ) ;
108+ } ) ;
109+
110+ it ( "returns alphabetical search results correctly when searching next results" , async ( ) => {
111+ const mockGetRequest = {
112+ status : 200 ,
113+ body : mockResponseBody
114+ } ;
115+
116+ const mockRequest = sinon . stub ( requestClient , "httpGet" ) . resolves ( mockGetRequest ) ;
117+ const search : AlphabeticalSearchService = new AlphabeticalSearchService ( requestClient ) ;
118+ const data : Resource < CompaniesResource > = await search . getCompanies ( testCompanyName , mockRequestId , null , searchAfter , size ) ;
71119
72120 expect ( data . httpStatusCode ) . to . equal ( 200 ) ;
73121 expect ( data . resource . topHit ) . to . equal ( mockResponseBody . topHit ) ;
0 commit comments