2021-01-14 21:33:10 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# 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
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe SupporterNote, type: :model do
|
|
|
|
include_context :shared_donation_charge_context
|
|
|
|
let(:content) { "CONTENT"}
|
|
|
|
let(:content2) {"CONTENT2"}
|
|
|
|
|
|
|
|
let(:supporter_note) { supporter.supporter_notes.create(content: content, user: user) }
|
2021-01-19 20:00:23 +00:00
|
|
|
|
2021-01-14 21:33:10 +00:00
|
|
|
it 'creates' do
|
|
|
|
expect(supporter_note.errors).to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'announces created' do
|
2021-01-19 20:00:23 +00:00
|
|
|
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_created, anything)
|
|
|
|
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_address_created, anything)
|
2021-01-14 21:33:10 +00:00
|
|
|
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_note_created, {
|
2021-01-21 22:15:24 +00:00
|
|
|
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
2021-01-14 21:33:10 +00:00
|
|
|
'object' => 'object_event',
|
|
|
|
'type' => 'supporter_note.created',
|
|
|
|
'data' => {
|
|
|
|
'object' => {
|
|
|
|
'id'=> kind_of(Numeric),
|
|
|
|
'deleted' => false,
|
|
|
|
'content' => content,
|
|
|
|
'nonprofit'=> {
|
|
|
|
'id' => nonprofit.id,
|
|
|
|
'name' => nonprofit.name,
|
|
|
|
'object' => 'nonprofit'
|
|
|
|
},
|
|
|
|
'object' => 'supporter_note',
|
|
|
|
'user' => {
|
|
|
|
'id' => user.id,
|
|
|
|
'object' => 'user'
|
|
|
|
},
|
2021-02-02 21:04:53 +00:00
|
|
|
'supporter' => supporter_to_builder_base.merge({'name' => "Fake Supporter Name"})
|
2021-01-14 21:33:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
supporter_note
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'announces updated' do
|
2021-01-19 20:00:23 +00:00
|
|
|
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_created, anything)
|
|
|
|
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_address_created, anything)
|
2021-01-14 21:33:10 +00:00
|
|
|
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_note_created, anything).ordered
|
|
|
|
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_note_updated, {
|
2021-01-21 22:15:24 +00:00
|
|
|
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
2021-01-14 21:33:10 +00:00
|
|
|
'object' => 'object_event',
|
|
|
|
'type' => 'supporter_note.updated',
|
|
|
|
'data' => {
|
|
|
|
'object' => {
|
|
|
|
'id'=> kind_of(Numeric),
|
|
|
|
'deleted' => false,
|
|
|
|
'content' => content2,
|
|
|
|
'nonprofit'=> {
|
|
|
|
'id' => nonprofit.id,
|
|
|
|
'name' => nonprofit.name,
|
|
|
|
'object' => 'nonprofit'
|
|
|
|
},
|
|
|
|
'object' => 'supporter_note',
|
|
|
|
'user' => {
|
|
|
|
'id' => user.id,
|
|
|
|
'object' => 'user'
|
|
|
|
},
|
2021-02-02 21:04:53 +00:00
|
|
|
'supporter' => supporter_to_builder_base.merge({'name' => "Fake Supporter Name"})
|
2021-01-14 21:33:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}).ordered
|
|
|
|
|
|
|
|
supporter_note
|
|
|
|
supporter_note.content = content2
|
|
|
|
supporter_note.save!
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'announces deleted' do
|
2021-01-19 20:00:23 +00:00
|
|
|
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_created, anything)
|
|
|
|
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_address_created, anything)
|
2021-01-14 21:33:10 +00:00
|
|
|
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_note_created, anything).ordered
|
|
|
|
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_note_deleted, {
|
2021-01-21 22:15:24 +00:00
|
|
|
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
2021-01-14 21:33:10 +00:00
|
|
|
'object' => 'object_event',
|
|
|
|
'type' => 'supporter_note.deleted',
|
|
|
|
'data' => {
|
|
|
|
'object' => {
|
|
|
|
'id'=> kind_of(Numeric),
|
|
|
|
'deleted' => true,
|
|
|
|
'content' => content,
|
|
|
|
'nonprofit'=> {
|
|
|
|
'id' => nonprofit.id,
|
|
|
|
'name' => nonprofit.name,
|
|
|
|
'object' => 'nonprofit'
|
|
|
|
},
|
|
|
|
'object' => 'supporter_note',
|
|
|
|
'user' => {
|
|
|
|
'id' => user.id,
|
|
|
|
'object' => 'user'
|
|
|
|
},
|
2021-02-02 21:04:53 +00:00
|
|
|
'supporter' => supporter_to_builder_base.merge({'name' => "Fake Supporter Name"})
|
2021-01-14 21:33:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}).ordered
|
|
|
|
|
|
|
|
supporter_note.discard!
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|