Skip to content

Commit

Permalink
fix test ad lint
Browse files Browse the repository at this point in the history
  • Loading branch information
wheresrhys committed Dec 28, 2019
1 parent befeef4 commit a6a3c80
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
18 changes: 14 additions & 4 deletions src/lib/compile-route.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const generateMatcher = require('./generate-matcher');


const isUrlMatcher = matcher => matcher instanceof RegExp || typeof matcher === 'string' || (typeof matcher === 'object' && 'href' in matcher)
const isUrlMatcher = matcher =>
matcher instanceof RegExp ||
typeof matcher === 'string' ||
(typeof matcher === 'object' && 'href' in matcher);

const sanitizeRoute = route => {
route = Object.assign({}, route);
Expand All @@ -10,15 +12,23 @@ const sanitizeRoute = route => {
route.method = route.method.toLowerCase();
}
if (isUrlMatcher(route.matcher)) {
route.url = route.matcher
route.url = route.matcher;
delete route.matcher;
}
route.identifier = route.name || route.url;
route.functionMatcher = route.matcher || route.functionMatcher;
return route;
};

const matcherTypes = ['query', 'method', 'headers', 'params', 'body', 'functionMatcher', 'url']
const matcherTypes = [
'query',
'method',
'headers',
'params',
'body',
'functionMatcher',
'url'
];

const validateRoute = route => {
if (!('response' in route)) {
Expand Down
3 changes: 1 addition & 2 deletions src/lib/generate-matcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ const getFullUrlMatcher = (route, matcherUrl, query) => {
};
};


const getFunctionMatcher = ({functionMatcher}) => functionMatcher;
const getFunctionMatcher = ({ functionMatcher }) => functionMatcher;

const getUrlMatcher = route => {
const { url: matcherUrl, query } = route;
Expand Down
12 changes: 7 additions & 5 deletions src/lib/set-up-and-tear-down.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
const compileRoute = require('./compile-route');
const FetchMock = {};

const isUrlMatcher = matcher => matcher instanceof RegExp || typeof matcher === 'string' || (typeof matcher === 'object' && 'href' in matcher)
const isFunctionMatcher = matcher => typeof matcher === 'function'
const isUrlMatcher = matcher =>
matcher instanceof RegExp ||
typeof matcher === 'string' ||
(typeof matcher === 'object' && 'href' in matcher);

const argsToRoute = args => {
const [matcher, response, options = {}] = args;

const routeConfig = {}
const routeConfig = {};

if (isUrlMatcher(matcher) || typeof matcher === 'function') {
routeConfig.matcher = matcher
routeConfig.matcher = matcher;
} else {
Object.assign(routeConfig, matcher);
}
Expand All @@ -19,7 +21,7 @@ const argsToRoute = args => {
routeConfig.response = response;
}

Object.assign(routeConfig, options)
Object.assign(routeConfig, options);

return routeConfig;
};
Expand Down
2 changes: 1 addition & 1 deletion test/specs/set-up-and-tear-down.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = fetchMock => {

describe('parameters', () => {
beforeEach(() => {
sinon.stub(fm, 'compileRoute').returns({});
sinon.spy(fm, 'compileRoute');
sinon.stub(fm, '_mock').returns(fm);
});

Expand Down

0 comments on commit a6a3c80

Please sign in to comment.