Skip to content

Commit

Permalink
Create test for GET avg_calories route
Browse files Browse the repository at this point in the history
Co-Authored-By: S. Mainar <[email protected]>
  • Loading branch information
sejinkim1904 and smainar committed Oct 14, 2019
1 parent 658e516 commit 33ffe15
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/recipes/get_avg_calories_request.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const shell = require('shelljs');
const request = require('supertest');
const app = require('../../app');
const recipeResponse = require("../../__fixtures__/chicken_recipes");
const mockAxios = require('axios');
const recipe = require('../../models').Recipe;

describe('Recipes API', () => {
describe('Average calories GET request', () => {
beforeEach(async () => {
await recipe.destroy({where: {}});
});
afterEach(async () => {
await recipe.destroy({where: {}});
});

test('It returns average calories for food type', () => {
mockAxios.get.mockImplementationOnce(() =>
Promise.resolve(recipeResponse)
);

return request(app).get('/api/v1/recipes/avg_calories?q=chicken')
.then(response => {
expect(response.status).toBe(200)
expect(response.body.averageCalories).toBe(4113.29)
});
});
});
});

0 comments on commit 33ffe15

Please sign in to comment.