Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions app/jobs/accountify/invoice/deleted_job.rb
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions app/jobs/accountify/invoice/drafted_job.rb
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions app/jobs/accountify/invoice/issued_job.rb
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions app/jobs/accountify/invoice/paid_job.rb
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions app/jobs/accountify/invoice/updated_job.rb
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions app/jobs/accountify/invoice/voided_job.rb
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions app/jobs/accountify/organisation/created_job.rb
Original file line number Diff line number Diff line change
@@ -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
56 changes: 11 additions & 45 deletions app/jobs/outboxer_integration/message/publish_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 54 additions & 0 deletions spec/jobs/accountify/invoice/deleted_job_spec.rb
Original file line number Diff line number Diff line change
@@ -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
54 changes: 54 additions & 0 deletions spec/jobs/accountify/invoice/drafted_job_spec.rb
Original file line number Diff line number Diff line change
@@ -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
54 changes: 54 additions & 0 deletions spec/jobs/accountify/invoice/issued_job_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Loading
Loading