forked from sombochea/verdaccio-ui
chore: sync with verdaccio master
This commit is contained in:
48
test/unit/webui/components/__mocks__/api.js
Normal file
48
test/unit/webui/components/__mocks__/api.js
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* 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;
|
||||
26
test/unit/webui/components/__mocks__/token.js
Normal file
26
test/unit/webui/components/__mocks__/token.js
Normal file
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Token Utility
|
||||
*/
|
||||
|
||||
import { Base64 } from 'js-base64';
|
||||
import addHours from 'date-fns/add_hours';
|
||||
|
||||
export function generateTokenWithTimeRange (limit = 0) {
|
||||
const payload = {
|
||||
username: 'verdaccio',
|
||||
exp: Number.parseInt(addHours(new Date(), limit).getTime() / 1000, 10)
|
||||
};
|
||||
return `xxxxxx.${Base64.encode(JSON.stringify(payload))}.xxxxxx`;
|
||||
}
|
||||
|
||||
export function generateTokenWithExpirationAsString () {
|
||||
const payload = { username: 'verdaccio', exp: 'I am not a number' };
|
||||
return `xxxxxx.${Base64.encode(payload)}.xxxxxx`;
|
||||
}
|
||||
|
||||
export function generateTokenWithOutExpiration (){
|
||||
const payload = {
|
||||
username: 'verdaccio'
|
||||
};
|
||||
return `xxxxxx.${Base64.encode(JSON.stringify(payload))}.xxxxxx`;
|
||||
}
|
||||
Reference in New Issue
Block a user