-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create test for GET avg_calories route
Co-Authored-By: S. Mainar <[email protected]>
- Loading branch information
1 parent
658e516
commit 33ffe15
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}); | ||
}); | ||
}); | ||
}); |