Skip to content
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

Tor & Wenjie - VideoStore - Octos #6

Open
wants to merge 25 commits into
base: master
Choose a base branch
from

Conversation

torshimizu
Copy link

Video Store API

Congratulations! You're submitting your assignment!
If you didn't get to the functionality the question is asking about, reply with what you would have done if you had completed it.

Comprehension Questions

Question Answer
Explain how you came up with the design of your ERD, based on the seed data. At first we did not use the seed data, so we had to go back and add some fields to our models (like movies checked out count). We worked off of the project README, and built our relations that way.
Describe a set of positive and negative test cases you implemented for a model. Positive test case: A movie can be created with sufficient data. Negative test case: a movie cannot be created without a title or with a negative inventory.
Describe a set of positive and negative test cases you implemented for a controller. Positive test case: For show, a single movie's details will be shown when the movie is found. Negative test case: a not found status would be sent with error text if the movie was not found.
How does your API respond when bad data is sent to it? If bad data is sent, we respond with error text in a hash and send a status code of bad_request or not_found (if the id was not found).
Describe one of your custom model methods and why you chose to wrap that functionality into a method. We have a method to find a rental with a given movie and customer id that has not yet been checked in. This method is used by our Rentals controller for when a movie is checked in. We decided to put this in the model so that we can do further testing and it can also be reused if we ever needed to modify or update the rental information.
Do you have any recommendations on how we could improve this project for the next cohort? Do something different than a Video Store - something more fun.
Link to Trello https://trello.com/b/yLm7THn3/video-store-api
Link to ERD https://www.lucidchart.com/documents/edit/6cce0be7-55f5-4c57-9b0e-6d6c83d5c2e6

torshimizu and others added 25 commits May 7, 2018 12:00
Implemented tests for customer model validations
Implemented tests for controller movies, all passed
… rental, wrote tests for additional validations
Modified tests for rental controller
Added another column in rental model
Implemented tests for business logic
@droberts-sea
Copy link

Video Store

What We're Looking For

Feature Feedback
Core Requirements
Git hygiene yes
Comprehension questions yes
General
Business Logic in Models yes - good work
All required endpoints return expected JSON data yes
Requests respond with appropriate HTTP Status Code yes
Errors are reported yes
Testing
Passes all Smoke Tests yes
Model Tests - all relations, validations, and custom functions test positive & negative cases yes
Controller Tests - URI parameters and data in the request body have positive & negative cases some edge cases missing, but generally good.
Overall Good work overall.

def same_name_and_same_phone
customers = Customer.where(name: name)

if customers.any? {|customer| customer.phone == phone}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rails supports this natively:

validates :phone, uniqueness: { scope: :name }

def has_enough_inventory?
unless self.movie.available_inventory > 0
errors[:quantity] << 'Not enough inventory for this rental'
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work on this custom validation

def self.find_checked_out_movie(movie_id, customer_id)
rental = Rental.where(movie_id: movie_id, customer_id: customer_id, check_in_date: nil)
return rental.empty? ? nil : rental.first
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good use of model methods here. I might take it a step further and have something like Rental.checkout(movie_id, customer_id) and Rental.checkin(movie_id, customer_id), which encapsulate all of the work in one place. You could even wrap the whole thing in a transaction.

def self.update_movie_and_customer(rental)

if rental.check_in_date.nil?
new_inventory = rental.movie.available_inventory - 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like it should be an instance method, since it requires an instance to run.


it 'returns bad request and error text for bad data' do
rental_data = {
movie_id: movies(:one).id,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the movie doesn't have enough inventory left in stock?

it "return bad request and error if the rental DNE" do
rental = rentals(:one)
rental_data = {
movie_id: rental.movie_id + 100,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about a rental that has already been checked in? What if there are multiple rentals for the same movie-customer pair?

it "returns nil if the rental DNE" do
rental = rentals(:one)
movie_id = rental.movie_id + 100
customer_id = rental.customer_id

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the rental has been checked in?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants