Fixing supporter and supporter note creation

This commit is contained in:
Clarissa Borges 2021-02-15 20:22:19 -03:00 committed by Eric Schultz
parent 3f8f5559ab
commit 885bcee03a
8 changed files with 19 additions and 11 deletions

View file

@ -11,13 +11,13 @@ class Nonprofits::SupporterNotesController < ApplicationController
# post /nonprofits/:nonprofit_id/supporters/:supporter_id/supporter_notes
def create
render_json { InsertSupporterNotes.create(supporter_params[:supporter_note]) }
render_json { InsertSupporterNotes.create(supporter_params) }
end
# put /nonprofits/:nonprofit_id/supporters/:supporter_id/supporter_notes/:id
def update
render_json { UpdateSupporterNotes.update(current_supporter_note,
supporter_params[:supporter_note].merge({user_id: current_user&.id})) }
supporter_note_content.merge({user_id: current_user&.id})) }
end
# delete /nonprofits/:nonprofit_id/supporters/:supporter_id/supporter_notes/:id
@ -32,6 +32,14 @@ class Nonprofits::SupporterNotesController < ApplicationController
end
def supporter_params
{
content: supporter_note_content,
supporter: current_supporter,
user: current_user
}
end
def supporter_note_content
params.require(:supporter_note).require(:content)
end
end

View file

@ -76,7 +76,7 @@ module Nonprofits
# post /nonprofits/:nonprofit_id/supporters
def create
render_json { InsertSupporter.create_or_update(nonprofit, create_supporter_params.to_h) }
render_json { InsertSupporter.create_or_update(current_nonprofit, create_supporter_params.to_h) }
end
# put /nonprofits/:nonprofit_id/supporters/:id

View file

@ -13,7 +13,7 @@ module InsertSupporterNotes
inserted = nil
ActiveRecord::Base.transaction do
inserted = note_supporter_users.map do |nsu|
nsu[:supporter].supporter_notes.create(nsu[:note].merge({user: nsu[:user]}))
nsu[:supporter].supporter_notes.create!(content: nsu[:content], user: nsu[:user])
end
InsertActivities.for_supporter_notes(inserted)
end

View file

@ -93,7 +93,7 @@ module PayRecurringDonation
rd.save!
result['recurring_donation'] = rd
Houdini.event_publisher.announce(:recurring_donation_payment_failed, donation)
InsertSupporterNotes.create({supporter:Supporter.find(donation['supporter_id']), user: User.find(540), note:{ content: "This supporter had a payment failure for their recurring donation with ID #{rd_id}"}})
InsertSupporterNotes.create({supporter:Supporter.find(donation['supporter_id']), user: User.find(540), content: "This supporter had a payment failure for their recurring donation with ID #{rd_id}"})
end
result
end

View file

@ -96,7 +96,7 @@ module UpdateRecurringDonations
.where('id=$id', id: rd_id.to_i)
)
rd = QueryRecurringDonations.fetch_for_edit(rd_id)['recurring_donation']
InsertSupporterNotes.create({ supporter: Supporter.find(rd['supporter_id']), user: nil, note: {content: "This supporter's recurring donation for $#{Format::Currency.cents_to_dollars(rd['amount'])} was cancelled by #{rd['cancelled_by']} on #{Format::Date.simple(rd['cancelled_at'])}"}})
InsertSupporterNotes.create({ supporter: Supporter.find(rd['supporter_id']), user: nil, content: "This supporter's recurring donation for $#{Format::Currency.cents_to_dollars(rd['amount'])} was cancelled by #{rd['cancelled_by']} on #{Format::Date.simple(rd['cancelled_at'])}"})
unless dont_notify_nonprofit
RecurringDonationCancelledJob.perform_later(Donation.find(rd['donation_id']))
end

View file

@ -11,8 +11,8 @@ describe InsertSupporterNotes do
let(:sn_first) {SupporterNote.first }
let(:sn_last) {SupporterNote.last }
it '.create' do
InsertSupporterNotes.create({supporter:supporter, user: user, note: {content: content}},
{supporter:supporter, user: user, note: {content: content_2}})
InsertSupporterNotes.create({supporter: supporter, user: user, content: content},
{supporter: supporter, user: user, content: content_2})
expect(SupporterNote.count).to eq 2
expect(sn_first.attributes.except('id')).to eq({
'content' => content,

View file

@ -8,7 +8,7 @@ describe UpdateRecurringDonations do
# deactivate a recurring donation
describe '.cancel' do
let(:np) { force_create(:nm_justice) }
let!(:np) { force_create(:nm_justice) }
let(:s) { force_create(:supporter, nonprofit: np) }
let(:donation) { force_create(:donation, nonprofit_id: np.id, supporter_id: s.id) }
let(:email) { 'test@test.com' }