mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-12 03:50:22 +00:00
Allow user to remove terms and conditions file
This commit is contained in:
50
spec/controllers/api/terms_and_conditions_controller_spec.rb
Normal file
50
spec/controllers/api/terms_and_conditions_controller_spec.rb
Normal file
@@ -0,0 +1,50 @@
|
||||
require "spec_helper"
|
||||
|
||||
module Api
|
||||
describe TermsAndConditionsController, type: :controller do
|
||||
include AuthenticationHelper
|
||||
|
||||
let(:enterprise_owner) { create(:user) }
|
||||
let(:enterprise) { create(:enterprise, owner: enterprise_owner ) }
|
||||
let(:enterprise_manager) { create(:user, enterprises: [enterprise]) }
|
||||
|
||||
describe "removing terms and conditions file" do
|
||||
fake_terms_file_path = File.open(Rails.root.join("app", "assets", "images", "logo-black.png"))
|
||||
let(:terms_and_conditions_file) { Rack::Test::UploadedFile.new(fake_terms_file_path, "application/pdf") }
|
||||
let(:enterprise) { create(:enterprise, owner: enterprise_owner) }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:spree_current_user) { current_user }
|
||||
enterprise.update terms_and_conditions: terms_and_conditions_file
|
||||
end
|
||||
|
||||
context "as manager" do
|
||||
let(:current_user) { enterprise_manager }
|
||||
|
||||
it "removes terms and conditions file" do
|
||||
spree_delete :destroy, enterprise_id: enterprise
|
||||
|
||||
expect(response).to be_success
|
||||
expect(json_response["id"]).to eq enterprise.id
|
||||
enterprise.reload
|
||||
expect(enterprise.terms_and_conditions?).to be false
|
||||
end
|
||||
|
||||
context "when terms and conditions file does not exist" do
|
||||
let(:enterprise) { create(:enterprise, owner: enterprise_owner) }
|
||||
|
||||
before do
|
||||
enterprise.update terms_and_conditions: nil
|
||||
end
|
||||
|
||||
it "responds with error" do
|
||||
spree_delete :destroy, enterprise_id: enterprise
|
||||
|
||||
expect(response.status).to eq(409)
|
||||
expect(json_response["error"]).to eq I18n.t("api.enterprise_terms_and_conditions.destroy_attachment_does_not_exist")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user