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 Feb 27, 2018
1 parent 0e64492 commit 974ba2a
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 @@ -2,6 +2,9 @@ import expect, {createSpy} from 'expect'
import xmock from 'xmock'
import Swagger from '../src/index'

// only used for the WORKAROUND (see below)
import url from 'url'

describe('constructor', () => {
afterEach(function () {
expect.restoreSpies()
Expand Down Expand Up @@ -530,6 +533,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.
})

it('should support request interceptor', function (cb) {
Expand Down Expand Up @@ -601,5 +606,22 @@ describe('constructor', () => {
cb()
}).catch(cb)
})

it('should give the interceptor the URL which actually hits the network', () =>
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
})
)
)
})
})

0 comments on commit 974ba2a

Please sign in to comment.