File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed
test/unit/api/response/iiif Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -102,11 +102,19 @@ function homepageUrl(pageInfo) {
102
102
result = new URL ( `/collections/${ collectionId } ` , dcUrl ( ) ) ;
103
103
} else {
104
104
result = new URL ( "/search" , dcUrl ( ) ) ;
105
- if ( pageInfo . options ?. queryStringParameters ?. query )
105
+ if ( pageInfo . options ?. queryStringParameters ?. query ) {
106
106
result . searchParams . set (
107
107
"q" ,
108
108
pageInfo . options . queryStringParameters . query
109
109
) ;
110
+ }
111
+
112
+ if ( pageInfo . query_url . includes ( "similar" ) ) {
113
+ // Grab the work id from the query_url and add it to the search params
114
+ const regex = / w o r k s \/ ( .* ) \/ s i m i l a r / ;
115
+ const found = pageInfo . query_url . match ( regex ) ;
116
+ result . searchParams . set ( "similar" , found [ 1 ] ) ;
117
+ }
110
118
}
111
119
112
120
return result ;
Original file line number Diff line number Diff line change @@ -54,4 +54,31 @@ describe("IIIF Collection response transformer", () => {
54
54
expect ( body . status ) . to . eq ( 404 ) ;
55
55
expect ( body . error ) . to . be . a ( "string" ) ;
56
56
} ) ;
57
+
58
+ it ( "handles a request including /similar route" , async ( ) => {
59
+ let pagerWorkSimilar = new Paginator (
60
+ "http://dcapi.library.northwestern.edu/api/v2/" ,
61
+ "works/1234/similar" ,
62
+ [ "works" ] ,
63
+ { query : { query_string : { query : "genre.label:architecture" } } } ,
64
+ "iiif" ,
65
+ {
66
+ includeToken : false ,
67
+ queryStringParameters : {
68
+ collectionLabel : "The collection label" ,
69
+ collectionSummary : "The collection Summary" ,
70
+ } ,
71
+ }
72
+ ) ;
73
+
74
+ const response = {
75
+ statusCode : 200 ,
76
+ body : helpers . testFixture ( "mocks/search.json" ) ,
77
+ } ;
78
+ const result = await transformer . transform ( response , pagerWorkSimilar ) ;
79
+ expect ( result . statusCode ) . to . eq ( 200 ) ;
80
+
81
+ const body = JSON . parse ( result . body ) ;
82
+ expect ( body . homepage [ 0 ] . id ) . to . contain ( "search?similar=1234" ) ;
83
+ } ) ;
57
84
} ) ;
You can’t perform that action at this time.
0 commit comments