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

46 lines
877 B
JavaScript
Raw Normal View History

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}
*/
const register = (url, method = 'get', options = {}) => {
2017-12-01 14:04:01 -05:00
if (url === 'login' && method.toLocaleLowerCase() === 'post') {
return login(options);
2017-12-01 14:04:01 -05:00
}
if (url === 'logo' && method.toLocaleLowerCase() === 'get') {
2017-12-01 14:04:01 -05:00
return logo();
}
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
}
throw Error('Not found');
2017-12-01 14:04:01 -05:00
};
/**
* Bind API methods
*/
class API {
request() {
return register.call(null, ...arguments);
}
}
2017-12-01 14:04:01 -05:00
export default new API;