0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-23 22:27:34 -05:00
verdaccio/test/webui/components/__mocks__/api.js
2018-01-07 07:59:36 +00:00

38 lines
814 B
JavaScript

/**
* API Mocks for WebUI
*/
import logo from '../store/logo';
import login from '../store/login';
import { packageMeta } from '../store/packageMeta';
/**
* Register mock api endpoints
* @param {string} endpoint
* @returns {Promise}
*/
const register = (method = 'get', endpoint, config = {}) => {
if (endpoint === 'login' && method === 'post') {
return login(config);
}
if (endpoint === 'logo' && method === 'get') {
return logo();
}
if (endpoint === 'sidebar/verdaccio' && method === 'get') {
return Promise.resolve({ data: packageMeta });
}
return Promise.reject({ status: 404, data: 'Not found' });
};
/**
* Bind API methods
*/
const API = ['get', 'post'].reduce((api, method) => {
api[method] = register.bind(null, method);
return api;
}, {});
export default API;