2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-12-04 22:40:48 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe QueryDonations do
|
2018-11-09 00:29:00 +00:00
|
|
|
describe 'campaign_export' do
|
2020-04-16 20:50:03 +00:00
|
|
|
let(:nonprofit) { force_create(:nm_justice) }
|
2019-07-30 21:29:24 +00:00
|
|
|
let(:supporter) { force_create(:supporter) }
|
2018-12-04 22:40:48 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
let(:profile_email) { 'something@profile_email.com' }
|
2019-01-22 21:41:13 +00:00
|
|
|
let(:profile) do
|
|
|
|
u = force_create(:user, email: profile_email)
|
|
|
|
profile = force_create(:profile, user: u)
|
|
|
|
end
|
2019-07-30 21:29:24 +00:00
|
|
|
let(:campaign) { force_create(:campaign, nonprofit: nonprofit, show_total_count: false, show_total_raised: false, goal_amount: 16_000, profile: profile) }
|
2019-01-22 21:41:13 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
let(:profile_email1) { 'something1@profile_email.com' }
|
|
|
|
let(:profile1) do
|
2019-01-22 21:41:13 +00:00
|
|
|
u = force_create(:user, email: profile_email1)
|
|
|
|
profile = force_create(:profile, user: u)
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|
|
|
|
let(:campaign_child) { force_create(:campaign, nonprofit: nonprofit, parent_campaign: campaign, show_total_count: true, show_total_raised: true, goal_amount: 8000, profile: profile1) }
|
2019-01-22 21:41:13 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
let(:profile_email2) { 'something2@profile_email.com' }
|
|
|
|
let(:profile2) do
|
2019-01-22 21:41:13 +00:00
|
|
|
u = force_create(:user, email: profile_email2)
|
|
|
|
profile = force_create(:profile, user: u)
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|
|
|
|
let(:campaign_child_2) { force_create(:campaign, nonprofit: nonprofit, parent_campaign: campaign, show_total_count: true, show_total_raised: true, goal_amount: 4000, profile: profile2) }
|
2018-12-04 22:40:48 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
let(:donation) { force_create(:donation, campaign: campaign, amount: 1000, supporter: supporter) }
|
|
|
|
let(:payment) { force_create(:payment, donation: donation, gross_amount: 1000, supporter: supporter) }
|
2018-12-04 22:40:48 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
let(:donation2) { force_create(:donation, campaign: campaign, amount: 2000, supporter: supporter) }
|
|
|
|
let(:payment2) { force_create(:payment, donation: donation2, gross_amount: 2000, supporter: supporter) }
|
2018-12-04 22:40:48 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
let(:donation3) { force_create(:donation, campaign: campaign_child, amount: 2000, supporter: supporter) }
|
|
|
|
let(:payment3) { force_create(:payment, donation: donation3, gross_amount: 4000, kind: 'RecurringPayment', supporter: supporter) }
|
|
|
|
let(:payment3_1) { force_create(:payment, donation: donation3, gross_amount: 2000, kind: 'RecurringPayment', supporter: supporter) }
|
|
|
|
let(:recurring) { force_create(:recurring_donation, donation: donation3, amount: 2000, supporter: supporter) }
|
2018-12-04 22:40:48 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
let(:donation4) { force_create(:donation, campaign: campaign_child_2, amount: 8000, supporter: supporter) }
|
|
|
|
let(:payment4) { force_create(:payment, donation: donation4, gross_amount: 8000, supporter: supporter) }
|
2018-12-04 22:40:48 +00:00
|
|
|
|
|
|
|
let(:payments) do
|
|
|
|
payment
|
|
|
|
payment2
|
|
|
|
payment3
|
|
|
|
payment3_1
|
|
|
|
recurring
|
|
|
|
payment4
|
|
|
|
end
|
|
|
|
|
|
|
|
let (:campaign_export) do
|
|
|
|
payments
|
|
|
|
QueryDonations.campaign_export(campaign.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'payment amounts get the first payment, not additional ones' do
|
|
|
|
export = vector_to_hash(campaign_export)
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
expect(export.map { |i| i['Amount'] }).to match_array(['$10.00', '$20.00', '$40.00', '$80.00'])
|
2018-12-04 22:40:48 +00:00
|
|
|
end
|
2019-01-22 17:34:54 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
it 'includes the campaign ids' do
|
|
|
|
export = vector_to_hash(campaign_export)
|
|
|
|
expect(export.map { |i| i['Campaign Id'] }).to match_array([campaign.id, campaign.id, campaign_child.id, campaign_child_2.id])
|
|
|
|
end
|
2019-01-22 21:41:13 +00:00
|
|
|
|
|
|
|
it 'includes user email' do
|
|
|
|
export = vector_to_hash(campaign_export)
|
2019-07-30 21:29:24 +00:00
|
|
|
expect(export.map { |i| i['Campaign Creator Email'] }).to match_array([profile_email, profile_email, profile_email1, profile_email2])
|
2019-01-22 21:41:13 +00:00
|
|
|
end
|
2018-12-04 22:40:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
## move to common area
|
|
|
|
def vector_to_hash(vecs)
|
2019-07-30 21:29:24 +00:00
|
|
|
keys = vecs.first.to_a.map { |k| k.to_s.titleize }
|
2018-12-04 22:40:48 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
vecs.drop(1).map { |v| keys.zip(v).to_h }
|
2018-12-04 22:40:48 +00:00
|
|
|
end
|
|
|
|
end
|