1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-17 07:45:52 +01:00
verdaccio/test/unit/webui/components/__mocks__/api.js

49 lines
1.0 KiB
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';
import { packageInformation } from '../store/package';
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(packageMeta);
});
2017-12-20 05:10:53 +01:00
}
if (url === 'packages' && method.toLocaleLowerCase() === 'get') {
return new Promise(function (resolve) {
resolve(packageInformation);
});
}
throw Error(`URL not found: ${url}`);
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;