Skip to content

Commit

Permalink
test: add quote test
Browse files Browse the repository at this point in the history
Refs #1252
  • Loading branch information
char0n committed Sep 12, 2023
1 parent ea08df2 commit f9207bd
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 7 deletions.
63 changes: 58 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
"formdata-node": "^4.0.0",
"is-plain-object": "^5.0.0",
"js-yaml": "^4.1.0",
"node-fetch-cjs": "^3.2.10",
"node-fetch-commonjs": "^3.3.1",
"qs": "^6.10.2",
"traverse": "~0.6.6",
"undici": "^5.24.0"
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/fetch-ponyfill-node-fetch.node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// we cannot use `node-fetch@3` as it's pure ESM package not compatible with CommonJS
import fetch, { Response, Headers, Request } from 'node-fetch-cjs';
import fetch, { Response, Headers, Request } from 'node-fetch-commonjs';

export { fetch, Response, Headers, Request };
32 changes: 32 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,16 @@ describe('constructor', () => {
{ $ref: 'http://petstore.swagger.io/v2/ref.json#b' },
{ headers: { 'Content-Type': 'application/json' } }
);
mockPool
.intercept({ path: "/v2/user/'" })
.reply(200, { u: 'quote' }, { headers: { 'Content-Type': 'application/json' } });
mockPool
.intercept({ path: '/v2/user/%27' })
.reply(
200,
{ u: 'percent-twentyseven' },
{ headers: { 'Content-Type': 'application/json' } }
);
});

test('should support request interceptor', (cb) => {
Expand Down Expand Up @@ -712,6 +722,28 @@ describe('constructor', () => {
})
.catch(cb);
});

test('should give the interceptor the URL which actually hits the network', (done) => {
expect.assertions(2);

new SwaggerClient({
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
done();
})
)
.catch(done);
});
});

describe('skipNormalization', () => {
Expand Down

0 comments on commit f9207bd

Please sign in to comment.