diff --git a/spec/controllers/collections_controller_spec.rb b/spec/controllers/collections_controller_spec.rb index 4914a8f..b8b0841 100644 --- a/spec/controllers/collections_controller_spec.rb +++ b/spec/controllers/collections_controller_spec.rb @@ -1,5 +1,23 @@ require 'rails_helper' RSpec.describe CollectionsController, type: :controller do + context "Collections" do + let(:current_user){create(:user)} + let(:another_user){create(:user)} + let(:collection){create(:collection)} + let(:collection2){create(:collection)} + it "Validate the 401 status when the user tries to access using the “GET Method” to the “Show view” to a collection that they are subscribed to, but reached their expiration date." do + videogame = create(:videogame, collection_id: collection.id) + subscription = create(:subscription, collection_id: collection.id, user_id: current_user.id, expiration_date: DateTime.current.to_date) + get(:show, params: { id: collection.id, user_id: current_user.id }) + expect(response.status).to eq(401) + end + it "Validate the 401 status when the user tries to access using the “GET Method” to the “Show view” to a collection that they are not subscribed to." do + videogame = create(:videogame, collection_id: collection.id) + subscription = create(:subscription, collection_id: collection.id, user_id: current_user.id, expiration_date: DateTime.current.to_date + 1.month) + get(:show, params: { id: collection2.id , user_id: current_user.id }) + expect(response.status).to eq(401) + end + end end diff --git a/spec/controllers/videogames_controller_spec.rb b/spec/controllers/videogames_controller_spec.rb index f070ccb..3026a18 100644 --- a/spec/controllers/videogames_controller_spec.rb +++ b/spec/controllers/videogames_controller_spec.rb @@ -1,5 +1,26 @@ require 'rails_helper' -RSpec.describe VideogamesController type: :controller do +RSpec.describe VideogamesController, type: :controller do + context "Videogame" do + let(:current_user){create(:user)} + let(:another_user){create(:user)} + let(:collection){create(:collection)} + let(:collection2){create(:collection)} + it "Validate the 200 status when the user tries to access using the “GET Method” to the “Show view” to see a video game in their collection." do + videogame = create(:videogame, collection_id: collection.id) + subscription = create(:subscription, collection_id: collection.id, user_id: current_user.id, expiration_date: DateTime.current.to_date + 1.month) + raw_response = get(:show, params: { id: videogame.id ,user_id: current_user.id, collection_id: collection.id }) + body = JSON.parse(raw_response.body) + expect(body["id"]).to eq(videogame.id) + expect(response.status).to eq(200) + end + it "Validate the 401 status when the user tries to access using the “GET Method” to the “Show View” for a videogame that is not in their collection." do + videogame = create(:videogame, collection_id: collection.id) + videogame2 = create(:videogame, collection_id: collection2.id) + subscription = create(:subscription, collection_id: collection.id, user_id: current_user.id, expiration_date: DateTime.current.to_date + 1.month) + get(:show, params: { id: videogame2.id, user_id: current_user.id, collection_id: collection.id }) + expect(response.status).to eq(401) + end + end end