diff --git a/app/jobs/accountify/invoice/deleted_job.rb b/app/jobs/accountify/invoice/deleted_job.rb new file mode 100644 index 0000000..809a841 --- /dev/null +++ b/app/jobs/accountify/invoice/deleted_job.rb @@ -0,0 +1,20 @@ +module Accountify + module Invoice + class DeletedJob + include Sidekiq::Job + + sidekiq_options retry: false, backtrace: true + + def perform(args) + event = ActiveRecord::Base.connection_pool.with_connection do + Models::Invoice::DeletedEvent.find(args['id']) + end + + InvoiceStatusSummary::RegenerateJob.perform_async({ + 'tenant_id' => event.tenant_id, + 'organisation_id' => event.body['organisation']['id'], + 'invoice_updated_at' => event.created_at.utc.iso8601 }) + end + end + end +end diff --git a/app/jobs/accountify/invoice/drafted_job.rb b/app/jobs/accountify/invoice/drafted_job.rb new file mode 100644 index 0000000..22e88a1 --- /dev/null +++ b/app/jobs/accountify/invoice/drafted_job.rb @@ -0,0 +1,20 @@ +module Accountify + module Invoice + class DraftedJob + include Sidekiq::Job + + sidekiq_options retry: false, backtrace: true + + def perform(args) + event = ActiveRecord::Base.connection_pool.with_connection do + Models::Invoice::DraftedEvent.find(args['id']) + end + + InvoiceStatusSummary::RegenerateJob.perform_async({ + 'tenant_id' => event.tenant_id, + 'organisation_id' => event.body['organisation']['id'], + 'invoice_updated_at' => event.created_at.utc.iso8601 }) + end + end + end +end diff --git a/app/jobs/accountify/invoice/issued_job.rb b/app/jobs/accountify/invoice/issued_job.rb new file mode 100644 index 0000000..336f6f2 --- /dev/null +++ b/app/jobs/accountify/invoice/issued_job.rb @@ -0,0 +1,20 @@ +module Accountify + module Invoice + class IssuedJob + include Sidekiq::Job + + sidekiq_options retry: false, backtrace: true + + def perform(args) + event = ActiveRecord::Base.connection_pool.with_connection do + Models::Invoice::IssuedEvent.find(args['id']) + end + + InvoiceStatusSummary::RegenerateJob.perform_async({ + 'tenant_id' => event.tenant_id, + 'organisation_id' => event.body['organisation']['id'], + 'invoice_updated_at' => event.created_at.utc.iso8601 }) + end + end + end +end diff --git a/app/jobs/accountify/invoice/paid_job.rb b/app/jobs/accountify/invoice/paid_job.rb new file mode 100644 index 0000000..39ee08e --- /dev/null +++ b/app/jobs/accountify/invoice/paid_job.rb @@ -0,0 +1,20 @@ +module Accountify + module Invoice + class PaidJob + include Sidekiq::Job + + sidekiq_options retry: false, backtrace: true + + def perform(args) + event = ActiveRecord::Base.connection_pool.with_connection do + Models::Invoice::PaidEvent.find(args['id']) + end + + InvoiceStatusSummary::RegenerateJob.perform_async({ + 'tenant_id' => event.tenant_id, + 'organisation_id' => event.body['organisation']['id'], + 'invoice_updated_at' => event.created_at.utc.iso8601 }) + end + end + end +end diff --git a/app/jobs/accountify/invoice/updated_job.rb b/app/jobs/accountify/invoice/updated_job.rb new file mode 100644 index 0000000..8604331 --- /dev/null +++ b/app/jobs/accountify/invoice/updated_job.rb @@ -0,0 +1,20 @@ +module Accountify + module Invoice + class UpdatedJob + include Sidekiq::Job + + sidekiq_options retry: false, backtrace: true + + def perform(args) + event = ActiveRecord::Base.connection_pool.with_connection do + Models::Invoice::UpdatedEvent.find(args['id']) + end + + InvoiceStatusSummary::RegenerateJob.perform_async({ + 'tenant_id' => event.tenant_id, + 'organisation_id' => event.body['organisation']['id'], + 'invoice_updated_at' => event.created_at.utc.iso8601 }) + end + end + end +end diff --git a/app/jobs/accountify/invoice/voided_job.rb b/app/jobs/accountify/invoice/voided_job.rb new file mode 100644 index 0000000..b059668 --- /dev/null +++ b/app/jobs/accountify/invoice/voided_job.rb @@ -0,0 +1,20 @@ +module Accountify + module Invoice + class VoidedJob + include Sidekiq::Job + + sidekiq_options retry: false, backtrace: true + + def perform(args) + event = ActiveRecord::Base.connection_pool.with_connection do + Models::Invoice::VoidedEvent.find(args['id']) + end + + InvoiceStatusSummary::RegenerateJob.perform_async({ + 'tenant_id' => event.tenant_id, + 'organisation_id' => event.body['organisation']['id'], + 'invoice_updated_at' => event.created_at.utc.iso8601 }) + end + end + end +end diff --git a/app/jobs/accountify/organisation/created_job.rb b/app/jobs/accountify/organisation/created_job.rb new file mode 100644 index 0000000..4acb2a7 --- /dev/null +++ b/app/jobs/accountify/organisation/created_job.rb @@ -0,0 +1,19 @@ +module Accountify + module Organisation + class CreatedJob + include Sidekiq::Job + + sidekiq_options retry: false, backtrace: true + + def perform(args) + event = ActiveRecord::Base.connection_pool.with_connection do + Models::Organisation::CreatedEvent.find(args['id']) + end + + InvoiceStatusSummary::GenerateJob.perform_async({ + 'tenant_id' => event.tenant_id, + 'organisation_id' => event.body['organisation']['id'] }) + end + end + end +end diff --git a/app/jobs/outboxer_integration/message/publish_job.rb b/app/jobs/outboxer_integration/message/publish_job.rb index 30bee08..f699f98 100644 --- a/app/jobs/outboxer_integration/message/publish_job.rb +++ b/app/jobs/outboxer_integration/message/publish_job.rb @@ -3,55 +3,21 @@ module Message class PublishJob include Sidekiq::Job - sidekiq_options queue: 'events', retry: false, backtrace: true + sidekiq_options retry: false, backtrace: true - def perform(args) - messageable = ActiveRecord::Base.connection_pool.with_connection do - args['messageable_type'].constantize.find(args['messageable_id']) - end - - case args['messageable_type'] - when 'Accountify::Models::Organisation::CreatedEvent' - Accountify::InvoiceStatusSummary::GenerateJob.perform_async({ - 'tenant_id' => messageable.tenant_id, - 'organisation_id' => messageable.body['organisation']['id'] }) - - when 'Accountify::Models::Invoice::DraftedEvent' - Accountify::InvoiceStatusSummary::RegenerateJob.perform_async({ - 'tenant_id' => messageable.tenant_id, - 'organisation_id' => messageable.body['organisation']['id'], - 'invoice_updated_at' => messageable.created_at.utc.iso8601 }) - - when 'Accountify::Models::Invoice::UpdatedEvent' - Accountify::InvoiceStatusSummary::RegenerateJob.perform_async({ - 'tenant_id' => messageable.tenant_id, - 'organisation_id' => messageable.body['organisation']['id'], - 'invoice_updated_at' => messageable.created_at.utc.iso8601 }) + MESSAGEABLE_TYPE_REGEX = /\A([A-Za-z]+)::Models::([A-Za-z]+)::([A-Za-z]+)Event\z/ - when 'Accountify::Models::Invoice::IssuedEvent' - Accountify::InvoiceStatusSummary::RegenerateJob.perform_async({ - 'tenant_id' => messageable.tenant_id, - 'organisation_id' => messageable.body['organisation']['id'], - 'invoice_updated_at' => messageable.created_at.utc.iso8601 }) - - when 'Accountify::Models::Invoice::PaidEvent' - Accountify::InvoiceStatusSummary::RegenerateJob.perform_async({ - 'tenant_id' => messageable.tenant_id, - 'organisation_id' => messageable.body['organisation']['id'], - 'invoice_updated_at' => messageable.created_at.utc.iso8601 }) - - when 'Accountify::Models::Invoice::VoidedEvent' - Accountify::InvoiceStatusSummary::RegenerateJob.perform_async({ - 'tenant_id' => messageable.tenant_id, - 'organisation_id' => messageable.body['organisation']['id'], - 'invoice_updated_at' => messageable.created_at.utc.iso8601 }) + def perform(args) + messageable_type = args['messageable_type'] - when 'Accountify::Models::Invoice::DeletedEvent' - Accountify::InvoiceStatusSummary::RegenerateJob.perform_async({ - 'tenant_id' => messageable.tenant_id, - 'organisation_id' => messageable.body['organisation']['id'], - 'invoice_updated_at' => messageable.created_at.utc.iso8601 }) + if !messageable_type.match(MESSAGEABLE_TYPE_REGEX) + raise StandardError, "Unexpected class name format: #{messageable_type}" end + + namespace, model, event = messageable_type.match(MESSAGEABLE_TYPE_REGEX).captures + job_class_name = "#{namespace}::#{model}::#{event}Job" + job_class = job_class_name.constantize + job_class.perform_async({ 'id' => args['messageable_id'] }) end end end diff --git a/spec/jobs/accountify/invoice/deleted_job_spec.rb b/spec/jobs/accountify/invoice/deleted_job_spec.rb new file mode 100644 index 0000000..7a12bdb --- /dev/null +++ b/spec/jobs/accountify/invoice/deleted_job_spec.rb @@ -0,0 +1,54 @@ + +require 'rails_helper' + +module Accountify + module Invoice + RSpec.describe DeletedJob, type: :job do + let(:user_id) { 123 } + let(:tenant_id) { 456 } + + let(:current_time) { Time.now } + + let(:accountify_organisation) do + create(:accountify_organisation, tenant_id: tenant_id) + end + + let(:accountify_contact) do + create(:accountify_contact, + tenant_id: tenant_id, organisation_id: organisation.id) + end + + let(:accountify_invoice) do + create(:accountify_invoice, + tenant_id: tenant_id, organisation_id: organisation.id, contact_id: contact.id) + end + + describe 'when Accountify::Models::Invoice::DeletedEvent' do + let(:event) do + create( + :accountify_invoice_deleted_event, + user_id: user_id, + tenant_id: tenant_id, + eventable: accountify_organisation, + created_at: current_time.utc, + body: { + 'organisation' => { 'id' => accountify_organisation.id } }) + end + + before do + DeletedJob.new.perform({ 'id' => event.id }) + end + + it 'performs Accountify::InvoiceStatusSummary::RegenerateJob async' do + expect(Accountify::InvoiceStatusSummary::RegenerateJob.jobs).to match([ + hash_including( + 'args' => [ + hash_including( + 'tenant_id' => tenant_id, + 'organisation_id' => accountify_organisation.id, + 'invoice_updated_at' => event.created_at.utc.iso8601 )])]) + end + end + end + end +end diff --git a/spec/jobs/accountify/invoice/drafted_job_spec.rb b/spec/jobs/accountify/invoice/drafted_job_spec.rb new file mode 100644 index 0000000..940e963 --- /dev/null +++ b/spec/jobs/accountify/invoice/drafted_job_spec.rb @@ -0,0 +1,54 @@ + +require 'rails_helper' + +module Accountify + module Invoice + RSpec.describe DraftedJob, type: :job do + let(:user_id) { 123 } + let(:tenant_id) { 456 } + + let(:current_time) { Time.now } + + let(:accountify_organisation) do + create(:accountify_organisation, tenant_id: tenant_id) + end + + let(:accountify_contact) do + create(:accountify_contact, + tenant_id: tenant_id, organisation_id: organisation.id) + end + + let(:accountify_invoice) do + create(:accountify_invoice, + tenant_id: tenant_id, organisation_id: organisation.id, contact_id: contact.id) + end + + describe 'when Accountify::Models::Invoice::DraftedEvent' do + let(:event) do + create( + :accountify_invoice_drafted_event, + user_id: user_id, + tenant_id: tenant_id, + eventable: accountify_organisation, + created_at: current_time.utc, + body: { + 'organisation' => { 'id' => accountify_organisation.id } }) + end + + before do + DraftedJob.new.perform({ 'id' => event.id }) + end + + it 'performs Accountify::InvoiceStatusSummary::RegenerateJob async' do + expect(Accountify::InvoiceStatusSummary::RegenerateJob.jobs).to match([ + hash_including( + 'args' => [ + hash_including( + 'tenant_id' => tenant_id, + 'organisation_id' => accountify_organisation.id, + 'invoice_updated_at' => event.created_at.utc.iso8601 )])]) + end + end + end + end +end diff --git a/spec/jobs/accountify/invoice/issued_job_spec.rb b/spec/jobs/accountify/invoice/issued_job_spec.rb new file mode 100644 index 0000000..9d4b507 --- /dev/null +++ b/spec/jobs/accountify/invoice/issued_job_spec.rb @@ -0,0 +1,54 @@ + +require 'rails_helper' + +module Accountify + module Invoice + RSpec.describe IssuedJob, type: :job do + let(:user_id) { 123 } + let(:tenant_id) { 456 } + + let(:current_time) { Time.now } + + let(:accountify_organisation) do + create(:accountify_organisation, tenant_id: tenant_id) + end + + let(:accountify_contact) do + create(:accountify_contact, + tenant_id: tenant_id, organisation_id: organisation.id) + end + + let(:accountify_invoice) do + create(:accountify_invoice, + tenant_id: tenant_id, organisation_id: organisation.id, contact_id: contact.id) + end + + describe 'when Accountify::Models::Invoice::IssuedEvent' do + let(:event) do + create( + :accountify_invoice_issued_event, + user_id: user_id, + tenant_id: tenant_id, + eventable: accountify_organisation, + created_at: current_time.utc, + body: { + 'organisation' => { 'id' => accountify_organisation.id } }) + end + + before do + IssuedJob.new.perform({ 'id' => event.id }) + end + + it 'performs Accountify::InvoiceStatusSummary::RegenerateJob async' do + expect(Accountify::InvoiceStatusSummary::RegenerateJob.jobs).to match([ + hash_including( + 'args' => [ + hash_including( + 'tenant_id' => tenant_id, + 'organisation_id' => accountify_organisation.id, + 'invoice_updated_at' => event.created_at.utc.iso8601 )])]) + end + end + end + end +end diff --git a/spec/jobs/accountify/invoice/paid_job_spec.rb b/spec/jobs/accountify/invoice/paid_job_spec.rb new file mode 100644 index 0000000..8aaafad --- /dev/null +++ b/spec/jobs/accountify/invoice/paid_job_spec.rb @@ -0,0 +1,54 @@ + +require 'rails_helper' + +module Accountify + module Invoice + RSpec.describe PaidJob, type: :job do + let(:user_id) { 123 } + let(:tenant_id) { 456 } + + let(:current_time) { Time.now } + + let(:accountify_organisation) do + create(:accountify_organisation, tenant_id: tenant_id) + end + + let(:accountify_contact) do + create(:accountify_contact, + tenant_id: tenant_id, organisation_id: organisation.id) + end + + let(:accountify_invoice) do + create(:accountify_invoice, + tenant_id: tenant_id, organisation_id: organisation.id, contact_id: contact.id) + end + + describe 'when Accountify::Models::Invoice::PaidEvent' do + let(:event) do + create( + :accountify_invoice_paid_event, + user_id: user_id, + tenant_id: tenant_id, + eventable: accountify_organisation, + created_at: current_time.utc, + body: { + 'organisation' => { 'id' => accountify_organisation.id } }) + end + + before do + PaidJob.new.perform({ 'id' => event.id }) + end + + it 'performs Accountify::InvoiceStatusSummary::RegenerateJob async' do + expect(Accountify::InvoiceStatusSummary::RegenerateJob.jobs).to match([ + hash_including( + 'args' => [ + hash_including( + 'tenant_id' => tenant_id, + 'organisation_id' => accountify_organisation.id, + 'invoice_updated_at' => event.created_at.utc.iso8601 )])]) + end + end + end + end +end diff --git a/spec/jobs/accountify/invoice/updated_job_spec.rb b/spec/jobs/accountify/invoice/updated_job_spec.rb new file mode 100644 index 0000000..d7e1938 --- /dev/null +++ b/spec/jobs/accountify/invoice/updated_job_spec.rb @@ -0,0 +1,54 @@ + +require 'rails_helper' + +module Accountify + module Invoice + RSpec.describe UpdatedJob, type: :job do + let(:user_id) { 123 } + let(:tenant_id) { 456 } + + let(:current_time) { Time.now } + + let(:accountify_organisation) do + create(:accountify_organisation, tenant_id: tenant_id) + end + + let(:accountify_contact) do + create(:accountify_contact, + tenant_id: tenant_id, organisation_id: organisation.id) + end + + let(:accountify_invoice) do + create(:accountify_invoice, + tenant_id: tenant_id, organisation_id: organisation.id, contact_id: contact.id) + end + + describe 'when Accountify::Models::Invoice::UpdatedEvent' do + let(:event) do + create( + :accountify_invoice_updated_event, + user_id: user_id, + tenant_id: tenant_id, + eventable: accountify_organisation, + created_at: current_time.utc, + body: { + 'organisation' => { 'id' => accountify_organisation.id } }) + end + + before do + UpdatedJob.new.perform({ 'id' => event.id }) + end + + it 'performs Accountify::InvoiceStatusSummary::RegenerateJob async' do + expect(Accountify::InvoiceStatusSummary::RegenerateJob.jobs).to match([ + hash_including( + 'args' => [ + hash_including( + 'tenant_id' => tenant_id, + 'organisation_id' => accountify_organisation.id, + 'invoice_updated_at' => event.created_at.utc.iso8601 )])]) + end + end + end + end +end diff --git a/spec/jobs/accountify/invoice/voided_job_spec.rb b/spec/jobs/accountify/invoice/voided_job_spec.rb new file mode 100644 index 0000000..2dfdb59 --- /dev/null +++ b/spec/jobs/accountify/invoice/voided_job_spec.rb @@ -0,0 +1,54 @@ + +require 'rails_helper' + +module Accountify + module Invoice + RSpec.describe VoidedJob, type: :job do + let(:user_id) { 123 } + let(:tenant_id) { 456 } + + let(:current_time) { Time.now } + + let(:accountify_organisation) do + create(:accountify_organisation, tenant_id: tenant_id) + end + + let(:accountify_contact) do + create(:accountify_contact, + tenant_id: tenant_id, organisation_id: organisation.id) + end + + let(:accountify_invoice) do + create(:accountify_invoice, + tenant_id: tenant_id, organisation_id: organisation.id, contact_id: contact.id) + end + + describe 'when Accountify::Models::Invoice::VoidedEvent' do + let(:event) do + create( + :accountify_invoice_voided_event, + user_id: user_id, + tenant_id: tenant_id, + eventable: accountify_organisation, + created_at: current_time.utc, + body: { + 'organisation' => { 'id' => accountify_organisation.id } }) + end + + before do + VoidedJob.new.perform({ 'id' => event.id }) + end + + it 'performs Accountify::InvoiceStatusSummary::RegenerateJob async' do + expect(Accountify::InvoiceStatusSummary::RegenerateJob.jobs).to match([ + hash_including( + 'args' => [ + hash_including( + 'tenant_id' => tenant_id, + 'organisation_id' => accountify_organisation.id, + 'invoice_updated_at' => event.created_at.utc.iso8601 )])]) + end + end + end + end +end diff --git a/spec/jobs/accountify/organisation/created_job_spec.rb b/spec/jobs/accountify/organisation/created_job_spec.rb new file mode 100644 index 0000000..07c881d --- /dev/null +++ b/spec/jobs/accountify/organisation/created_job_spec.rb @@ -0,0 +1,50 @@ +require 'rails_helper' + +module Accountify + module Organisation + RSpec.describe CreatedJob, type: :job do + let(:user_id) { 123 } + let(:tenant_id) { 456 } + + let(:current_time) { Time.now } + + let(:accountify_organisation) do + create(:accountify_organisation, tenant_id: tenant_id) + end + + let(:accountify_contact) do + create(:accountify_contact, + tenant_id: tenant_id, organisation_id: organisation.id) + end + + let(:accountify_invoice) do + create(:accountify_invoice, + tenant_id: tenant_id, organisation_id: organisation.id, contact_id: contact.id) + end + + describe 'when Accountify::Models::Organisation::CreatedEvent' do + let(:event) do + create( + :accountify_organisation_created_event, + user_id: user_id, + tenant_id: tenant_id, + eventable: accountify_organisation, + body: { 'organisation' => { 'id' => accountify_organisation.id } }) + end + + before do + CreatedJob.new.perform({ 'id' => event.id }) + end + + it 'performs Accountify::InvoiceStatusSummary::GenerateJob async' do + expect(Accountify::InvoiceStatusSummary::GenerateJob.jobs).to match([ + hash_including( + 'args' => [ + hash_including( + 'tenant_id' => tenant_id, + 'organisation_id' => accountify_organisation.id )])]) + end + end + end + end +end diff --git a/spec/jobs/outboxer_integration/message/publish_job_spec.rb b/spec/jobs/outboxer_integration/message/publish_job_spec.rb index a0c2570..e682192 100644 --- a/spec/jobs/outboxer_integration/message/publish_job_spec.rb +++ b/spec/jobs/outboxer_integration/message/publish_job_spec.rb @@ -3,222 +3,37 @@ module OutboxerIntegration module Message RSpec.describe PublishJob, type: :job do - let(:user_id) { 123 } - let(:tenant_id) { 456 } - - let(:current_time) { Time.now } - - let(:accountify_organisation) do - create(:accountify_organisation, tenant_id: tenant_id) - end - - let(:accountify_contact) do - create(:accountify_contact, - tenant_id: tenant_id, organisation_id: organisation.id) - end - - let(:accountify_invoice) do - create(:accountify_invoice, - tenant_id: tenant_id, organisation_id: organisation.id, contact_id: contact.id) - end - - describe 'when Accountify::Models::Organisation::CreatedEvent' do - let(:event) do - create( - :accountify_organisation_created_event, - user_id: user_id, - tenant_id: tenant_id, - eventable: accountify_organisation, - body: { 'organisation' => { 'id' => accountify_organisation.id } }) - end - - before do - PublishJob.new.perform({ - 'messageable_type' => 'Accountify::Models::Organisation::CreatedEvent', - 'messageable_id' => event.id }) - end - - it 'performs Accountify::InvoiceStatusSummary::GenerateJob async' do - expect(Accountify::InvoiceStatusSummary::GenerateJob.jobs).to match([ - hash_including( - 'args' => [ - hash_including( - 'tenant_id' => tenant_id, - 'organisation_id' => accountify_organisation.id )])]) - end - end - - describe 'when Accountify::Models::Invoice::DraftedEvent' do - let(:event) do - create( - :accountify_invoice_drafted_event, - user_id: user_id, - tenant_id: tenant_id, - eventable: accountify_organisation, - created_at: current_time.utc, - body: { - 'organisation' => { 'id' => accountify_organisation.id } }) - end - - before do - PublishJob.new.perform({ - 'messageable_type' => 'Accountify::Models::Invoice::DraftedEvent', - 'messageable_id' => event.id }) - end - - it 'performs Accountify::InvoiceStatusSummary::RegenerateJob async' do - expect(Accountify::InvoiceStatusSummary::RegenerateJob.jobs).to match([ - hash_including( - 'args' => [ - hash_including( - 'tenant_id' => tenant_id, - 'organisation_id' => accountify_organisation.id, - 'invoice_updated_at' => event.created_at.utc.iso8601 )])]) - end - end - - describe 'when Accountify::Models::Invoice::UpdatedEvent' do - let(:event) do - create( - :accountify_invoice_updated_event, - user_id: user_id, - tenant_id: tenant_id, - eventable: accountify_organisation, - created_at: current_time.utc, - body: { - 'organisation' => { 'id' => accountify_organisation.id } }) - end - - before do - PublishJob.new.perform({ - 'messageable_type' => 'Accountify::Models::Invoice::UpdatedEvent', - 'messageable_id' => event.id }) - end - - it 'performs Accountify::InvoiceStatusSummary::RegenerateJob async' do - expect(Accountify::InvoiceStatusSummary::RegenerateJob.jobs).to match([ - hash_including( - 'args' => [ - hash_including( - 'tenant_id' => tenant_id, - 'organisation_id' => accountify_organisation.id, - 'invoice_updated_at' => event.created_at.utc.iso8601 )])]) - end - end - - describe 'when Accountify::Models::Invoice::IssuedEvent' do - let(:event) do - create( - :accountify_invoice_issued_event, - user_id: user_id, - tenant_id: tenant_id, - eventable: accountify_organisation, - created_at: current_time.utc, - body: { - 'organisation' => { 'id' => accountify_organisation.id } }) - end - - before do - PublishJob.new.perform({ - 'messageable_type' => 'Accountify::Models::Invoice::IssuedEvent', - 'messageable_id' => event.id }) - end - - it 'performs Accountify::InvoiceStatusSummary::RegenerateJob async' do - expect(Accountify::InvoiceStatusSummary::RegenerateJob.jobs).to match([ - hash_including( - 'args' => [ - hash_including( - 'tenant_id' => tenant_id, - 'organisation_id' => accountify_organisation.id, - 'invoice_updated_at' => event.created_at.utc.iso8601 )])]) - end - end - - describe 'when Accountify::Models::Invoice::PaidEvent' do - let(:event) do - create( - :accountify_invoice_paid_event, - user_id: user_id, - tenant_id: tenant_id, - eventable: accountify_organisation, - created_at: current_time.utc, - body: { - 'organisation' => { 'id' => accountify_organisation.id } }) - end - - before do - PublishJob.new.perform({ - 'messageable_type' => 'Accountify::Models::Invoice::PaidEvent', - 'messageable_id' => event.id }) - end - - it 'performs Accountify::InvoiceStatusSummary::RegenerateJob async' do - expect(Accountify::InvoiceStatusSummary::RegenerateJob.jobs).to match([ - hash_including( - 'args' => [ - hash_including( - 'tenant_id' => tenant_id, - 'organisation_id' => accountify_organisation.id, - 'invoice_updated_at' => event.created_at.utc.iso8601 )])]) - end - end - - describe 'when Accountify::Models::Invoice::VoidedEvent' do - let(:event) do - create( - :accountify_invoice_voided_event, - user_id: user_id, - tenant_id: tenant_id, - eventable: accountify_organisation, - created_at: current_time.utc, - body: { - 'organisation' => { 'id' => accountify_organisation.id } }) - end - - before do - PublishJob.new.perform({ - 'messageable_type' => 'Accountify::Models::Invoice::VoidedEvent', - 'messageable_id' => event.id }) - end - - it 'performs Accountify::InvoiceStatusSummary::RegenerateJob async' do - expect(Accountify::InvoiceStatusSummary::RegenerateJob.jobs).to match([ - hash_including( - 'args' => [ - hash_including( - 'tenant_id' => tenant_id, - 'organisation_id' => accountify_organisation.id, - 'invoice_updated_at' => event.created_at.utc.iso8601 )])]) - end - end - - describe 'when Accountify::Models::Invoice::DeletedEvent' do - let(:event) do - create( - :accountify_invoice_deleted_event, - user_id: user_id, - tenant_id: tenant_id, - eventable: accountify_organisation, - created_at: current_time.utc, - body: { - 'organisation' => { 'id' => accountify_organisation.id } }) - end - - before do - PublishJob.new.perform({ - 'messageable_type' => 'Accountify::Models::Invoice::DeletedEvent', - 'messageable_id' => event.id }) - end - - it 'performs Accountify::InvoiceStatusSummary::RegenerateJob async' do - expect(Accountify::InvoiceStatusSummary::RegenerateJob.jobs).to match([ - hash_including( - 'args' => [ - hash_including( - 'tenant_id' => tenant_id, - 'organisation_id' => accountify_organisation.id, - 'invoice_updated_at' => event.created_at.utc.iso8601 )])]) + describe '#perform' do + context 'when Accountify::Models::Invoice::DraftedEvent' do + let(:args) do + { + 'messageable_type' => 'Accountify::Models::Invoice::DraftedEvent', + 'messageable_id' => '123' + } + end + + it 'performs Accountify::Invoice::DraftedJob async' do + PublishJob.new.perform(args) + + expect(Accountify::Invoice::DraftedJob.jobs).to match([ + hash_including('args' => [include('id' => '123')]) + ]) + end + end + + context 'with invalid messageable_type' do + let(:args) do + { + 'messageable_type' => 'Wrong::Format::Test', + 'messageable_id' => '123' + } + end + + it 'raises an error for unexpected class name format' do + expect { + PublishJob.new.perform(args) + }.to raise_error(StandardError, "Unexpected class name format: Wrong::Format::Test") + end end end end