Skip to content

Commit

Permalink
Failing test: escaping inconsistent to requestInterceptor
Browse files Browse the repository at this point in the history
For: #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
  • Loading branch information
srl295 committed May 4, 2020
1 parent 0340b15 commit 5e17a17
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,8 @@ describe('constructor', () => {
$ref: 'http://petstore.swagger.io/v2/ref.json#b'
}
))
.get('http://petstore.swagger.io/v2/user/\'', () => ({u: 'quote'})) // Not hit, this is the URL the interceptor sees.
.get('http://petstore.swagger.io/v2/user/%27', () => ({u: 'percent-twentyseven'})) // We actually get this.
})

test('should support request interceptor', (cb) => {
Expand Down Expand Up @@ -646,5 +648,25 @@ describe('constructor', () => {
}).catch(cb)
}
)
test(
'should give the interceptor the URL which actually hits the network',
(cb) => {
new Swagger({
url: 'http://petstore.swagger.io/v2/swagger.json',
requestInterceptor: (req) => {
if (req.url === 'http://petstore.swagger.io/v2/swagger.json') {
return req // skip this
}
expect(req.url).toEqual('http://petstore.swagger.io/v2/user/\'') // Not percent-escaped
return req
}
}).then(client =>
client.apis.user.getUserByName({username: '\''}).then((data) => {
expect(data.body.u).toEqual('quote') // not percent escaped
cb()
})
).catch(cb)
}
)
})
})

0 comments on commit 5e17a17

Please sign in to comment.