0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-13 22:48:31 -05:00
verdaccio/test/webui/components/__mocks__/api.js

46 lines
877 B
JavaScript
Raw Normal View History

2017-12-02 00:34:01 +05:30
/**
* API Mocks for WebUI
*/
import logo from '../store/logo';
import login from '../store/login';
2017-12-20 09:40:53 +05:30
import { packageMeta } from '../store/packageMeta';
2017-12-02 00:34:01 +05:30
/**
* Register mock api endpoints
* @param {string} endpoint
* @returns {Promise}
*/
const register = (url, method = 'get', options = {}) => {
2017-12-02 00:34:01 +05:30
if (url === 'login' && method.toLocaleLowerCase() === 'post') {
return login(options);
2017-12-02 00:34:01 +05:30
}
if (url === 'logo' && method.toLocaleLowerCase() === 'get') {
2017-12-02 00:34:01 +05:30
return logo();
}
if (url === 'sidebar/verdaccio' && method.toLocaleLowerCase() === 'get') {
return new Promise(function(resolve) {
resolve({
json: function() {
return packageMeta;
}
});
});
2017-12-20 09:40:53 +05:30
}
throw Error('Not found');
2017-12-02 00:34:01 +05:30
};
/**
* Bind API methods
*/
class API {
request() {
return register.call(null, ...arguments);
}
}
2017-12-02 00:34:01 +05:30
export default new API;