All files groceries.js

100% Statements 11/11
100% Branches 2/2
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 39 40 41 42 43 44 45 46                1x 1x   1x   1x   1x                     7x 7x 2x   5x                       2x 2x    
/**
 * Module for working with TheMealDB
 *
 * @module groceries
 */
 
'use strict';
 
const axios = require("axios");
const FuzzyMatching = require("fuzzy-matching")
 
const config = require("./config.json");
 
const Meal = require("./meal.js");
 
module.exports = {
  /**
   * Gets meal data for a specific meal
   *
   * @param meal {string}   String of meal
   * @returns {Meal}        Data pertaining to meal as a Meal object
   *
   * @example
   * getMealData("pork tacos");
   */
  getMealData: async function(meal) {
    const response = await axios.get(config.api_base_url + "search.php?s=" + meal);
    if (response.data.meals === null) {
      return {};
    }
    return new Meal(response.data.meals[0]);
  },
 
  /**
   * Gets data for a random meal
   *
   * @returns {Meal}        Data pertaining to meal as a Meal object
   *
   * @example
   * getRandomMeal();
   */
  getRandomMeal: async function() {
    const response = await axios.get(config.api_base_url + "random.php");
    return new Meal(response.data.meals[0]);
  }
};