From 067dfc3a5040c44bd7ab6764e62b3eb0f25f6ca0 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sat, 22 Jan 2022 07:39:54 +0100 Subject: [PATCH] Add tests for `FeedbackController` --- spec/controllers/feedback_controller_spec.rb | 100 +++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 spec/controllers/feedback_controller_spec.rb diff --git a/spec/controllers/feedback_controller_spec.rb b/spec/controllers/feedback_controller_spec.rb new file mode 100644 index 00000000..6625f5bc --- /dev/null +++ b/spec/controllers/feedback_controller_spec.rb @@ -0,0 +1,100 @@ +# frozen_string_literal: true + +require "rails_helper" + +describe FeedbackController, type: :controller do + before do + stub_const("APP_CONFIG", { + 'hostname' => 'example.com', + 'https' => true, + 'items_per_page' => 5, + 'canny' => { + 'sso': 'sso', + 'feature_board': 'feature', + 'bug_board': 'bug' + } + }) + end + + describe "#consent" do + context "user signed in without consent" do + let(:user) { FactoryBot.create(:user) } + + before(:each) { sign_in(user) } + + it "renders the consent template" do + get :consent + expect(response).to render_template(:consent) + end + + it "sets the consent role" do + post :consent, params: { consent: 'true' } + expect(user.has_role?(:canny_consent)).to eq(true) + expect(response).to redirect_to(feedback_bugs_path) + end + end + + context "user signed in with consent" do + let(:user) { FactoryBot.create(:user, roles: [:canny_consent]) } + + before(:each) { sign_in(user) } + + it "redirects away from the consent page" do + get :consent + expect(response).to redirect_to(feedback_bugs_path) + end + end + end + + describe "#features" do + subject { get :features } + + context "user signed in with consent" do + let(:user) { FactoryBot.create(:user, roles: [:canny_consent]) } + + before(:each) { sign_in(user) } + + it "renders the features template" do + subject + expect(response).to render_template(:features) + end + end + + context "user signed in without consent" do + let(:user) { FactoryBot.create(:user) } + + before(:each) { sign_in(user) } + + it "redirects to the consent page" do + subject + expect(response).to redirect_to(feedback_consent_path) + end + end + end + + describe "#bugs" do + subject { get :bugs } + + context "user signed in with consent" do + let(:user) { FactoryBot.create(:user, roles: [:canny_consent]) } + + before(:each) { sign_in(user) } + + it "renders the bugs template" do + subject + expect(response).to render_template(:bugs) + end + end + + context "user signed in without consent" do + let(:user) { FactoryBot.create(:user) } + + before(:each) { sign_in(user) } + + it "redirects to the consent page" do + subject + expect(response).to redirect_to(feedback_consent_path) + end + end + end +end \ No newline at end of file