All files / src/containers/ApiCalls ApiKey.js

100% Statements 11/11
100% Branches 8/8
100% Functions 3/3
100% Lines 11/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33          27x 7x     20x 1x     19x         7x       19x 1x     18x 1x     17x    
import is from 'is_js';
import ApiAction from './ApiAction';
 
export default class ApiKey {
  static create(param) {
    if (ApiAction.isApiAction(param)) {
      return createFromApiAction(param);
    }
 
    if (is.not.object(param)) {
      throw new Error('Expected an ApiAction or an object');
    }
 
    return createFromObject(param);
  }
}
 
function createFromApiAction(apiAction) {
  return `${apiAction.method} ${apiAction.url}`;
}
 
function createFromObject({ method, url }) {
  if (is.not.string(method)) {
    throw new Error('The method property should be a string');
  }
 
  if (is.not.string(url)) {
    throw new Error('The url property should be a string');
  }
 
  return `${method.toUpperCase()} ${url.toLowerCase()}`;
}