1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-13 03:35:52 +01:00
verdaccio/test/webui/components/__mocks__/api.js

46 lines
877 B
JavaScript
Raw Normal View History

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