Skip to content

Commit 5e17a17

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 0340b15 commit 5e17a17

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

test/index.js

+22
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,8 @@ describe('constructor', () => {
566566
$ref: 'http://petstore.swagger.io/v2/ref.json#b'
567567
}
568568
))
569+
.get('http://petstore.swagger.io/v2/user/\'', () => ({u: 'quote'})) // Not hit, this is the URL the interceptor sees.
570+
.get('http://petstore.swagger.io/v2/user/%27', () => ({u: 'percent-twentyseven'})) // We actually get this.
569571
})
570572

571573
test('should support request interceptor', (cb) => {
@@ -646,5 +648,25 @@ describe('constructor', () => {
646648
}).catch(cb)
647649
}
648650
)
651+
test(
652+
'should give the interceptor the URL which actually hits the network',
653+
(cb) => {
654+
new Swagger({
655+
url: 'http://petstore.swagger.io/v2/swagger.json',
656+
requestInterceptor: (req) => {
657+
if (req.url === 'http://petstore.swagger.io/v2/swagger.json') {
658+
return req // skip this
659+
}
660+
expect(req.url).toEqual('http://petstore.swagger.io/v2/user/\'') // Not percent-escaped
661+
return req
662+
}
663+
}).then(client =>
664+
client.apis.user.getUserByName({username: '\''}).then((data) => {
665+
expect(data.body.u).toEqual('quote') // not percent escaped
666+
cb()
667+
})
668+
).catch(cb)
669+
}
670+
)
649671
})
650672
})

0 commit comments

Comments
 (0)