-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jamila Octos c9 #36
base: master
Are you sure you want to change the base?
Jamila Octos c9 #36
Conversation
I know I didnt get to controller tests and some of my other tests have probably broken due to adding the show page functionality. I also needed and wanted to add a test to the wrapper tests for the new method I created. I meant to at least put some flex css for the pagination and make my form view into a partial so I could better place it when I added more css later. |
API MuncherWhat We're Looking For
Good work overall. It's clear that the the core learning goal for the assignment around interacting with an API was met. I also really like your lib tests - good job on this! There are two places I see room for improvement. The first is in error handling - making sure that you've got a comprehensive story for how errors get from the bottom layer (the API) all the way back to the user is not easy, but it's a piece of what sets apart a really strong application. The other place is controller testing, which you're aware of. Fortunately these are both major components of the VideoStore API project - please spend some time focusing on these concepts this week. I've seen you putting in a large amount of work recently, and I think it really shows on this assignment. This submission represents a big improvement over where you were a couple weeks ago. Keep it up! |
root 'edamams#new' | ||
get '/recipe/new', to: 'edamams#new' | ||
get '/recipe/index', to: 'edamams#index', as: 'recipe_list' | ||
get '/recipe/:uri', to: 'edamams#show', as: 'recipe_details' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that new
is a good name for this route/action. You're not really creating a new recipe, you're doing a search.
Also, could you use resources
for the index and show pages?
raise_error(source) | ||
raise_error(uri) | ||
raise_error(url) | ||
raise_error(ingredientLines) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say you're over-validating here. In general you should only validate fields that will cause your app to break if they're not there. In this case that's label
, uri
and possibly image
. Anything beyond that is an unnecessary dependency on the data coming from the API, and is an extra thing for you to test.
def self.raise_on_error(response) | ||
# this needs to be changed based on the api | ||
unless response["more"] | ||
raise RecipeError.new(response["error"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that Edamam gives error messages back under the error
key like this.
full_uri = URI.encode("https://api.edamam.com/search?r=#{BASE_URI}#{uri}&app_id=#{TOKEN_ID}&app_key=#{TOKEN_KEY}") | ||
|
||
response = HTTParty.get(full_uri).parsed_response | ||
return Recipe.from_api(response[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should check that the API call succeeded before calling Recipe.from_api
here.
def index | ||
recipe_list = RecipeApiWrapper.recipes(params[:recipe]) | ||
@recipe_list = Kaminari.paginate_array(recipe_list).page(params[:page]).per(10) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've written your API wrapper to raise an error if the API call fails, but you're not looking for an error here. You should wrap this call in a begin
/rescue
.
|
||
it "raises and error if query is empty" do | ||
VCR.use_cassette('recipes') do | ||
query = ' ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good error case
describe "single recipe" do | ||
it "" do | ||
|
||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two tests I would want to see here:
- Do you get an instance of class
Recipe
back with a valid URI? - What happens when you pass in a bogus URI?
|
||
describe EdamamsController do | ||
# it "must be a real test" do | ||
# flunk "Need real tests" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need some controller tests! Here is my list of what I'm looking for:
Index:
- Valid search term
- Search term that produces no results (e.g.
adfohdaglhjalj
) - No search term
Show:
- Valid URI
- Bogus URI
- No URI
Root
- Does it work at all (only one test)
API Muncher
Congratulations! You're submitting your assignment!
Comprehension Questions