@@ -82,6 +82,137 @@ describe('Parsoid API', function() {
8282
8383 } ) ; // formats
8484
85+ describe ( 'accepts' , function ( ) {
86+
87+ var acceptableHtmlResponse = function ( profile ) {
88+ return function ( res ) {
89+ res . statusCode . should . equal ( 200 ) ;
90+ res . headers . should . have . property ( 'content-type' ) ;
91+ res . headers [ 'content-type' ] . should . equal (
92+ 'text/html; charset=utf-8; profile="https://www.mediawiki.org/wiki/Specs/HTML/' + profile + '"'
93+ ) ;
94+ res . text . should . not . equal ( '' ) ;
95+ } ;
96+ } ;
97+
98+ var acceptablePageBundleResponse = function ( profile ) {
99+ return function ( res ) {
100+ res . statusCode . should . equal ( 200 ) ;
101+ res . body . should . have . property ( 'html' ) ;
102+ res . body . html . should . have . property ( 'headers' ) ;
103+ res . body . html . headers . should . have . property ( 'content-type' ) ;
104+ res . body . html . headers [ 'content-type' ] . should . equal (
105+ 'text/html; charset=utf-8; profile="https://www.mediawiki.org/wiki/Specs/HTML/' + profile + '"'
106+ ) ;
107+ res . body . html . should . have . property ( 'body' ) ;
108+ res . body . should . have . property ( 'data-parsoid' ) ;
109+ res . body [ 'data-parsoid' ] . should . have . property ( 'headers' ) ;
110+ res . body [ 'data-parsoid' ] . headers . should . have . property ( 'content-type' ) ;
111+ // FIXME: There's only one content version now, and they should all have it.
112+ // res.body['data-parsoid'].headers['content-type'].should.equal(
113+ // 'application/json; charset=utf-8; profile="https://www.mediawiki.org/wiki/Specs/data-parsoid/' + profile + '"'
114+ // );
115+ res . body [ 'data-parsoid' ] . should . have . property ( 'body' ) ;
116+ } ;
117+ } ;
118+
119+ it ( 'should not accept requests for older html versions' , function ( done ) {
120+ request ( api )
121+ . post ( mockDomain + '/v3/transform/wikitext/to/html/' )
122+ . set ( 'Accept' , 'text/html; profile="https://www.mediawiki.org/wiki/Specs/HTML/0.0.0"' )
123+ . send ( { wikitext : '== h2 ==' } )
124+ . expect ( 406 )
125+ . end ( done ) ;
126+ } ) ;
127+
128+ it ( 'should not accept requests for older pagebundle versions' , function ( done ) {
129+ request ( api )
130+ . post ( mockDomain + '/v3/transform/wikitext/to/pagebundle/' )
131+ . set ( 'Accept' , 'application/json; profile="https://www.mediawiki.org/wiki/Specs/HTML/0.0.0"' )
132+ . send ( { wikitext : '== h2 ==' } )
133+ . expect ( 406 )
134+ . end ( done ) ;
135+ } ) ;
136+
137+ it ( 'should not accept requests for other profiles' , function ( done ) {
138+ request ( api )
139+ . post ( mockDomain + '/v3/transform/wikitext/to/html/' )
140+ . set ( 'Accept' , 'text/html; profile="something different"' )
141+ . send ( { wikitext : '== h2 ==' } )
142+ . expect ( 406 )
143+ . end ( done ) ;
144+ } ) ;
145+
146+ it ( 'should accept requests with no accept header' , function ( done ) {
147+ var profile = '1.2.1' ;
148+ request ( api )
149+ . post ( mockDomain + '/v3/transform/wikitext/to/html/' )
150+ . send ( { wikitext : '== h2 ==' } )
151+ . expect ( 200 )
152+ . expect ( acceptableHtmlResponse ( profile ) )
153+ . end ( done ) ;
154+ } ) ;
155+
156+ it ( 'should accept wildcards' , function ( done ) {
157+ var profile = '1.2.1' ;
158+ request ( api )
159+ . post ( mockDomain + '/v3/transform/wikitext/to/html/' )
160+ . set ( 'Accept' , '*/*' )
161+ . send ( { wikitext : '== h2 ==' } )
162+ . expect ( 200 )
163+ . expect ( acceptableHtmlResponse ( profile ) )
164+ . end ( done ) ;
165+ } ) ;
166+
167+ it ( 'should prefer higher quality' , function ( done ) {
168+ // FIXME: This test would be better if there were more available
169+ // versions. Fix it in the followup.
170+ var profile = '1.2.1' ;
171+ request ( api )
172+ . post ( mockDomain + '/v3/transform/wikitext/to/html/' )
173+ . set ( 'Accept' , 'text/html; profile="https://www.mediawiki.org/wiki/Specs/HTML/0.0.0"; q=0.5,' +
174+ 'text/html; profile="https://www.mediawiki.org/wiki/Specs/HTML/' + profile + '"; q=0.8' )
175+ . send ( { wikitext : '== h2 ==' } )
176+ . expect ( 200 )
177+ . expect ( acceptableHtmlResponse ( profile ) )
178+ . end ( done ) ;
179+ } ) ;
180+
181+ it ( 'should accept requests for the latest html versions' , function ( done ) {
182+ var profile = '1.2.1' ;
183+ request ( api )
184+ . post ( mockDomain + '/v3/transform/wikitext/to/html/' )
185+ . set ( 'Accept' , 'text/html; profile="https://www.mediawiki.org/wiki/Specs/HTML/' + profile + '"' )
186+ . send ( { wikitext : '== h2 ==' } )
187+ . expect ( 200 )
188+ . expect ( acceptableHtmlResponse ( profile ) )
189+ . end ( done ) ;
190+ } ) ;
191+
192+ it ( 'should accept requests for the latest pagebundle versions' , function ( done ) {
193+ var profile = '1.2.1' ;
194+ request ( api )
195+ . post ( mockDomain + '/v3/transform/wikitext/to/pagebundle/' )
196+ . set ( 'Accept' , 'application/json; profile="https://www.mediawiki.org/wiki/Specs/pagebundle/' + profile + '"' )
197+ . send ( { wikitext : '== h2 ==' } )
198+ . expect ( 200 )
199+ . expect ( acceptablePageBundleResponse ( profile ) )
200+ . end ( done ) ;
201+ } ) ;
202+
203+ it ( 'should accept requests for the latest pagebundle versions' , function ( done ) {
204+ var profile = '1.2.1' ;
205+ request ( api )
206+ . post ( mockDomain + '/v3/transform/wikitext/to/pagebundle/' )
207+ . set ( 'Accept' , 'application/json; profile="https://www.mediawiki.org/wiki/Specs/pagebundle/' + profile + '"' )
208+ . send ( { wikitext : '== h2 ==' } )
209+ . expect ( 200 )
210+ . expect ( acceptablePageBundleResponse ( profile ) )
211+ . end ( done ) ;
212+ } ) ;
213+
214+ } ) ; // accepts
215+
85216 describe ( "wt2html" , function ( ) {
86217
87218 var validHtmlResponse = function ( expectFunc ) {
0 commit comments