All files / src/modules showVersionedPackage.js

100% Statements 11/11
100% Branches 3/3
100% Functions 2/2
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 34 35 36 37 38                          7x   3x 3x 3x 3x   3x         12x   3x   1x   1x   1x        
import validateOptions from './validateOptions';
/**
 * Get package information for RubyGem, Python, and Java packages.
 * @module src/modules/showVersionedPackage
 * @param {Object} superagent request object.
 * @param {Object} options - Repository options.
 * @param {string} options.repo - The fully-qualified repository name, i.e., 'username/reponame'.
 * @param {string} options.type - The type of package, supported types: gem, python, java.
 * @param {string} options.packageName - The name of the package.
 * @param {string} options.version - The version number of the package.
 * @return {Promise} The superagent promise object.
 */
export default (request, options) => {
  validateOptions(options, ['repo', 'type', 'packageName', 'version']);
 
  let repo = options.repo,
      name = options.packageName,
      version = options.version,
      packageType = privateMethods.versionedPackageString(options.type);
 
  return request.get([options.baseUrl + "repos",
                      repo, "package", packageType,
                      name, version + ".json"].join("/"));
}
 
const privateMethods = {
  versionedPackageString(string) {
    switch (string) {
    case "java":
      return "java/maven2";
    case "gem":
      return string;
    case "python":
      return string;
    }
  }
}