router.js
507 Bytes
export const matchMockHandler = (handler, context) => {
const matchedMethod = !handler.method || String(handler.method).toUpperCase() === context.method
const matchedAction = !handler.action || String(handler.action) === context.action
const matchedType = !handler.type || String(handler.type) === context.type
return matchedMethod && matchedAction && matchedType
}
export const findMockHandler = (handlers, context) => (
handlers.find((handler) => matchMockHandler(handler, context)) || null
)