2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-06-12 20:03:43 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
|
|
|
|
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
|
2018-03-25 17:30:42 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe DeleteCampaignGiftOption do
|
|
|
|
describe '.delete' do
|
2021-01-15 23:10:37 +00:00
|
|
|
let(:nonprofit) { create(:nm_justice)}
|
2019-07-30 21:29:24 +00:00
|
|
|
let(:profile) { force_create(:profile, user: force_create(:user)) }
|
2021-01-15 23:10:37 +00:00
|
|
|
let(:campaign) { force_create(:campaign, profile: profile, nonprofit:nonprofit) }
|
2019-07-30 21:29:24 +00:00
|
|
|
let(:campaign_gift_option) { force_create(:campaign_gift_option, campaign: campaign) }
|
|
|
|
let(:campaign_gift) { force_create(:campaign_gift, campaign_gift_option: campaign_gift_option) }
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
it 'cgo deletion is rejected because a gift has already been sold' do
|
|
|
|
campaign_gift_option
|
|
|
|
campaign_gift
|
2021-01-15 23:10:37 +00:00
|
|
|
expect { DeleteCampaignGiftOption.delete(campaign_gift_option) }.to(raise_error do |error|
|
2018-03-25 17:30:42 +00:00
|
|
|
expect(error).to be_a ParamValidation::ValidationError
|
2019-07-30 21:29:24 +00:00
|
|
|
expect_validation_errors(error.data, [{ key: :campaign_gift_option_id }])
|
2018-03-25 17:30:42 +00:00
|
|
|
expect(error.message).to eq("#{campaign_gift_option.id} already has campaign gifts. It can't be deleted for safety reasons.")
|
|
|
|
|
|
|
|
expect(CampaignGiftOption.any?).to eq true
|
2019-07-30 21:29:24 +00:00
|
|
|
end)
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'cgo deletion succeeds' do
|
2019-07-30 21:29:24 +00:00
|
|
|
Timecop.freeze(2020, 10, 12) do
|
2018-03-25 17:30:42 +00:00
|
|
|
campaign_gift_option
|
2021-01-15 23:10:37 +00:00
|
|
|
result = DeleteCampaignGiftOption.delete(campaign_gift_option)
|
2018-03-25 17:30:42 +00:00
|
|
|
expect(result).to be_a CampaignGiftOption
|
2019-07-30 21:29:24 +00:00
|
|
|
expect(result.attributes).to eq campaign_gift_option.attributes
|
2018-03-25 17:30:42 +00:00
|
|
|
expect(CampaignGiftOption.any?).to eq false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|