|
@@ -10,6 +10,7 @@ describe Controllers::AttachmentsControllerPolicy do
|
|
|
let(:record_class) { AttachmentsController }
|
|
|
let(:object) { create(:knowledge_base_answer, visibility, :with_attachment, category: category) }
|
|
|
let(:params) { { id: object.attachments.first.id } }
|
|
|
+ let(:session) { {} }
|
|
|
|
|
|
let(:record) do
|
|
|
rec = record_class.new
|
|
@@ -19,6 +20,10 @@ describe Controllers::AttachmentsControllerPolicy do
|
|
|
rec
|
|
|
end
|
|
|
|
|
|
+ before do
|
|
|
+ allow(record).to receive(:session).and_return(session)
|
|
|
+ end
|
|
|
+
|
|
|
context 'with no user' do
|
|
|
let(:user) { nil }
|
|
|
|
|
@@ -67,4 +72,23 @@ describe Controllers::AttachmentsControllerPolicy do
|
|
|
it { is_expected.to forbid_actions :show, :destroy }
|
|
|
end
|
|
|
end
|
|
|
+
|
|
|
+ context 'with a preview token' do
|
|
|
+ let(:user) { false }
|
|
|
+ let(:visibility) { :draft }
|
|
|
+ let(:session) { { kb_preview_token: token } }
|
|
|
+
|
|
|
+ context 'when token is valid' do
|
|
|
+ let(:token) { Token.renew_token! 'KnowledgeBasePreview', create(:admin).id }
|
|
|
+
|
|
|
+ it { is_expected.to permit_actions :show }
|
|
|
+ it { is_expected.to forbid_actions :destroy }
|
|
|
+ end
|
|
|
+
|
|
|
+ context 'when token user does not have access' do
|
|
|
+ let(:token) { Token.renew_token! 'KnowledgeBasePreview', create(:customer).id }
|
|
|
+
|
|
|
+ it { is_expected.to forbid_actions :show, :destroy }
|
|
|
+ end
|
|
|
+ end
|
|
|
end
|