2017-12-01 14:04:01 -05:00
|
|
|
/**
|
|
|
|
* API Mocks for WebUI
|
|
|
|
*/
|
|
|
|
import logo from '../store/logo';
|
|
|
|
import login from '../store/login';
|
2017-12-19 23:10:53 -05:00
|
|
|
import { packageMeta } from '../store/packageMeta';
|
2017-12-01 14:04:01 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Register mock api endpoints
|
|
|
|
* @param {string} endpoint
|
|
|
|
* @returns {Promise}
|
|
|
|
*/
|
2018-03-21 15:44:19 -05:00
|
|
|
const register = (url, method = 'get', options = {}) => {
|
2017-12-01 14:04:01 -05:00
|
|
|
|
2018-03-21 15:44:19 -05:00
|
|
|
if (url === 'login' && method.toLocaleLowerCase() === 'post') {
|
|
|
|
return login(options);
|
2017-12-01 14:04:01 -05:00
|
|
|
}
|
|
|
|
|
2018-03-21 15:44:19 -05:00
|
|
|
if (url === 'logo' && method.toLocaleLowerCase() === 'get') {
|
2017-12-01 14:04:01 -05:00
|
|
|
return logo();
|
|
|
|
}
|
|
|
|
|
2018-03-21 15:44:19 -05:00
|
|
|
if (url === 'sidebar/verdaccio' && method.toLocaleLowerCase() === 'get') {
|
|
|
|
return new Promise(function(resolve) {
|
|
|
|
resolve({
|
|
|
|
json: function() {
|
|
|
|
return packageMeta;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2017-12-19 23:10:53 -05:00
|
|
|
}
|
|
|
|
|
2018-03-21 15:44:19 -05:00
|
|
|
throw Error('Not found');
|
2017-12-01 14:04:01 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bind API methods
|
|
|
|
*/
|
2018-03-21 15:44:19 -05:00
|
|
|
class API {
|
|
|
|
request() {
|
|
|
|
return register.call(null, ...arguments);
|
|
|
|
}
|
|
|
|
}
|
2017-12-01 14:04:01 -05:00
|
|
|
|
2018-03-21 15:44:19 -05:00
|
|
|
export default new API;
|