All files / src utils.js

100% Statements 15/15
50% Branches 1/2
100% Functions 6/6
100% Lines 15/15

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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 531x   7x 7x     1x   7x 7x     1x 3x 3x     1x 3x 3x         1x   2x                     2x                              
const convertGreenHouseGasesEmission = (value, visits) => {
  // greenhouseGasesEmission is in g
  const input = 90; // 90g CO2 /km (gCO2e)
  return Math.round((value * visits) / input);
};
 
const convertWater = (value, visits) => {
  // waterConsumption is in cl
  const input = 60; // 60L / douche
  return Math.round(((value / 100) * visits) / input);
};
 
const getComplementaryGESInfo = (greenhouseGasesEmission, options) => {
  const convertedValue = convertGreenHouseGasesEmission(greenhouseGasesEmission, options.visits);
  return `Pour un total de ${options.visits} visites par mois, ceci correspond à ${convertedValue}km en voiture (Peugeot 208 5P 1.6 BlueHDi FAP (75ch) BVM5)`;
};
 
const getComplementaryWaterInfo = (waterConsumption, options) => {
  const convertedValue = convertWater(waterConsumption, options.visits);
  return `Pour un total de ${options.visits} visites par mois, ceci correspond à ${convertedValue} douche${
    convertedValue > 1 ? "s" : ""
  }`;
};
 
module.exports = {
  getComplementaryGESInfoAndDetails: (greenhouseGasesEmission, options) => {
    return {
      comment: getComplementaryGESInfo(greenhouseGasesEmission, options),
      commentDetails: {
        numberOfVisit: options.visits,
        value_km: convertGreenHouseGasesEmission(greenhouseGasesEmission, options.visits),
        value: convertGreenHouseGasesEmission(greenhouseGasesEmission, options.visits),
        unit: 'km'
      },
    };
  },
  getComplementaryWaterInfoAndDetails: (waterConsumption, options) => {
    return {
      comment: getComplementaryWaterInfo(waterConsumption, options),
      commentDetails: {
        numberOfVisit: options.visits,
        value_shower: convertWater(waterConsumption, options.visits),
        value: convertWater(waterConsumption, options.visits),
        unit: 'douches'
      },
    };
  },
 
  getComplementaryGESInfo,
 
  getComplementaryWaterInfo,
};