mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-11-13 03:35:52 +01:00
9cd3ccb408
* fix: login without reload (#678) (#679) * fix: implements code review suggestions (#914) * refactor: adds scope to the app * refactor: handles null value from localstorage for username * refactor: removes text type from <Input /> * refactor: replaces isNull with isNil * refactor: improves makeLogin method * refactor: adds error from api constant * fix: updates error using API_ERROR constant in tests * refactor: updates regex for moduleMapper in jest config
49 lines
1.0 KiB
JavaScript
49 lines
1.0 KiB
JavaScript
/**
|
|
* API Mocks for WebUI
|
|
*/
|
|
import logo from '../store/logo';
|
|
import login from '../store/login';
|
|
import { packageMeta } from '../store/packageMeta';
|
|
import { packageInformation } from '../store/package';
|
|
|
|
/**
|
|
* Register mock api endpoints
|
|
* @param {string} endpoint
|
|
* @returns {Promise}
|
|
*/
|
|
const register = (url, method = 'get', options = {}) => {
|
|
|
|
if (url === 'login' && method.toLocaleLowerCase() === 'post') {
|
|
return login(options);
|
|
}
|
|
|
|
if (url === 'logo' && method.toLocaleLowerCase() === 'get') {
|
|
return logo();
|
|
}
|
|
|
|
if (url === 'sidebar/verdaccio' && method.toLocaleLowerCase() === 'get') {
|
|
return new Promise(function(resolve) {
|
|
resolve(packageMeta);
|
|
});
|
|
}
|
|
|
|
if (url === 'packages' && method.toLocaleLowerCase() === 'get') {
|
|
return new Promise(function (resolve) {
|
|
resolve(packageInformation);
|
|
});
|
|
}
|
|
|
|
throw Error(`URL not found: ${url}`);
|
|
};
|
|
|
|
/**
|
|
* Bind API methods
|
|
*/
|
|
class API {
|
|
request() {
|
|
return register.call(null, ...arguments);
|
|
}
|
|
}
|
|
|
|
export default new API;
|