@@ -41,6 +41,7 @@ describe('[Function] bigQuery', () => {
4141 name : 'name' ,
4242 locale : 'locale' ,
4343 taxon : 'taxon' ,
44+ person : 'person' ,
4445 organisation : 'organisation' ,
4546 link : 'link' ,
4647 }
@@ -59,6 +60,7 @@ describe('[Function] bigQuery', () => {
5960 name : 'name' ,
6061 locale : 'locale' ,
6162 taxon : 'taxon' ,
63+ person : 'person' ,
6264 organisation : 'organisation' ,
6365 link : 'link' ,
6466 } ,
@@ -75,6 +77,9 @@ describe('[Function] sendInitQuery', () => {
7577 . mockResolvedValueOnce ( [
7678 [ { name : 'taxon1' } , { name : 'taxon2' } , { name : 'taxon3' } ] ,
7779 ] )
80+ . mockResolvedValueOnce ( [
81+ [ { name : 'person1' } , { name : 'person2' } , { name : 'person3' } ] ,
82+ ] )
7883 . mockResolvedValueOnce ( [
7984 [ { title : 'org1' } , { title : 'org2' } , { title : 'org3' } ] ,
8085 ] )
@@ -90,7 +95,7 @@ describe('[Function] sendInitQuery', () => {
9095 ] )
9196 const result = await sendInitQuery ( )
9297
93- expect ( BigQuery . prototype . query ) . toHaveBeenCalledTimes ( 5 )
98+ expect ( BigQuery . prototype . query ) . toHaveBeenCalledTimes ( 6 )
9499
95100 expect ( BigQuery . prototype . query ) . toHaveBeenNthCalledWith ( 1 , {
96101 query : `
@@ -108,6 +113,14 @@ describe('[Function] sendInitQuery', () => {
108113 location : 'europe-west2' ,
109114 params : { } ,
110115 } )
116+ expect ( BigQuery . prototype . query ) . toHaveBeenNthCalledWith ( 2 , {
117+ query : `
118+ SELECT DISTINCT title
119+ FROM \`search.person\`
120+ ` ,
121+ location : 'europe-west2' ,
122+ params : { } ,
123+ } )
111124 expect ( BigQuery . prototype . query ) . toHaveBeenNthCalledWith ( 3 , {
112125 query : `
113126 SELECT DISTINCT title
@@ -136,6 +149,7 @@ describe('[Function] sendInitQuery', () => {
136149 expect ( result ) . toEqual ( {
137150 locales : [ '' , 'en' , 'cy' , 'fr' , 'de' ] ,
138151 taxons : [ 'taxon1' , 'taxon2' , 'taxon3' ] ,
152+ people : [ 'person1' , 'person2' , 'person3' ] ,
139153 organisations : [ 'org1' , 'org2' , 'org3' ] ,
140154 documentTypes : [ 'dt1' , 'dt2' , 'dt3' ] ,
141155 governments : [ 'gov1' , 'gov2' , 'gov3' ] ,
@@ -150,6 +164,7 @@ describe('[Function] sendSearchQuery', () => {
150164 selectedWords : 'keyword1 keyword2' ,
151165 excludedWords : 'excluded1 excluded2' ,
152166 taxon : 'taxon' ,
167+ person : 'person' ,
153168 publishingOrganisation : 'organisation' ,
154169 language : 'en' ,
155170 documentType : '' ,
@@ -184,6 +199,7 @@ describe('[Function] sendSearchQuery', () => {
184199 locale : 'en' ,
185200 organisation : 'organisation' ,
186201 taxon : 'taxon' ,
202+ person : 'person' ,
187203 } ,
188204 } )
189205 } )
@@ -207,6 +223,31 @@ describe('[Function] sendSearchQuery', () => {
207223 locale : 'en' ,
208224 organisation : 'organisation' ,
209225 taxon : 'taxon' ,
226+ person : 'person' ,
227+ } ,
228+ } )
229+ } )
230+ it ( 'Calls the appropriate queries with Person search type' , async ( ) => {
231+ jest . spyOn ( buildSqlQuery , 'buildSqlQuery' ) . mockReturnValue ( 'query' )
232+ ; ( BigQuery . prototype . query as jest . Mock )
233+ . mockResolvedValueOnce ( [ 'Some result' ] )
234+ . mockResolvedValueOnce ( [ 'Some result' ] )
235+ await sendSearchQuery ( makeSearchParams ( { searchType : SearchType . Person } ) )
236+ expect ( BigQuery . prototype . query ) . toHaveBeenCalledTimes ( 1 )
237+ expect ( BigQuery . prototype . query ) . toHaveBeenNthCalledWith ( 1 , {
238+ query : 'query' ,
239+ location : 'europe-west2' ,
240+ params : {
241+ excluded_keyword0 : 'excluded1' ,
242+ excluded_keyword1 : 'excluded2' ,
243+ politicalStatus : 'any' ,
244+ keyword0 : 'keyword1' ,
245+ keyword1 : 'keyword2' ,
246+ link : 'link' ,
247+ locale : 'en' ,
248+ organisation : 'organisation' ,
249+ taxon : 'taxon' ,
250+ person : 'person' ,
210251 } ,
211252 } )
212253 } )
@@ -232,6 +273,7 @@ describe('[Function] sendSearchQuery', () => {
232273 locale : 'en' ,
233274 organisation : 'organisation' ,
234275 taxon : 'taxon' ,
276+ person : 'person' ,
235277 } ,
236278 } )
237279 } )
0 commit comments