Skip to content

Commit

Permalink
Merge pull request #34 from josephlee702/spec/movie_service_spec
Browse files Browse the repository at this point in the history
add spec for movie service
  • Loading branch information
josephlee702 authored Dec 2, 2023
2 parents 17f72f1 + 5a9ca14 commit 7f835a2
Show file tree
Hide file tree
Showing 7 changed files with 366 additions and 33 deletions.
48 changes: 24 additions & 24 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions spec/fixtures/vcr_cassettes/cast.yml

Large diffs are not rendered by default.

69 changes: 69 additions & 0 deletions spec/fixtures/vcr_cassettes/movie_details.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions spec/fixtures/vcr_cassettes/reviews.yml

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions spec/fixtures/vcr_cassettes/search_movies.yml

Large diffs are not rendered by default.

9 changes: 0 additions & 9 deletions spec/services/movie_service.rb

This file was deleted.

96 changes: 96 additions & 0 deletions spec/services/movie_service_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
require 'rails_helper'

RSpec.describe MovieService do
describe 'class methods' do
before(:each) do
@user = User.create(name: 'Joseph', email: 'jlee230@turing.edu')
end

context '#conn' do
it 'returns a Faraday connection' do
conn = MovieService.conn

expect(conn).to be_a(Faraday::Connection)
end
end

context '#get_url' do
it 'returns a parsed response' do
VCR.use_cassette('top_rated_movies') do
response = MovieService.get_url('/3/movie/top_rated')

expect(response).to be_a(Hash)
expect(response).to have_key(:results)
end
end
end

context '#top_rated' do
it 'returns the top rated movies' do
VCR.use_cassette('top_rated_movies') do
movies = MovieService.top_rated[:results]

expect(movies).to be_an(Array)
expect(movies.first).to be_a(Hash)
expect(movies.first).to have_key(:title)
expect(movies.first).to have_key(:vote_average)
end
end
end

context 'search' do
it 'returns movies based on search term' do
VCR.use_cassette('search_movies') do
movies = MovieService.search('The Matrix')[:results]

expect(movies).to be_an(Array)
expect(movies.first).to be_a(Hash)
expect(movies.first).to have_key(:title)
expect(movies.first[:title]).to include('Matrix')
end
end
end

context 'movie_details' do
it 'returns movie details' do
VCR.use_cassette('movie_details') do
movie = MovieService.movie_details(603)

expect(movie).to be_a(Hash)
expect(movie.first).to be_an(Array)

expect(movie).to have_key(:title)
expect(movie).to have_key(:id)
expect(movie).to have_key(:runtime)
end
end
end

context 'cast' do
it 'returns cast members' do
VCR.use_cassette('cast') do
cast = MovieService.cast(603)[:cast]

expect(cast).to be_an(Array)
expect(cast.first).to be_a(Hash)

expect(cast.first).to have_key(:name)
expect(cast.first).to have_key(:character)
end
end
end

context 'reviews' do
it 'returns reviews' do
VCR.use_cassette('reviews') do
reviews = MovieService.reviews(603)[:results]

expect(reviews).to be_an(Array)
expect(reviews.first).to be_a(Hash)
expect(reviews.first).to have_key(:author)
expect(reviews.first).to have_key(:content)
end
end
end
end
end

0 comments on commit 7f835a2

Please sign in to comment.