All files ci_source_helpers.js

100% Statements 6/6
100% Branches 4/4
100% Functions 4/4
100% Lines 6/6
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                        7x 12x   7x                   2x 2x   2x    
// @flow
"use strict"
 
import type { Env } from "./ci_source"
 
/**
 * Validates that all ENV keys exist and have a length
 * @param {Env} env The environment.
 * @param {[string]} keys Keys to ensure existence of
 * @returns {bool} true if they exist, false if not
*/
export function ensureEnvKeysExist(env: Env, keys: string[]) : boolean {
  let hasKeys = keys.map((key: string) : boolean => {
    return env.hasOwnProperty(key) && env[key].length > 0
  })
  return !hasKeys.includes(false)
}
 
/**
 * Validates that all ENV keys exist and can be turned into ints
 * @param {Env} env The environment.
 * @param {[string]} keys Keys to ensure existence and number-ness of
 * @returns {bool} true if they are all good, false if not
*/
export function ensureEnvKeysAreInt(env: Env, keys: string[]) : boolean {
  let hasKeys = keys.map((key: string) : boolean => {
    return env.hasOwnProperty(key) && !isNaN(parseInt(env.TRAVIS_PULL_REQUEST))
  })
  return !hasKeys.includes(false)
}