@@ -13,6 +13,7 @@ describe('Prefix Middleware', () => {
1313 redirect : sinon . stub ( ) ,
1414 set : sinon . stub ( ) ,
1515 status : ( ) => ( { end : sinon . stub ( ) } ) ,
16+ vary : sinon . stub ( ) ,
1617 } ;
1718 fakeConfig = new Map ( ) ;
1819 fakeConfig . set ( 'validClientApplications' , [ 'firefox' , 'android' ] ) ;
@@ -27,8 +28,8 @@ describe('Prefix Middleware', () => {
2728 headers : { } ,
2829 } ;
2930 prefixMiddleware ( fakeReq , fakeRes , fakeNext , { _config : fakeConfig } ) ;
30- expect ( fakeRes . redirect . firstCall . args ) . toEqual ( [ 302 , '/en-US/firefox' ] ) ;
31- expect ( fakeNext . called ) . toBeFalsy ( ) ;
31+ sinon . assert . calledWith ( fakeRes . redirect , 302 , '/en-US/firefox' ) ;
32+ sinon . assert . notCalled ( fakeNext ) ;
3233 } ) ;
3334
3435 it ( 'should call res.redirect if handed a locale insted of a lang' , ( ) => {
@@ -37,8 +38,8 @@ describe('Prefix Middleware', () => {
3738 headers : { } ,
3839 } ;
3940 prefixMiddleware ( fakeReq , fakeRes , fakeNext , { _config : fakeConfig } ) ;
40- expect ( fakeRes . redirect . firstCall . args ) . toEqual ( [ 302 , '/en-US/firefox' ] ) ;
41- expect ( fakeNext . called ) . toBeFalsy ( ) ;
41+ sinon . assert . calledWith ( fakeRes . redirect , 302 , '/en-US/firefox' ) ;
42+ sinon . assert . notCalled ( fakeNext ) ;
4243 } ) ;
4344
4445 it ( 'should add an application when missing' , ( ) => {
@@ -47,7 +48,7 @@ describe('Prefix Middleware', () => {
4748 headers : { } ,
4849 } ;
4950 prefixMiddleware ( fakeReq , fakeRes , fakeNext , { _config : fakeConfig } ) ;
50- expect ( fakeRes . redirect . firstCall . args ) . toEqual ( [ 302 , '/en-US/firefox/whatever/' ] ) ;
51+ sinon . assert . calledWith ( fakeRes . redirect , 302 , '/en-US/firefox/whatever/' ) ;
5152 } ) ;
5253
5354 it ( 'should prepend a lang when missing but leave a valid app intact' , ( ) => {
@@ -56,8 +57,8 @@ describe('Prefix Middleware', () => {
5657 headers : { } ,
5758 } ;
5859 prefixMiddleware ( fakeReq , fakeRes , fakeNext , { _config : fakeConfig } ) ;
59- expect ( fakeRes . redirect . firstCall . args ) . toEqual ( [ 302 , '/en-US/firefox/whatever' ] ) ;
60- expect ( fakeRes . set . firstCall . args ) . toEqual ( [ ' vary' , [ ] ] ) ;
60+ sinon . assert . calledWith ( fakeRes . redirect , 302 , '/en-US/firefox/whatever' ) ;
61+ sinon . assert . notCalled ( fakeRes . vary ) ;
6162 } ) ;
6263
6364 it ( 'should prepend lang when missing but keep clientAppUrlException' , ( ) => {
@@ -66,8 +67,8 @@ describe('Prefix Middleware', () => {
6667 headers : { } ,
6768 } ;
6869 prefixMiddleware ( fakeReq , fakeRes , fakeNext , { _config : fakeConfig } ) ;
69- expect ( fakeRes . redirect . firstCall . args ) . toEqual ( [ 302 , '/en-US/validprefix/whatever' ] ) ;
70- expect ( fakeRes . set . firstCall . args ) . toEqual ( [ ' vary' , [ ] ] ) ;
70+ sinon . assert . calledWith ( fakeRes . redirect , 302 , '/en-US/validprefix/whatever' ) ;
71+ sinon . assert . notCalled ( fakeRes . vary ) ;
7172 } ) ;
7273
7374 it ( 'should render 404 when a localeURL exception exists' , ( ) => {
@@ -77,7 +78,7 @@ describe('Prefix Middleware', () => {
7778 } ;
7879 const statusSpy = sinon . spy ( fakeRes , 'status' ) ;
7980 prefixMiddleware ( fakeReq , fakeRes , fakeNext , { _config : fakeConfig } ) ;
80- expect ( statusSpy . firstCall . args ) . toEqual ( [ 404 ] ) ;
81+ sinon . assert . calledWith ( statusSpy , 404 ) ;
8182 } ) ;
8283
8384 it ( 'should redirect a locale exception at the root' , ( ) => {
@@ -87,9 +88,9 @@ describe('Prefix Middleware', () => {
8788 } ;
8889 prefixMiddleware ( fakeReq , fakeRes , fakeNext , { _config : fakeConfig } ) ;
8990
90- expect ( fakeRes . redirect . firstCall . args ) . toEqual ( [ 302 ,
91- '/firefox/downloads/file/224748/my-addon-4.9.21-fx%2Bsm.xpi' ] ) ;
92- expect ( fakeRes . set . firstCall . args ) . toEqual ( [ ' vary' , [ 'user-agent' ] ] ) ;
91+ sinon . assert . calledWith ( fakeRes . redirect , 302 ,
92+ '/firefox/downloads/file/224748/my-addon-4.9.21-fx%2Bsm.xpi' ) ;
93+ sinon . assert . calledWith ( fakeRes . vary , 'user-agent' ) ;
9394 } ) ;
9495
9596 it ( 'should redirect a locale exception nested in a valid locale' , ( ) => {
@@ -99,9 +100,9 @@ describe('Prefix Middleware', () => {
99100 } ;
100101 prefixMiddleware ( fakeReq , fakeRes , fakeNext , { _config : fakeConfig } ) ;
101102
102- expect ( fakeRes . redirect . firstCall . args ) . toEqual ( [ 302 ,
103- '/firefox/downloads/file/224748/my-addon-4.9.21-fx%2Bsm.xpi' ] ) ;
104- expect ( fakeRes . set . firstCall . args ) . toEqual ( [ ' vary' , [ 'user-agent' ] ] ) ;
103+ sinon . assert . calledWith ( fakeRes . redirect , 302 ,
104+ '/firefox/downloads/file/224748/my-addon-4.9.21-fx%2Bsm.xpi' ) ;
105+ sinon . assert . calledWith ( fakeRes . vary , 'user-agent' ) ;
105106 } ) ;
106107
107108 it ( 'should render a 404 when a clientApp URL exception is found' , ( ) => {
@@ -111,7 +112,7 @@ describe('Prefix Middleware', () => {
111112 } ;
112113 const statusSpy = sinon . spy ( fakeRes , 'status' ) ;
113114 prefixMiddleware ( fakeReq , fakeRes , fakeNext , { _config : fakeConfig } ) ;
114- expect ( statusSpy . firstCall . args ) . toEqual ( [ 404 ] ) ;
115+ sinon . assert . calledWith ( statusSpy , 404 ) ;
115116 } ) ;
116117
117118 it ( 'should set lang when invalid, preserving clientApp URL exception' , ( ) => {
@@ -120,8 +121,8 @@ describe('Prefix Middleware', () => {
120121 headers : { } ,
121122 } ;
122123 prefixMiddleware ( fakeReq , fakeRes , fakeNext , { _config : fakeConfig } ) ;
123- expect ( fakeRes . redirect . firstCall . args ) . toEqual ( [ 302 , '/en-US/developers/' ] ) ;
124- expect ( fakeRes . set . firstCall . args ) . toEqual ( [ ' vary' , [ ] ] ) ;
124+ sinon . assert . calledWith ( fakeRes . redirect , 302 , '/en-US/developers/' ) ;
125+ sinon . assert . notCalled ( fakeRes . vary ) ;
125126 } ) ;
126127
127128 it ( 'should render a 404 with clientApp exception' , ( ) => {
@@ -131,7 +132,7 @@ describe('Prefix Middleware', () => {
131132 } ;
132133 const statusSpy = sinon . spy ( fakeRes , 'status' ) ;
133134 prefixMiddleware ( fakeReq , fakeRes , fakeNext , { _config : fakeConfig } ) ;
134- expect ( statusSpy . firstCall . args ) . toEqual ( [ 404 ] ) ;
135+ sinon . assert . calledWith ( statusSpy , 404 ) ;
135136 } ) ;
136137
137138 it ( 'should fallback to and vary on accept-language headers' , ( ) => {
@@ -142,8 +143,8 @@ describe('Prefix Middleware', () => {
142143 } ,
143144 } ;
144145 prefixMiddleware ( fakeReq , fakeRes , fakeNext , { _config : fakeConfig } ) ;
145- expect ( fakeRes . redirect . firstCall . args ) . toEqual ( [ 302 , '/pt-BR/firefox/whatever' ] ) ;
146- expect ( fakeRes . set . firstCall . args [ 1 ] ) . toEqual ( [ 'accept-language' ] ) ;
146+ sinon . assert . calledWith ( fakeRes . redirect , 302 , '/pt-BR/firefox/whatever' ) ;
147+ sinon . assert . calledWith ( fakeRes . vary , 'accept-language' ) ;
147148 } ) ;
148149
149150 it ( 'should map aliased langs' , ( ) => {
@@ -152,7 +153,7 @@ describe('Prefix Middleware', () => {
152153 headers : { } ,
153154 } ;
154155 prefixMiddleware ( fakeReq , fakeRes , fakeNext , { _config : fakeConfig } ) ;
155- expect ( fakeRes . redirect . firstCall . args ) . toEqual ( [ 302 , '/pt-PT/firefox/whatever' ] ) ;
156+ sinon . assert . calledWith ( fakeRes . redirect , 302 , '/pt-PT/firefox/whatever' ) ;
156157 } ) ;
157158
158159 it ( 'should vary on accept-language and user-agent' , ( ) => {
@@ -163,8 +164,9 @@ describe('Prefix Middleware', () => {
163164 } ,
164165 } ;
165166 prefixMiddleware ( fakeReq , fakeRes , fakeNext , { _config : fakeConfig } ) ;
166- expect ( fakeRes . redirect . firstCall . args ) . toEqual ( [ 302 , '/pt-BR/firefox/whatever' ] ) ;
167- expect ( fakeRes . set . firstCall . args [ 1 ] ) . toEqual ( [ 'accept-language' , 'user-agent' ] ) ;
167+ sinon . assert . calledWith ( fakeRes . redirect , 302 , '/pt-BR/firefox/whatever' ) ;
168+ sinon . assert . calledWith ( fakeRes . vary , 'accept-language' ) ;
169+ sinon . assert . calledWith ( fakeRes . vary , 'user-agent' ) ;
168170 } ) ;
169171
170172 it ( 'should find the app based on ua string' , ( ) => {
@@ -175,8 +177,8 @@ describe('Prefix Middleware', () => {
175177 } ,
176178 } ;
177179 prefixMiddleware ( fakeReq , fakeRes , fakeNext , { _config : fakeConfig } ) ;
178- expect ( fakeRes . redirect . firstCall . args ) . toEqual ( [ 302 , '/en-US/android/whatever' ] ) ;
179- expect ( fakeRes . set . firstCall . args [ 1 ] ) . toEqual ( [ 'user-agent' ] ) ;
180+ sinon . assert . calledWith ( fakeRes . redirect , 302 , '/en-US/android/whatever' ) ;
181+ sinon . assert . calledWith ( fakeRes . vary , 'user-agent' ) ;
180182 } ) ;
181183
182184 it ( 'should populate res.locals for a valid request' , ( ) => {
@@ -187,7 +189,7 @@ describe('Prefix Middleware', () => {
187189 prefixMiddleware ( fakeReq , fakeRes , fakeNext , { _config : fakeConfig } ) ;
188190 expect ( fakeRes . locals . lang ) . toEqual ( 'en-US' ) ;
189191 expect ( fakeRes . locals . clientApp ) . toEqual ( 'firefox' ) ;
190- expect ( fakeRes . redirect . called ) . toBeFalsy ( ) ;
192+ sinon . assert . notCalled ( fakeRes . redirect ) ;
191193 } ) ;
192194
193195 it ( 'should not populate res.locals for a redirection' , ( ) => {
@@ -198,7 +200,7 @@ describe('Prefix Middleware', () => {
198200 prefixMiddleware ( fakeReq , fakeRes , fakeNext , { _config : fakeConfig } ) ;
199201 expect ( fakeRes . locals . lang ) . toEqual ( undefined ) ;
200202 expect ( fakeRes . locals . clientApp ) . toEqual ( undefined ) ;
201- expect ( fakeRes . redirect . called ) . toBeTruthy ( ) ;
203+ sinon . assert . called ( fakeRes . redirect ) ;
202204 } ) ;
203205
204206 it ( 'should not mangle a query string for a redirect' , ( ) => {
@@ -207,6 +209,7 @@ describe('Prefix Middleware', () => {
207209 headers : { } ,
208210 } ;
209211 prefixMiddleware ( fakeReq , fakeRes , fakeNext , { _config : fakeConfig } ) ;
210- expect ( fakeRes . redirect . firstCall . args ) . toEqual ( [ 302 , '/en-US/firefox/foo/bar?test=1&bar=2' ] ) ;
212+ sinon . assert . calledWith ( fakeRes . redirect , 302 ,
213+ '/en-US/firefox/foo/bar?test=1&bar=2' ) ;
211214 } ) ;
212215} ) ;
0 commit comments