From cd406d2c26b3d5b2b42dd050e20d66e1f73f37bd Mon Sep 17 00:00:00 2001 From: juanjose Date: Thu, 22 Apr 2021 15:12:21 -0500 Subject: [PATCH 1/4] Tests --- .../collections_controller_spec.rb | 18 +++++++++++++++ .../controllers/videogames_controller_spec.rb | 22 ++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/spec/controllers/collections_controller_spec.rb b/spec/controllers/collections_controller_spec.rb index 4914a8f..e32d287 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 "follow request" do + let(:current_user){create(:user)} + let(:another_user){create(:user)} + let(:collection){create(:collection)} + let(:collection2){create(:collection)} + it "401 status when expired 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 "401 status" 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..c2f04a8 100644 --- a/spec/controllers/videogames_controller_spec.rb +++ b/spec/controllers/videogames_controller_spec.rb @@ -1,5 +1,25 @@ require 'rails_helper' -RSpec.describe VideogamesController type: :controller do +RSpec.describe VideogamesController, type: :controller do + context "follow request" do + let(:current_user){create(:user)} + let(:another_user){create(:user)} + let(:collection){create(:collection)} + let(:collection2){create(:collection)} + it "200 status" 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[0]["id"]).to eq(videogame.id) + expect(response.status).to eq(200) + end + it "401 status when try to access to a videogame that is not subscribed" 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: videogame.id, user_id: current_user.id, id: videogame.id , collection_id: collection2.id,}) + expect(response.status).to eq(401) + end + end end From 5a2de73c30780e72376dead03bccf75744b65bfb Mon Sep 17 00:00:00 2001 From: juanjose Date: Thu, 22 Apr 2021 16:13:27 -0500 Subject: [PATCH 2/4] Update test --- spec/controllers/collections_controller_spec.rb | 2 +- spec/controllers/videogames_controller_spec.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/controllers/collections_controller_spec.rb b/spec/controllers/collections_controller_spec.rb index e32d287..5b3e586 100644 --- a/spec/controllers/collections_controller_spec.rb +++ b/spec/controllers/collections_controller_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' RSpec.describe CollectionsController, type: :controller do - context "follow request" do + context "Collections" do let(:current_user){create(:user)} let(:another_user){create(:user)} let(:collection){create(:collection)} diff --git a/spec/controllers/videogames_controller_spec.rb b/spec/controllers/videogames_controller_spec.rb index c2f04a8..c18739e 100644 --- a/spec/controllers/videogames_controller_spec.rb +++ b/spec/controllers/videogames_controller_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' RSpec.describe VideogamesController, type: :controller do - context "follow request" do + context "Videogame" do let(:current_user){create(:user)} let(:another_user){create(:user)} let(:collection){create(:collection)} @@ -11,14 +11,14 @@ 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[0]["id"]).to eq(videogame.id) + expect(body["id"]).to eq(videogame.id) expect(response.status).to eq(200) end it "401 status when try to access to a videogame that is not subscribed" 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: videogame.id, user_id: current_user.id, id: videogame.id , collection_id: collection2.id,}) + get(:show, params: { id: videogame.id, user_id: current_user.id, collection_id: collection2.id }) expect(response.status).to eq(401) end end From 9f0371487d6d85ca58bb1208fe2c30c3b716bfcc Mon Sep 17 00:00:00 2001 From: juanjose Date: Thu, 22 Apr 2021 16:18:43 -0500 Subject: [PATCH 3/4] Update test titles --- spec/controllers/collections_controller_spec.rb | 4 ++-- spec/controllers/videogames_controller_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/controllers/collections_controller_spec.rb b/spec/controllers/collections_controller_spec.rb index 5b3e586..b8b0841 100644 --- a/spec/controllers/collections_controller_spec.rb +++ b/spec/controllers/collections_controller_spec.rb @@ -6,14 +6,14 @@ let(:another_user){create(:user)} let(:collection){create(:collection)} let(:collection2){create(:collection)} - it "401 status when expired date" do + 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 "401 status" do + 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 }) diff --git a/spec/controllers/videogames_controller_spec.rb b/spec/controllers/videogames_controller_spec.rb index c18739e..f9b08f5 100644 --- a/spec/controllers/videogames_controller_spec.rb +++ b/spec/controllers/videogames_controller_spec.rb @@ -6,7 +6,7 @@ let(:another_user){create(:user)} let(:collection){create(:collection)} let(:collection2){create(:collection)} - it "200 status" do + 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 }) @@ -15,7 +15,7 @@ expect(response.status).to eq(200) end - it "401 status when try to access to a videogame that is not subscribed" do + 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) subscription = create(:subscription, collection_id: collection.id, user_id: current_user.id, expiration_date: DateTime.current.to_date + 1.month) get(:show, params: { id: videogame.id, user_id: current_user.id, collection_id: collection2.id }) From 97a10f46ea5213c58423858e51902f2bbdf81ea8 Mon Sep 17 00:00:00 2001 From: juanjose Date: Thu, 22 Apr 2021 16:28:11 -0500 Subject: [PATCH 4/4] Update videogame test --- spec/controllers/videogames_controller_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/controllers/videogames_controller_spec.rb b/spec/controllers/videogames_controller_spec.rb index f9b08f5..3026a18 100644 --- a/spec/controllers/videogames_controller_spec.rb +++ b/spec/controllers/videogames_controller_spec.rb @@ -17,8 +17,9 @@ 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: videogame.id, user_id: current_user.id, collection_id: collection2.id }) + get(:show, params: { id: videogame2.id, user_id: current_user.id, collection_id: collection.id }) expect(response.status).to eq(401) end end