-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: fieldKeyParser: make clearer assertions about url manipulation #1291
base: master
Are you sure you want to change the base?
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of having createRequest()
automatically specify originalUrl
by prepending /v1 to url
, could we just have individual tests specify originalUrl
when they need to? I only see three sets of tests that specify url
at all:
versionParser()
fieldKeyParser()
odataPreprocessor()
I don't think versionParser()
needs access to originalUrl
. For the tests of odataPreprocessor()
, I don't think it makes a ton of sense to prepend /v1 to url
: the url
s are things like '/odata.svc?$format=json'
.
What do you think about adding a utility function just for the tests of fieldKeyParser()
? Those seem to be the only ones that actually use originalUrl
. I'm thinking of something similar to createPreVersionParserRequest()
:
const createFieldKeyParserRequest = ({ url, ...props }) =>
if (originalUrl) throw new Error('Should not specify originalUrl');
return createRequest({ url, originalUrl: `/v1${url}`, ...props });
};
Maybe we could come back to the idea of automatically specifying originalUrl
if/when we have more tests that need that.
We could, but it's allows people to forget to do specify it.
It's true, but to understand that these tests do not need |
I see what you're saying, but I think there's potential for confusion if our version of We don't have that many preprocessors, and there's only one preprocessor where there's a problem with the tests. I think it'd be better to wait to modify Just to throw out another idea, what do you think about wrapping the request in a proxy that gates the const guardOriginalUrl = {
get: (request, prop) => {
if (prop === 'originalUrl')
throw new Error('no originalUrl was passed to createRequest()');
return request[prop];
},
set: (request, prop, value) => {
request[prop] = value;
return true;
}
};
const createRequest = options => {
// ...
const request = wrapped.createRequest({ ...options, query: qs.parse(search.substr(1)) });
return options.originalUrl != null ? request : new Proxy(request, guardOriginalUrl);
}; |
No description provided.