Custom response based on headers
grug opened this issue · 3 comments
grug commented
I know there have been similar issues opened in here but I think this is slightly different (feel free to correct me here)
Is there a way to have multiple mocks for the same endpoint, but the responses are different based on headers
i.e.
a mock of GET /foo
that responds with {hello: 'world'}
AND
a mock of GET /foo
with an auth token in the request to respond with {something: 'else'}
Please let me know if my question is not clear enough and I'll provide more details.
Thanks
jameslnewell commented
Yeah!
mock.get('/foo', (req, res) => {
if (!req.header('Authorisation')) {
return res.body(JSON.stringify({hello: 'world'}));
} else {
return res.body(JSON.stringify({something: 'else'}));
}
});
grug commented
Oh, perfect!
grug commented
I'll give that a go and let you know :)