Skip to content

Commit c4fac2d

Browse files
committed
Failing test: escaping inconsistent to requestInterceptor
For: swagger-api#1220 `npm t` gives: > Error: Expected 'percent-twentyseven' to equal 'quote' * Request has a quote (') in it * The interceptor sees req.url ending in quote (') which is a perfectly valid thing for a URL to end in… * However, the xmock shows the actual URL ends in /%27
1 parent 0e64492 commit c4fac2d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/index.js

+19
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,8 @@ describe('constructor', () => {
530530
$ref: 'http://petstore.swagger.io/v2/ref.json#b'
531531
}
532532
))
533+
.get('http://petstore.swagger.io/v2/user/\'', () => ({u: 'quote'})) // Not hit, this is the URL the interceptor sees.
534+
.get('http://petstore.swagger.io/v2/user/%27', () => ({u: 'percent-twentyseven'})) // We actually get this.
533535
})
534536

535537
it('should support request interceptor', function (cb) {
@@ -601,5 +603,22 @@ describe('constructor', () => {
601603
cb()
602604
}).catch(cb)
603605
})
606+
607+
it('should give the interceptor the URL which actually hits the network', () =>
608+
new Swagger({
609+
url: 'http://petstore.swagger.io/v2/swagger.json',
610+
requestInterceptor: (req) => {
611+
if (req.url === 'http://petstore.swagger.io/v2/swagger.json') {
612+
return req // skip this
613+
}
614+
expect(req.url).toEqual('http://petstore.swagger.io/v2/user/\'') // Not percent-escaped
615+
return req
616+
}
617+
}).then(client =>
618+
client.apis.user.getUserByName({username: '\''}).then((data) => {
619+
expect(data.body.u).toEqual('quote') // not percent escaped
620+
})
621+
)
622+
)
604623
})
605624
})

0 commit comments

Comments
 (0)