Add Meal to Day

POST {{url}}/meal

Pick one of the food items and assign to Meal m without repetition

Pre-request Script: ``` var m = environment.m ? _.parseInt(environment.m) : 1, // which meal of the day, defaulting to 1 // Remaining food items, which haven't already been fed to the dog today todayItems = environment.todayItems ? JSON.parse(environment.todayItems) : JSON.parse(environment.items), // Randomly choose one of the remaining food items foodItem = _.sample(todayItems);

// Remove the selected foodItem from contention for the rest of the day _.pull(todayItems, foodItem); Qodex.setEnvironmentVariable(m, m); Qodex.setEnvironmentVariable(foodItem, foodItem); Qodex.setEnvironmentVariable(todayItems, JSON.stringify(todayItems)); ```

Test Script: ``` tests[Status code is 200] = (responseCode.code === 200);

if (responseCode.code === 200) { // Increment meal counter by 1 var m = _.parseInt(environment.m) + 1, d = _.parseInt(environment.d);

// If last meal of the day
if (m === 4) {
    Qodex.setEnvironmentVariable("m", 1);
    Qodex.setEnvironmentVariable("todayItems", "");
    // If not last day of the week, return to Create Day Log to set meals for the next day
    // otherwise end the workflow, by not setting the Next Request
    if (d < 7) {
        Qodex.setNextRequest("Create Day Log");
    }
    else {
        Qodex.setEnvironmentVariable("d", 0);
        // Terminate execution
        Qodex.setNextRequest(null);
    }
}
// otherwise loop for the subsequent meal
else {
    Qodex.setEnvironmentVariable("m", m);
    Qodex.setNextRequest("Add Meal to Day");
}

} else { // Stop execution Qodex.setNextRequest(null); } ```

Request Body

[{"name"=>"meal_item", "value"=>"{{foodItem}}", "datatype"=>"string"}, {"name"=>"day", "value"=>"{{d}}", "datatype"=>"string"}, {"name"=>"meal", "value"=>"{{m}}", "datatype"=>"string"}, {"name"=>"run_id", "value"=>"{{run_id}}", "datatype"=>"string"}]

RESPONSES

status: OK

{&quot;a&quot;:2}