diff --git a/app/controllers/accountify/contact_controller.rb b/app/controllers/accountify/contact_controller.rb index 0162b39..f56c851 100644 --- a/app/controllers/accountify/contact_controller.rb +++ b/app/controllers/accountify/contact_controller.rb @@ -1,7 +1,7 @@ module Accountify class ContactController < AccountifyController def create - contact = Contact.create( + contact = ContactService.create( user_id: user_id, tenant_id: tenant_id, organisation_id: params[:organisation_id], @@ -13,7 +13,7 @@ def create end def show - contact = Contact.find_by_id( + contact = ContactService.find_by_id( user_id: user_id, tenant_id: tenant_id, id: params[:id]) @@ -22,7 +22,7 @@ def show end def update - contact = Contact.update( + contact = ContactService.update( user_id: user_id, tenant_id: tenant_id, id: params[:id], @@ -34,7 +34,7 @@ def update end def destroy - contact = Contact.delete( + contact = ContactService.delete( user_id: user_id, tenant_id: tenant_id, id: params[:id]) diff --git a/app/controllers/accountify/invoice_controller.rb b/app/controllers/accountify/invoice_controller.rb index 86f77ee..6053510 100644 --- a/app/controllers/accountify/invoice_controller.rb +++ b/app/controllers/accountify/invoice_controller.rb @@ -1,7 +1,7 @@ module Accountify class InvoiceController < AccountifyController def create - invoice = Invoice.draft( + invoice = InvoiceService.draft( user_id: user_id, tenant_id: tenant_id, organisation_id: params[:organisation_id], @@ -14,7 +14,7 @@ def create end def show - invoice = Invoice.find_by_id( + invoice = InvoiceService.find_by_id( user_id: user_id, tenant_id: tenant_id, id: params[:id]) @@ -23,7 +23,7 @@ def show end def update - invoice = Invoice.update( + invoice = InvoiceService.update( user_id: user_id, tenant_id: tenant_id, id: params[:id], @@ -36,7 +36,7 @@ def update end def destroy - invoice = Invoice.delete( + invoice = InvoiceService.delete( user_id: user_id, tenant_id: tenant_id, id: params[:id]) @@ -45,7 +45,7 @@ def destroy end def issue - invoice = Invoice.issue( + invoice = InvoiceService.issue( user_id: user_id, tenant_id: tenant_id, id: params[:id]) @@ -54,7 +54,7 @@ def issue end def paid - invoice = Invoice.paid( + invoice = InvoiceService.paid( user_id: user_id, tenant_id: tenant_id, id: params[:id]) @@ -63,7 +63,7 @@ def paid end def void - invoice = Invoice.void( + invoice = InvoiceService.void( user_id: user_id, tenant_id: tenant_id, id: params[:id]) diff --git a/app/controllers/accountify/organisation_controller.rb b/app/controllers/accountify/organisation_controller.rb index 23c2dc4..6adbfe3 100644 --- a/app/controllers/accountify/organisation_controller.rb +++ b/app/controllers/accountify/organisation_controller.rb @@ -1,7 +1,7 @@ module Accountify class OrganisationController < AccountifyController def create - organisation = Organisation.create( + organisation = OrganisationService.create( user_id: user_id, tenant_id: tenant_id, name: params[:name]) @@ -10,7 +10,7 @@ def create end def show - organisation = Organisation.find_by_id( + organisation = OrganisationService.find_by_id( user_id: user_id, tenant_id: tenant_id, id: params[:id]) @@ -19,7 +19,7 @@ def show end def update - organisation = Organisation.update( + organisation = OrganisationService.update( user_id: user_id, tenant_id: tenant_id, id: params[:id], @@ -29,7 +29,7 @@ def update end def destroy - organisation = Organisation.delete( + organisation = OrganisationService.delete( user_id: user_id, tenant_id: tenant_id, id: params[:id]) diff --git a/app/domains/accountify/models/contact.rb b/app/domains/accountify/models/contact.rb deleted file mode 100644 index 022769a..0000000 --- a/app/domains/accountify/models/contact.rb +++ /dev/null @@ -1,11 +0,0 @@ -module Accountify - module Models - class Contact < ActiveRecord::Base - self.table_name = 'accountify_contacts' - - validates :organisation_id, presence: true - - has_many :events, -> { order(created_at: :asc) }, as: :eventable, class_name: '::Models::Event' - end - end -end diff --git a/app/domains/accountify/models/contact/created_event.rb b/app/domains/accountify/models/contact/created_event.rb deleted file mode 100644 index 3ce6d5b..0000000 --- a/app/domains/accountify/models/contact/created_event.rb +++ /dev/null @@ -1,9 +0,0 @@ -module Accountify - module Models - class Contact - class CreatedEvent < ::Models::Event - - end - end - end -end diff --git a/app/domains/accountify/models/contact/deleted_event.rb b/app/domains/accountify/models/contact/deleted_event.rb deleted file mode 100644 index e18bc8c..0000000 --- a/app/domains/accountify/models/contact/deleted_event.rb +++ /dev/null @@ -1,9 +0,0 @@ -module Accountify - module Models - class Contact - class DeletedEvent < ::Models::Event - - end - end - end -end diff --git a/app/domains/accountify/models/contact/updated_event.rb b/app/domains/accountify/models/contact/updated_event.rb deleted file mode 100644 index 6a0114d..0000000 --- a/app/domains/accountify/models/contact/updated_event.rb +++ /dev/null @@ -1,9 +0,0 @@ -module Accountify - module Models - class Contact - class UpdatedEvent < ::Models::Event - - end - end - end -end diff --git a/app/domains/accountify/models/invoice.rb b/app/domains/accountify/models/invoice.rb deleted file mode 100644 index 2b73262..0000000 --- a/app/domains/accountify/models/invoice.rb +++ /dev/null @@ -1,15 +0,0 @@ -module Accountify - module Models - class Invoice < ActiveRecord::Base - self.table_name = 'accountify_invoices' - - validates :organisation_id, presence: true - - has_many :line_items, -> { order(id: :asc) } - - has_many :events, -> { order(created_at: :asc) }, as: :eventable, class_name: '::Models::Event' - - has_one :invoice_status_summary - end - end -end diff --git a/app/domains/accountify/models/invoice/deleted_event.rb b/app/domains/accountify/models/invoice/deleted_event.rb deleted file mode 100644 index 7d0ccee..0000000 --- a/app/domains/accountify/models/invoice/deleted_event.rb +++ /dev/null @@ -1,9 +0,0 @@ -module Accountify - module Models - class Invoice - class DeletedEvent < ::Models::Event - - end - end - end -end diff --git a/app/domains/accountify/models/invoice/drafted_event.rb b/app/domains/accountify/models/invoice/drafted_event.rb deleted file mode 100644 index 07cd494..0000000 --- a/app/domains/accountify/models/invoice/drafted_event.rb +++ /dev/null @@ -1,9 +0,0 @@ -module Accountify - module Models - class Invoice - class DraftedEvent < ::Models::Event - - end - end - end -end diff --git a/app/domains/accountify/models/invoice/issued_event.rb b/app/domains/accountify/models/invoice/issued_event.rb deleted file mode 100644 index feb5602..0000000 --- a/app/domains/accountify/models/invoice/issued_event.rb +++ /dev/null @@ -1,9 +0,0 @@ -module Accountify - module Models - class Invoice - class IssuedEvent < ::Models::Event - - end - end - end -end diff --git a/app/domains/accountify/models/invoice/line_item.rb b/app/domains/accountify/models/invoice/line_item.rb deleted file mode 100644 index 0e2adb7..0000000 --- a/app/domains/accountify/models/invoice/line_item.rb +++ /dev/null @@ -1,9 +0,0 @@ -module Accountify - module Models - class Invoice < ActiveRecord::Base - class LineItem < ActiveRecord::Base - - end - end - end -end diff --git a/app/domains/accountify/models/invoice/paid_event.rb b/app/domains/accountify/models/invoice/paid_event.rb deleted file mode 100644 index 8a4b01b..0000000 --- a/app/domains/accountify/models/invoice/paid_event.rb +++ /dev/null @@ -1,9 +0,0 @@ -module Accountify - module Models - class Invoice - class PaidEvent < ::Models::Event - - end - end - end -end diff --git a/app/domains/accountify/models/invoice/updated_event.rb b/app/domains/accountify/models/invoice/updated_event.rb deleted file mode 100644 index 051525a..0000000 --- a/app/domains/accountify/models/invoice/updated_event.rb +++ /dev/null @@ -1,9 +0,0 @@ -module Accountify - module Models - class Invoice - class UpdatedEvent < ::Models::Event - - end - end - end -end diff --git a/app/domains/accountify/models/invoice/voided_event.rb b/app/domains/accountify/models/invoice/voided_event.rb deleted file mode 100644 index 799e1fe..0000000 --- a/app/domains/accountify/models/invoice/voided_event.rb +++ /dev/null @@ -1,9 +0,0 @@ -module Accountify - module Models - class Invoice - class VoidedEvent < ::Models::Event - - end - end - end -end diff --git a/app/domains/accountify/models/invoice_status_summary.rb b/app/domains/accountify/models/invoice_status_summary.rb deleted file mode 100644 index 5fc9713..0000000 --- a/app/domains/accountify/models/invoice_status_summary.rb +++ /dev/null @@ -1,30 +0,0 @@ -module Accountify - module Models - class InvoiceStatusSummary < ActiveRecord::Base - self.table_name = 'accountify_invoice_status_summaries' - - validates :organisation_id, presence: true - - validates :drafted_count, - presence: true, - numericality: { only_integer: true, greater_than_or_equal_to: 0 } - - validates :issued_count, - presence: true, - numericality: { only_integer: true, greater_than_or_equal_to: 0 } - - validates :paid_count, - presence: true, - numericality: { only_integer: true, greater_than_or_equal_to: 0 } - - validates :voided_count, - presence: true, - numericality: { only_integer: true, greater_than_or_equal_to: 0 } - - validates :generated_at, - presence: true - - belongs_to :organisation - end - end -end diff --git a/app/domains/accountify/models/organisation.rb b/app/domains/accountify/models/organisation.rb deleted file mode 100644 index bf1b4dc..0000000 --- a/app/domains/accountify/models/organisation.rb +++ /dev/null @@ -1,11 +0,0 @@ -module Accountify - module Models - class Organisation < ActiveRecord::Base - self.table_name = 'accountify_organisations' - - has_many :events, -> { order(created_at: :asc) }, as: :eventable, class_name: '::Models::Event' - - has_one :invoice_status_summary - end - end -end diff --git a/app/domains/accountify/models/organisation/created_event.rb b/app/domains/accountify/models/organisation/created_event.rb deleted file mode 100644 index 1c498bd..0000000 --- a/app/domains/accountify/models/organisation/created_event.rb +++ /dev/null @@ -1,9 +0,0 @@ -module Accountify - module Models - class Organisation - class CreatedEvent < ::Models::Event - - end - end - end -end diff --git a/app/domains/accountify/models/organisation/deleted_event.rb b/app/domains/accountify/models/organisation/deleted_event.rb deleted file mode 100644 index ccb2cac..0000000 --- a/app/domains/accountify/models/organisation/deleted_event.rb +++ /dev/null @@ -1,9 +0,0 @@ -module Accountify - module Models - class Organisation - class DeletedEvent < ::Models::Event - - end - end - end -end diff --git a/app/domains/accountify/models/organisation/updated_event.rb b/app/domains/accountify/models/organisation/updated_event.rb deleted file mode 100644 index 40d61ec..0000000 --- a/app/domains/accountify/models/organisation/updated_event.rb +++ /dev/null @@ -1,9 +0,0 @@ -module Accountify - module Models - class Organisation - class UpdatedEvent < ::Models::Event - - end - end - end -end diff --git a/app/domains/models/event.rb b/app/domains/models/event.rb deleted file mode 100644 index cb9f466..0000000 --- a/app/domains/models/event.rb +++ /dev/null @@ -1,21 +0,0 @@ -module Models - class Event < ActiveRecord::Base - self.table_name = 'events' - - # associations - - belongs_to :eventable, polymorphic: true - - # validations - - validates :user_id, presence: true - validates :tenant_id, presence: true - - validates :type, presence: true, length: { maximum: 255 } - - validates :eventable_type, presence: true, length: { maximum: 255 }, - if: -> { eventable_id.present? } - - validates :eventable_id, presence: true, if: -> { eventable_type.present? } - end -end diff --git a/app/jobs/accountify/generate_invoice_status_summary_job.rb b/app/jobs/accountify/generate_invoice_status_summary_job.rb new file mode 100644 index 0000000..83e5e8b --- /dev/null +++ b/app/jobs/accountify/generate_invoice_status_summary_job.rb @@ -0,0 +1,11 @@ +module Accountify + class GenerateInvoiceStatusSummaryJob + include Sidekiq::Job + + sidekiq_options queue: 'reporting', backtrace: true + + def perform(args) + InvoiceStatusSummary.generate(event_id: args['event_id']) + end + end +end diff --git a/app/jobs/accountify/invoice/deleted_job.rb b/app/jobs/accountify/invoice/deleted_job.rb deleted file mode 100644 index 9d072b4..0000000 --- a/app/jobs/accountify/invoice/deleted_job.rb +++ /dev/null @@ -1,13 +0,0 @@ -module Accountify - module Invoice - class DeletedJob - include Sidekiq::Job - - sidekiq_options retry: false, backtrace: true - - def perform(args) - InvoiceStatusSummary::RegenerateJob.perform_async({ 'event_id' => args['event_id'] }) - end - end - end -end diff --git a/app/jobs/accountify/invoice/drafted_job.rb b/app/jobs/accountify/invoice/drafted_job.rb deleted file mode 100644 index 2d02e68..0000000 --- a/app/jobs/accountify/invoice/drafted_job.rb +++ /dev/null @@ -1,13 +0,0 @@ -module Accountify - module Invoice - class DraftedJob - include Sidekiq::Job - - sidekiq_options retry: false, backtrace: true - - def perform(args) - InvoiceStatusSummary::RegenerateJob.perform_async({ 'event_id' => args['event_id'] }) - end - end - end -end diff --git a/app/jobs/accountify/invoice/issued_job.rb b/app/jobs/accountify/invoice/issued_job.rb deleted file mode 100644 index daf97cc..0000000 --- a/app/jobs/accountify/invoice/issued_job.rb +++ /dev/null @@ -1,13 +0,0 @@ -module Accountify - module Invoice - class IssuedJob - include Sidekiq::Job - - sidekiq_options retry: false, backtrace: true - - def perform(args) - InvoiceStatusSummary::RegenerateJob.perform_async({ 'event_id' => args['event_id'] }) - end - end - end -end diff --git a/app/jobs/accountify/invoice/paid_job.rb b/app/jobs/accountify/invoice/paid_job.rb deleted file mode 100644 index c510aaf..0000000 --- a/app/jobs/accountify/invoice/paid_job.rb +++ /dev/null @@ -1,13 +0,0 @@ -module Accountify - module Invoice - class PaidJob - include Sidekiq::Job - - sidekiq_options retry: false, backtrace: true - - def perform(args) - InvoiceStatusSummary::RegenerateJob.perform_async({ 'event_id' => args['event_id'] }) - end - end - end -end diff --git a/app/jobs/accountify/invoice/updated_job.rb b/app/jobs/accountify/invoice/updated_job.rb deleted file mode 100644 index 2910362..0000000 --- a/app/jobs/accountify/invoice/updated_job.rb +++ /dev/null @@ -1,13 +0,0 @@ -module Accountify - module Invoice - class UpdatedJob - include Sidekiq::Job - - sidekiq_options retry: false, backtrace: true - - def perform(args) - InvoiceStatusSummary::RegenerateJob.perform_async({ 'event_id' => args['event_id'] }) - end - end - end -end diff --git a/app/jobs/accountify/invoice/voided_job.rb b/app/jobs/accountify/invoice/voided_job.rb deleted file mode 100644 index 4f371b9..0000000 --- a/app/jobs/accountify/invoice/voided_job.rb +++ /dev/null @@ -1,13 +0,0 @@ -module Accountify - module Invoice - class VoidedJob - include Sidekiq::Job - - sidekiq_options retry: false, backtrace: true - - def perform(args) - InvoiceStatusSummary::RegenerateJob.perform_async({ 'event_id' => args['event_id'] }) - end - end - end -end diff --git a/app/jobs/accountify/invoice_deleted_job.rb b/app/jobs/accountify/invoice_deleted_job.rb new file mode 100644 index 0000000..42b1b71 --- /dev/null +++ b/app/jobs/accountify/invoice_deleted_job.rb @@ -0,0 +1,11 @@ +module Accountify + class InvoiceDeletedJob + include Sidekiq::Job + + sidekiq_options retry: false, backtrace: true + + def perform(args) + RegenerateInvoiceStatusSummaryJob.perform_async({ 'event_id' => args['event_id'] }) + 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..0860f2a --- /dev/null +++ b/app/jobs/accountify/invoice_drafted_job.rb @@ -0,0 +1,11 @@ +module Accountify + class InvoiceDraftedJob + include Sidekiq::Job + + sidekiq_options retry: false, backtrace: true + + def perform(args) + RegenerateInvoiceStatusSummaryJob.perform_async({ 'event_id' => args['event_id'] }) + 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..97f680d --- /dev/null +++ b/app/jobs/accountify/invoice_issued_job.rb @@ -0,0 +1,11 @@ +module Accountify + class InvoiceIssuedJob + include Sidekiq::Job + + sidekiq_options retry: false, backtrace: true + + def perform(args) + RegenerateInvoiceStatusSummaryJob.perform_async({ 'event_id' => args['event_id'] }) + 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..54e2c89 --- /dev/null +++ b/app/jobs/accountify/invoice_paid_job.rb @@ -0,0 +1,11 @@ +module Accountify + class InvoicePaidJob + include Sidekiq::Job + + sidekiq_options retry: false, backtrace: true + + def perform(args) + RegenerateInvoiceStatusSummaryJob.perform_async({ 'event_id' => args['event_id'] }) + end + end +end diff --git a/app/jobs/accountify/invoice_status_summary/generate_job.rb b/app/jobs/accountify/invoice_status_summary/generate_job.rb deleted file mode 100644 index 22e727a..0000000 --- a/app/jobs/accountify/invoice_status_summary/generate_job.rb +++ /dev/null @@ -1,13 +0,0 @@ -module Accountify - module InvoiceStatusSummary - class GenerateJob - include Sidekiq::Job - - sidekiq_options queue: 'reporting', backtrace: true - - def perform(args) - InvoiceStatusSummary.generate(event_id: args['event_id']) - end - end - end -end diff --git a/app/jobs/accountify/invoice_status_summary/regenerate_job.rb b/app/jobs/accountify/invoice_status_summary/regenerate_job.rb deleted file mode 100644 index 328436c..0000000 --- a/app/jobs/accountify/invoice_status_summary/regenerate_job.rb +++ /dev/null @@ -1,15 +0,0 @@ -module Accountify - module InvoiceStatusSummary - class RegenerateJob - include Sidekiq::Job - - sidekiq_options queue: 'reporting', backtrace: true - - def perform(args) - InvoiceStatusSummary.regenerate(event_id: args['event_id']) - rescue NotAvailable - RegenerateJob.perform_in(1.minute, args) - 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..b3322f9 --- /dev/null +++ b/app/jobs/accountify/invoice_updated_job.rb @@ -0,0 +1,11 @@ +module Accountify + class InvoiceUpdatedJob + include Sidekiq::Job + + sidekiq_options retry: false, backtrace: true + + def perform(args) + RegenerateInvoiceStatusSummaryJob.perform_async({ 'event_id' => args['event_id'] }) + 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..2d002d2 --- /dev/null +++ b/app/jobs/accountify/invoice_voided_job.rb @@ -0,0 +1,11 @@ +module Accountify + class InvoiceVoidedJob + include Sidekiq::Job + + sidekiq_options retry: false, backtrace: true + + def perform(args) + RegenerateInvoiceStatusSummaryJob.perform_async({ 'event_id' => args['event_id'] }) + end + end +end diff --git a/app/jobs/accountify/organisation/created_job.rb b/app/jobs/accountify/organisation/created_job.rb deleted file mode 100644 index c4243c2..0000000 --- a/app/jobs/accountify/organisation/created_job.rb +++ /dev/null @@ -1,13 +0,0 @@ -module Accountify - module Organisation - class CreatedJob - include Sidekiq::Job - - sidekiq_options retry: false, backtrace: true - - def perform(args) - InvoiceStatusSummary::GenerateJob.perform_async({ 'event_id' => args['event_id'] }) - 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..7f94101 --- /dev/null +++ b/app/jobs/accountify/organisation_created_job.rb @@ -0,0 +1,11 @@ +module Accountify + class OrganisationCreatedJob + include Sidekiq::Job + + sidekiq_options retry: false, backtrace: true + + def perform(args) + GenerateInvoiceStatusSummaryJob.perform_async({ 'event_id' => args['event_id'] }) + end + end +end diff --git a/app/jobs/accountify/regenerate_invoice_status_summary_job.rb b/app/jobs/accountify/regenerate_invoice_status_summary_job.rb new file mode 100644 index 0000000..927004f --- /dev/null +++ b/app/jobs/accountify/regenerate_invoice_status_summary_job.rb @@ -0,0 +1,13 @@ +module Accountify + class RegenerateInvoiceStatusSummaryJob + include Sidekiq::Job + + sidekiq_options queue: 'reporting', backtrace: true + + def perform(args) + InvoiceStatusSummary.regenerate(event_id: args['event_id']) + rescue NotAvailable + RegenerateJob.perform_in(1.minute, args) + end + end +end diff --git a/app/jobs/outboxer_integration/message/publish_job.rb b/app/jobs/outboxer_integration/message/publish_job.rb deleted file mode 100644 index c951d45..0000000 --- a/app/jobs/outboxer_integration/message/publish_job.rb +++ /dev/null @@ -1,29 +0,0 @@ -module OutboxerIntegration - module Message - class PublishJob - include Sidekiq::Job - - sidekiq_options retry: false, backtrace: true - - MESSAGEABLE_TYPE_REGEX = /\A([A-Za-z]+)::Models::([A-Za-z]+)::([A-Za-z]+)Event\z/ - - def perform(args) - messageable_type = args['messageable_type'] - - 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" - - begin - job_class = job_class_name.constantize - job_class.perform_async({ 'id' => args['messageable_id'] }) - rescue NameError - # no-op - end - end - end - end -end diff --git a/app/models/accountify/contact.rb b/app/models/accountify/contact.rb new file mode 100644 index 0000000..0b3b93c --- /dev/null +++ b/app/models/accountify/contact.rb @@ -0,0 +1,9 @@ +module Accountify + class Contact < ActiveRecord::Base + self.table_name = 'accountify_contacts' + + validates :organisation_id, presence: true + + has_many :events, -> { order(created_at: :asc) }, as: :eventable + end +end diff --git a/app/models/accountify/contact_created_event.rb b/app/models/accountify/contact_created_event.rb new file mode 100644 index 0000000..1402e2f --- /dev/null +++ b/app/models/accountify/contact_created_event.rb @@ -0,0 +1,4 @@ +module Accountify + class ContactCreatedEvent < Event + end +end diff --git a/app/models/accountify/contact_deleted_event.rb b/app/models/accountify/contact_deleted_event.rb new file mode 100644 index 0000000..64557c2 --- /dev/null +++ b/app/models/accountify/contact_deleted_event.rb @@ -0,0 +1,5 @@ +module Accountify + class ContactDeletedEvent < Event + + end +end diff --git a/app/models/accountify/contact_updated_event.rb b/app/models/accountify/contact_updated_event.rb new file mode 100644 index 0000000..442756d --- /dev/null +++ b/app/models/accountify/contact_updated_event.rb @@ -0,0 +1,5 @@ +module Accountify + class ContactUpdatedEvent < Event + + end +end diff --git a/app/models/accountify/invoice.rb b/app/models/accountify/invoice.rb new file mode 100644 index 0000000..d2f6922 --- /dev/null +++ b/app/models/accountify/invoice.rb @@ -0,0 +1,20 @@ +module Accountify + class Invoice < ActiveRecord::Base + self.table_name = 'accountify_invoices' + + module Status + DRAFTED = 'drafted' + ISSUED = 'issued' + PAID = 'paid' + VOIDED = 'voided' + end + + validates :organisation_id, presence: true + + has_many :line_items, -> { order(id: :asc) }, class_name: 'Accountify::InvoiceLineItem' + + has_many :events, -> { order(created_at: :asc) }, as: :eventable + + has_one :invoice_status_summary + end +end diff --git a/app/models/accountify/invoice_deleted_event.rb b/app/models/accountify/invoice_deleted_event.rb new file mode 100644 index 0000000..b4e8434 --- /dev/null +++ b/app/models/accountify/invoice_deleted_event.rb @@ -0,0 +1,5 @@ +module Accountify + class InvoiceDeletedEvent < Event + + end +end diff --git a/app/models/accountify/invoice_drafted_event.rb b/app/models/accountify/invoice_drafted_event.rb new file mode 100644 index 0000000..fe5a0c8 --- /dev/null +++ b/app/models/accountify/invoice_drafted_event.rb @@ -0,0 +1,5 @@ +module Accountify + class InvoiceDraftedEvent < Event + + end +end diff --git a/app/models/accountify/invoice_issued_event.rb b/app/models/accountify/invoice_issued_event.rb new file mode 100644 index 0000000..05fd5fb --- /dev/null +++ b/app/models/accountify/invoice_issued_event.rb @@ -0,0 +1,5 @@ +module Accountify + class InvoiceIssuedEvent < Event + + end +end diff --git a/app/models/accountify/invoice_line_item.rb b/app/models/accountify/invoice_line_item.rb new file mode 100644 index 0000000..423ea55 --- /dev/null +++ b/app/models/accountify/invoice_line_item.rb @@ -0,0 +1,5 @@ +module Accountify + class InvoiceLineItem < ActiveRecord::Base + self.table_name = 'accountify_invoice_line_items' + end +end diff --git a/app/models/accountify/invoice_paid_event.rb b/app/models/accountify/invoice_paid_event.rb new file mode 100644 index 0000000..15c7400 --- /dev/null +++ b/app/models/accountify/invoice_paid_event.rb @@ -0,0 +1,5 @@ +module Accountify + class InvoicePaidEvent < Event + + end +end diff --git a/app/models/accountify/invoice_status_summary.rb b/app/models/accountify/invoice_status_summary.rb new file mode 100644 index 0000000..be8ae55 --- /dev/null +++ b/app/models/accountify/invoice_status_summary.rb @@ -0,0 +1,28 @@ +module Accountify + class InvoiceStatusSummary < ActiveRecord::Base + self.table_name = 'accountify_invoice_status_summaries' + + validates :organisation_id, presence: true + + validates :drafted_count, + presence: true, + numericality: { only_integer: true, greater_than_or_equal_to: 0 } + + validates :issued_count, + presence: true, + numericality: { only_integer: true, greater_than_or_equal_to: 0 } + + validates :paid_count, + presence: true, + numericality: { only_integer: true, greater_than_or_equal_to: 0 } + + validates :voided_count, + presence: true, + numericality: { only_integer: true, greater_than_or_equal_to: 0 } + + validates :generated_at, + presence: true + + belongs_to :organisation + end +end diff --git a/app/models/accountify/invoice_updated_event.rb b/app/models/accountify/invoice_updated_event.rb new file mode 100644 index 0000000..d442b55 --- /dev/null +++ b/app/models/accountify/invoice_updated_event.rb @@ -0,0 +1,5 @@ +module Accountify + class InvoiceUpdatedEvent < Event + + end +end diff --git a/app/models/accountify/invoice_voided_event.rb b/app/models/accountify/invoice_voided_event.rb new file mode 100644 index 0000000..ba0b95c --- /dev/null +++ b/app/models/accountify/invoice_voided_event.rb @@ -0,0 +1,5 @@ +module Accountify + class InvoiceVoidedEvent < Event + + end +end diff --git a/app/models/accountify/organisation.rb b/app/models/accountify/organisation.rb new file mode 100644 index 0000000..f87f0be --- /dev/null +++ b/app/models/accountify/organisation.rb @@ -0,0 +1,9 @@ +module Accountify + class Organisation < ActiveRecord::Base + self.table_name = 'accountify_organisations' + + has_many :events, -> { order(created_at: :asc) }, as: :eventable + + has_one :invoice_status_summary + end +end diff --git a/app/models/accountify/organisation_created_event.rb b/app/models/accountify/organisation_created_event.rb new file mode 100644 index 0000000..d5c1a05 --- /dev/null +++ b/app/models/accountify/organisation_created_event.rb @@ -0,0 +1,5 @@ +module Accountify + class OrganisationCreatedEvent < Event + + end +end diff --git a/app/models/accountify/organisation_deleted_event.rb b/app/models/accountify/organisation_deleted_event.rb new file mode 100644 index 0000000..67583a3 --- /dev/null +++ b/app/models/accountify/organisation_deleted_event.rb @@ -0,0 +1,5 @@ +module Accountify + class OrganisationDeletedEvent < Event + + end +end diff --git a/app/models/accountify/organisation_updated_event.rb b/app/models/accountify/organisation_updated_event.rb new file mode 100644 index 0000000..836d0f9 --- /dev/null +++ b/app/models/accountify/organisation_updated_event.rb @@ -0,0 +1,5 @@ +module Accountify + class OrganisationUpdatedEvent < Event + + end +end diff --git a/app/models/event.rb b/app/models/event.rb new file mode 100644 index 0000000..dbc5573 --- /dev/null +++ b/app/models/event.rb @@ -0,0 +1,19 @@ +class Event < ActiveRecord::Base + self.table_name = 'events' + + # associations + + belongs_to :eventable, polymorphic: true + + # validations + + validates :user_id, presence: true + validates :tenant_id, presence: true + + validates :type, presence: true, length: { maximum: 255 } + + validates :eventable_type, presence: true, length: { maximum: 255 }, + if: -> { eventable_id.present? } + + validates :eventable_id, presence: true, if: -> { eventable_type.present? } +end diff --git a/app/domains/accountify/contact.rb b/app/services/accountify/contact_service.rb similarity index 90% rename from app/domains/accountify/contact.rb rename to app/services/accountify/contact_service.rb index e6c96d2..2b34c60 100644 --- a/app/domains/accountify/contact.rb +++ b/app/services/accountify/contact_service.rb @@ -1,5 +1,5 @@ module Accountify - module Contact + module ContactService extend self def create(user_id:, tenant_id:, @@ -8,7 +8,7 @@ def create(user_id:, tenant_id:, event = nil ActiveRecord::Base.transaction do - contact = Models::Contact + contact = Contact .create!( tenant_id: tenant_id, organisation_id: organisation_id, @@ -16,7 +16,7 @@ def create(user_id:, tenant_id:, last_name: last_name, email: email) - event = Models::Contact::CreatedEvent + event = ContactCreatedEvent .create!( user_id: user_id, tenant_id: tenant_id, @@ -33,7 +33,7 @@ def create(user_id:, tenant_id:, end def find_by_id(user_id:, tenant_id:, id:) - contact = Models::Contact + contact = Contact .includes(:events) .where(tenant_id: tenant_id) .find_by!(id: id) @@ -62,7 +62,7 @@ def update(user_id:, tenant_id:, id:, event = nil ActiveRecord::Base.transaction do - contact = Models::Contact + contact = Contact .where(tenant_id: tenant_id).lock.find_by!(id: id) contact.update!( @@ -70,7 +70,7 @@ def update(user_id:, tenant_id:, id:, last_name: last_name, email: email) - event = Models::Contact::UpdatedEvent + event = ContactUpdatedEvent .create!( user_id: user_id, tenant_id: tenant_id, @@ -91,12 +91,12 @@ def delete(user_id:, tenant_id:, id:, time: ::Time) event = nil ActiveRecord::Base.transaction do - contact = Models::Contact + contact = Contact .where(tenant_id: tenant_id).lock.find_by!(id: id) contact.update!(deleted_at: time.now.utc) - event = Models::Contact::DeletedEvent + event = ContactDeletedEvent .create!( user_id: user_id, tenant_id: tenant_id, diff --git a/app/domains/accountify/error.rb b/app/services/accountify/error.rb similarity index 100% rename from app/domains/accountify/error.rb rename to app/services/accountify/error.rb diff --git a/app/domains/accountify/invoice.rb b/app/services/accountify/invoice_service.rb similarity index 88% rename from app/domains/accountify/invoice.rb rename to app/services/accountify/invoice_service.rb index 60f6fef..3096a88 100644 --- a/app/domains/accountify/invoice.rb +++ b/app/services/accountify/invoice_service.rb @@ -1,14 +1,7 @@ module Accountify - module Invoice + module InvoiceService extend self - module Status - DRAFTED = 'drafted' - ISSUED = 'issued' - PAID = 'paid' - VOIDED = 'voided' - end - def draft(user_id:, tenant_id:, organisation_id:, contact_id:, currency_code:, due_date:, line_items:, @@ -19,19 +12,19 @@ def draft(user_id:, tenant_id:, current_utc_time = time.now.utc ActiveRecord::Base.transaction do - organisation = Models::Organisation + organisation = Organisation .where(tenant_id: tenant_id) .find_by!(id: organisation_id) - contact = Models::Contact + contact = Contact .where(tenant_id: tenant_id) .find_by!(organisation_id: organisation.id, id: contact_id) - invoice = Models::Invoice.create!( + invoice = Invoice.create!( tenant_id: tenant_id, organisation_id: organisation_id, contact_id: contact_id, - status: Status::DRAFTED, + status: Invoice::Status::DRAFTED, currency_code: currency_code, due_date: due_date, sub_total_amount: line_items.sum do |line_item| @@ -49,7 +42,7 @@ def draft(user_id:, tenant_id:, quantity: line_item[:quantity]) end - event = Models::Invoice::DraftedEvent.create!( + event = InvoiceDraftedEvent.create!( user_id: user_id, tenant_id: tenant_id, created_at: current_utc_time, @@ -79,7 +72,7 @@ def draft(user_id:, tenant_id:, end def find_by_id(user_id:, tenant_id:, id:) - invoice = Models::Invoice + invoice = Invoice .includes(:events) .where(tenant_id: tenant_id) .find_by!(id: id) @@ -126,15 +119,15 @@ def update(user_id:, tenant_id:, id:, current_utc_time = time.now.utc ActiveRecord::Base.transaction do - organisation = Models::Organisation + organisation = Organisation .where(tenant_id: tenant_id) .find_by!(id: organisation_id) - contact = Models::Contact + contact = Contact .where(tenant_id: tenant_id) .find_by!(organisation_id: organisation.id, id: contact_id) - invoice = Models::Invoice + invoice = Invoice .where(tenant_id: tenant_id).lock.find_by!(id: id) invoice.line_items.destroy_all @@ -144,7 +137,7 @@ def update(user_id:, tenant_id:, id:, organisation_id: organisation.id, updated_at: current_utc_time, contact_id: contact.id, - status: Status::DRAFTED, + status: Invoice::Status::DRAFTED, due_date: due_date, sub_total_amount: line_items.sum do |line_item| BigDecimal(line_item[:unit_amount][:amount]) * line_item[:quantity].to_i @@ -158,7 +151,7 @@ def update(user_id:, tenant_id:, id:, quantity: line_item[:quantity]) end - event = Models::Invoice::UpdatedEvent.create!( + event = InvoiceUpdatedEvent.create!( user_id: user_id, tenant_id: tenant_id, created_at: current_utc_time, @@ -194,11 +187,11 @@ def delete(user_id:, tenant_id:, id:, time: ::Time) current_utc_time = time.now.utc ActiveRecord::Base.transaction do - invoice = Models::Invoice.where(tenant_id: tenant_id).lock.find_by!(id: id) + invoice = Invoice.where(tenant_id: tenant_id).lock.find_by!(id: id) invoice.update!(updated_at: current_utc_time, deleted_at: current_utc_time) - event = Models::Invoice::DeletedEvent.create!( + event = InvoiceDeletedEvent.create!( user_id: user_id, tenant_id: tenant_id, created_at: current_utc_time, @@ -220,14 +213,14 @@ def issue(user_id:, tenant_id:, id:, time: ::Time) current_utc_time = time.now.utc ActiveRecord::Base.transaction do - invoice = Models::Invoice.where(tenant_id: tenant_id).lock.find_by!(id: id) + invoice = Invoice.where(tenant_id: tenant_id).lock.find_by!(id: id) invoice.update!( status: Invoice::Status::ISSUED, issued_at: current_utc_time, updated_at: current_utc_time) - event = Models::Invoice::IssuedEvent.create!( + event = InvoiceIssuedEvent.create!( user_id: user_id, tenant_id: tenant_id, created_at: current_utc_time, @@ -250,7 +243,7 @@ def paid(user_id:, tenant_id:, id:, time: ::Time) current_utc_time = time.now.utc ActiveRecord::Base.transaction do - invoice = Models::Invoice.where(tenant_id: tenant_id).lock.find_by!(id: id) + invoice = Invoice.where(tenant_id: tenant_id).lock.find_by!(id: id) if invoice.status != Invoice::Status::ISSUED raise "Accountify::Invoice #{id} must be issued, not #{invoice.status}" @@ -258,7 +251,7 @@ def paid(user_id:, tenant_id:, id:, time: ::Time) invoice.update!(status: Invoice::Status::PAID, paid_at: Time.current) - event = Models::Invoice::PaidEvent.create!( + event = InvoicePaidEvent.create!( user_id: user_id, tenant_id: tenant_id, eventable: invoice, @@ -279,11 +272,11 @@ def void(user_id:, tenant_id:, id:, time: ::Time) event = nil ActiveRecord::Base.transaction do - invoice = Models::Invoice.where(tenant_id: tenant_id).lock.find_by!(id: id) + invoice = Invoice.where(tenant_id: tenant_id).lock.find_by!(id: id) invoice.update!(status: Invoice::Status::VOIDED) - event = Models::Invoice::VoidedEvent.create!( + event = InvoiceVoidedEvent.create!( user_id: user_id, tenant_id: tenant_id, eventable: invoice, diff --git a/app/domains/accountify/invoice_status_summary.rb b/app/services/accountify/invoice_status_summary_service.rb similarity index 89% rename from app/domains/accountify/invoice_status_summary.rb rename to app/services/accountify/invoice_status_summary_service.rb index 4240011..08c69e7 100644 --- a/app/domains/accountify/invoice_status_summary.rb +++ b/app/services/accountify/invoice_status_summary_service.rb @@ -1,5 +1,5 @@ module Accountify - module InvoiceStatusSummary + module InvoiceStatusSummaryService extend self def generate(event_id:, time: ::Time) @@ -10,16 +10,16 @@ def generate(event_id:, time: ::Time) ActiveRecord::Base.connection_pool.with_connection do ActiveRecord::Base.transaction(isolation: :repeatable_read) do - event = ::Models::Event.find(event_id) + event = Event.find(event_id) tenant_id = event.tenant_id organisation_id = event.body['organisation']['id'] - grouped_invoices = Models::Invoice + grouped_invoices = Invoice .where(tenant_id: tenant_id, organisation_id: organisation_id).group(:status) .count - Models::InvoiceStatusSummary.create!( + InvoiceStatusSummary.create!( tenant_id: tenant_id, organisation_id: organisation_id, generated_at: current_utc_time, @@ -41,17 +41,17 @@ def regenerate(event_id:, invoice_updated_at: ::Time.now.utc, time: ::Time) ActiveRecord::Base.connection_pool.with_connection do ActiveRecord::Base.transaction(isolation: :repeatable_read) do - event = ::Models::Event.find(event_id) + event = Event.find(event_id) tenant_id = event.tenant_id organisation_id = event.body['organisation']['id'] - summary = Models::InvoiceStatusSummary + summary = InvoiceStatusSummary .where('generated_at <= ?', invoice_updated_at) .lock('FOR UPDATE NOWAIT') .find_by!(tenant_id: tenant_id, organisation_id: organisation_id) - grouped_invoices = Models::Invoice + grouped_invoices = Invoice .where(tenant_id: tenant_id, organisation_id: organisation_id).group(:status) .count @@ -74,7 +74,7 @@ def regenerate(event_id:, invoice_updated_at: ::Time.now.utc, time: ::Time) def find_by_organisation_id(tenant_id:, organisation_id:) ActiveRecord::Base.connection_pool.with_connection do - summary = Models::InvoiceStatusSummary + summary = InvoiceStatusSummary .find_by!(tenant_id: tenant_id, organisation_id: organisation_id) { diff --git a/app/domains/accountify/not_available.rb b/app/services/accountify/not_available.rb similarity index 100% rename from app/domains/accountify/not_available.rb rename to app/services/accountify/not_available.rb diff --git a/app/domains/accountify/not_found.rb b/app/services/accountify/not_found.rb similarity index 100% rename from app/domains/accountify/not_found.rb rename to app/services/accountify/not_found.rb diff --git a/app/domains/accountify/organisation.rb b/app/services/accountify/organisation_service.rb similarity index 87% rename from app/domains/accountify/organisation.rb rename to app/services/accountify/organisation_service.rb index 40ef7c4..1cf5811 100644 --- a/app/domains/accountify/organisation.rb +++ b/app/services/accountify/organisation_service.rb @@ -1,5 +1,5 @@ module Accountify - module Organisation + module OrganisationService extend self def create(user_id:, tenant_id:, name:) @@ -7,11 +7,11 @@ def create(user_id:, tenant_id:, name:) event = nil ActiveRecord::Base.transaction do - organisation = Models::Organisation + organisation = Organisation .where(tenant_id: tenant_id) .create!(name: name) - event = Models::Organisation::CreatedEvent + event = OrganisationCreatedEvent .where(user_id: user_id, tenant_id: tenant_id) .create!( eventable: organisation, @@ -25,7 +25,7 @@ def create(user_id:, tenant_id:, name:) end def find_by_id(user_id:, tenant_id:, id:) - organisation = Models::Organisation + organisation = Organisation .includes(:events) .where(tenant_id: tenant_id) .find_by!(id: id) @@ -51,12 +51,12 @@ def update(user_id:, tenant_id:, id:, name:) event = nil ActiveRecord::Base.transaction do - organisation = Models::Organisation + organisation = Organisation .where(tenant_id: tenant_id).lock.find_by!(id: id) organisation.update!(name: name) - event = Models::Organisation::UpdatedEvent + event = OrganisationUpdatedEvent .where(user_id: user_id, tenant_id: tenant_id) .create!( eventable: organisation, @@ -74,12 +74,12 @@ def delete(user_id:, tenant_id:, id:, time: ::Time) event = nil ActiveRecord::Base.transaction do - organisation = Models::Organisation + organisation = Organisation .where(tenant_id: tenant_id).lock.find_by!(id: id) organisation.update!(deleted_at: time.now.utc) - event = Models::Organisation::DeletedEvent + event = OrganisationDeletedEvent .where(user_id: user_id, tenant_id: tenant_id) .create!( eventable: organisation, diff --git a/spec/controllers/accountify/contact_controller_spec.rb b/spec/controllers/accountify/contact_controller_spec.rb index 1c14b7f..b4ec8bb 100644 --- a/spec/controllers/accountify/contact_controller_spec.rb +++ b/spec/controllers/accountify/contact_controller_spec.rb @@ -69,7 +69,7 @@ module Accountify expect(response).to have_http_status(:ok) expect(JSON.parse(response.body)).to have_key('id') expect(JSON.parse(response.body)).to have_key('events') - expect(Models::Contact.find_by(deleted_at: nil, id: contact.id)).to be_nil + expect(Contact.find_by(deleted_at: nil, id: contact.id)).to be_nil end end end diff --git a/spec/controllers/accountify/invoice_controller/create_spec.rb b/spec/controllers/accountify/invoice_controller/create_spec.rb index a477bca..3dbd3e1 100644 --- a/spec/controllers/accountify/invoice_controller/create_spec.rb +++ b/spec/controllers/accountify/invoice_controller/create_spec.rb @@ -42,13 +42,13 @@ module Accountify let!(:response_body_json) { JSON.parse(response.body) } let(:invoice) do - Models::Invoice + Invoice .where(tenant_id: tenant_id) .find_by!(id: response_body_json['id']) end let(:event) do - Models::Invoice::DraftedEvent + InvoiceDraftedEvent .where(tenant_id: tenant_id) .find_by!(id: response_body_json['events'].last['id']) end diff --git a/spec/controllers/accountify/invoice_controller/delete_spec.rb b/spec/controllers/accountify/invoice_controller/delete_spec.rb index 27f7ae3..2e5aefa 100644 --- a/spec/controllers/accountify/invoice_controller/delete_spec.rb +++ b/spec/controllers/accountify/invoice_controller/delete_spec.rb @@ -51,7 +51,7 @@ module Accountify let!(:response_body_json) { JSON.parse(response.body) } let(:event) do - Models::Invoice::DeletedEvent + InvoiceDeletedEvent .where(tenant_id: tenant_id) .find_by!(id: response_body_json['events'].last['id']) end @@ -65,7 +65,7 @@ module Accountify it 'deletes the invoice' do expect( - Models::Invoice + Invoice .where.not(deleted_at: nil) .where(tenant_id: tenant_id) .exists?(id: invoice.id) diff --git a/spec/controllers/accountify/invoice_controller/issue_spec.rb b/spec/controllers/accountify/invoice_controller/issue_spec.rb index a9291fd..0d6e511 100644 --- a/spec/controllers/accountify/invoice_controller/issue_spec.rb +++ b/spec/controllers/accountify/invoice_controller/issue_spec.rb @@ -52,13 +52,13 @@ module Accountify let!(:response_body_json) { JSON.parse(response.body) } let(:event) do - Models::Invoice::IssuedEvent + InvoiceIssuedEvent .where(tenant_id: tenant_id) .find_by!(id: response_body_json['events'].last['id']) end let(:invoice) do - Models::Invoice.where(tenant_id: tenant_id).find_by!(id: id) + Invoice.where(tenant_id: tenant_id).find_by!(id: id) end describe 'PATCH #issue' do diff --git a/spec/controllers/accountify/invoice_controller/paid_spec.rb b/spec/controllers/accountify/invoice_controller/paid_spec.rb index 018c4fa..556a783 100644 --- a/spec/controllers/accountify/invoice_controller/paid_spec.rb +++ b/spec/controllers/accountify/invoice_controller/paid_spec.rb @@ -52,13 +52,13 @@ module Accountify let!(:response_body_json) { JSON.parse(response.body) } let(:event) do - Models::Invoice::PaidEvent + InvoicePaidEvent .where(tenant_id: tenant_id) .find_by!(id: response_body_json['events'].last['id']) end let(:invoice) do - Models::Invoice.where(tenant_id: tenant_id).find_by!(id: id) + Invoice.where(tenant_id: tenant_id).find_by!(id: id) end describe 'PATCH #paid' do diff --git a/spec/controllers/accountify/invoice_controller/update_spec.rb b/spec/controllers/accountify/invoice_controller/update_spec.rb index 0008751..3da654f 100644 --- a/spec/controllers/accountify/invoice_controller/update_spec.rb +++ b/spec/controllers/accountify/invoice_controller/update_spec.rb @@ -75,7 +75,7 @@ module Accountify let!(:response_body_json) { JSON.parse(response.body) } let(:event) do - Models::Invoice::UpdatedEvent + InvoiceUpdatedEvent .where(tenant_id: tenant_id) .find_by!(id: response_body_json['events'].last['id']) end diff --git a/spec/controllers/accountify/invoice_controller/void_spec.rb b/spec/controllers/accountify/invoice_controller/void_spec.rb index 8b0ef7f..6335339 100644 --- a/spec/controllers/accountify/invoice_controller/void_spec.rb +++ b/spec/controllers/accountify/invoice_controller/void_spec.rb @@ -52,7 +52,7 @@ module Accountify let!(:response_body_json) { JSON.parse(response.body) } let(:event) do - Models::Invoice::VoidedEvent + InvoiceVoidedEvent .where(tenant_id: tenant_id) .find_by!(id: response_body_json['events'].last['id']) end @@ -66,7 +66,7 @@ module Accountify it 'updates the invoice status to voided' do expect( - Models::Invoice + Invoice .where(deleted_at: nil, tenant_id: tenant_id) .find_by!(id: invoice.id) .status diff --git a/spec/controllers/accountify/organisation_controller_spec.rb b/spec/controllers/accountify/organisation_controller_spec.rb index 4384b04..a672ba8 100644 --- a/spec/controllers/accountify/organisation_controller_spec.rb +++ b/spec/controllers/accountify/organisation_controller_spec.rb @@ -56,7 +56,7 @@ module Accountify expect(JSON.parse(response.body)).to have_key('events') expect( - Models::Organisation.find_by(deleted_at: nil, id: organisation.id) + Organisation.find_by(deleted_at: nil, id: organisation.id) ).to be_nil end end diff --git a/spec/factories/accountify_contacts.rb b/spec/factories/accountify_contacts.rb index 81f46ab..5071422 100644 --- a/spec/factories/accountify_contacts.rb +++ b/spec/factories/accountify_contacts.rb @@ -1,5 +1,5 @@ FactoryBot.define do - factory :accountify_contact, class: 'Accountify::Models::Contact' do + factory :accountify_contact, class: 'Accountify::Contact' do tenant_id { 4 } first_name { "John" } last_name { "Smith" } diff --git a/spec/factories/accountify_invoice_line_items.rb b/spec/factories/accountify_invoice_line_items.rb index 9f47777..dc3c912 100644 --- a/spec/factories/accountify_invoice_line_items.rb +++ b/spec/factories/accountify_invoice_line_items.rb @@ -1,5 +1,5 @@ FactoryBot.define do - factory :accountify_invoice_line_item, class: 'Accountify::Models::Invoice::LineItem' do + factory :accountify_invoice_line_item, class: 'Accountify::InvoiceLineItem' do description { 'Chair' } unit_amount_amount { BigDecimal('100.00') } unit_amount_currency_code { 'AUD' } diff --git a/spec/factories/accountify_invoice_status_summaries.rb b/spec/factories/accountify_invoice_status_summaries.rb index e747f22..bee4315 100644 --- a/spec/factories/accountify_invoice_status_summaries.rb +++ b/spec/factories/accountify_invoice_status_summaries.rb @@ -1,4 +1,4 @@ FactoryBot.define do - factory :accountify_invoice_status_summary, class: 'Accountify::Models::InvoiceStatusSummary' do + factory :accountify_invoice_status_summary, class: 'Accountify::InvoiceStatusSummary' do end end diff --git a/spec/factories/accountify_invoices.rb b/spec/factories/accountify_invoices.rb index bda0b17..a9ab55b 100644 --- a/spec/factories/accountify_invoices.rb +++ b/spec/factories/accountify_invoices.rb @@ -1,5 +1,5 @@ FactoryBot.define do - factory :accountify_invoice, class: 'Accountify::Models::Invoice' do + factory :accountify_invoice, class: 'Accountify::Invoice' do tenant_id { 4 } currency_code { "AUD" } due_date { Date.today + 30.days } diff --git a/spec/factories/accountify_organisations.rb b/spec/factories/accountify_organisations.rb index 9674b7c..c4c64ec 100644 --- a/spec/factories/accountify_organisations.rb +++ b/spec/factories/accountify_organisations.rb @@ -1,5 +1,5 @@ FactoryBot.define do - factory :accountify_organisation, class: 'Accountify::Models::Organisation' do + factory :accountify_organisation, class: 'Accountify::Organisation' do tenant_id { 4 } name { "Cool Bin Company" } end diff --git a/spec/factories/events.rb b/spec/factories/events.rb index 3fdcb66..9370829 100644 --- a/spec/factories/events.rb +++ b/spec/factories/events.rb @@ -1,25 +1,25 @@ FactoryBot.define do - factory :event, class: 'Models::Event' do + factory :event, class: 'Event' do end - factory :accountify_organisation_created_event, class: 'Accountify::Models::Organisation::CreatedEvent', parent: :event do + factory :accountify_organisation_created_event, class: 'Accountify::OrganisationCreatedEvent', parent: :event do end - factory :accountify_invoice_drafted_event, class: 'Accountify::Models::Invoice::DraftedEvent', parent: :event do + factory :accountify_invoice_drafted_event, class: 'Accountify::InvoiceDraftedEvent', parent: :event do end - factory :accountify_invoice_updated_event, class: 'Accountify::Models::Invoice::UpdatedEvent', parent: :event do + factory :accountify_invoice_updated_event, class: 'Accountify::InvoiceUpdatedEvent', parent: :event do end - factory :accountify_invoice_issued_event, class: 'Accountify::Models::Invoice::IssuedEvent', parent: :event do + factory :accountify_invoice_issued_event, class: 'Accountify::InvoiceIssuedEvent', parent: :event do end - factory :accountify_invoice_paid_event, class: 'Accountify::Models::Invoice::PaidEvent', parent: :event do + factory :accountify_invoice_paid_event, class: 'Accountify::InvoicePaidEvent', parent: :event do end - factory :accountify_invoice_voided_event, class: 'Accountify::Models::Invoice::VoidedEvent', parent: :event do + factory :accountify_invoice_voided_event, class: 'Accountify::InvoiceVoidedEvent', parent: :event do end - factory :accountify_invoice_deleted_event, class: 'Accountify::Models::Invoice::DeletedEvent', parent: :event do + factory :accountify_invoice_deleted_event, class: 'Accountify::InvoiceDeletedEvent', parent: :event do end end diff --git a/spec/integration/accountify/invoice/test_lifecycle_spec.rb b/spec/integration/accountify/invoice/test_lifecycle_spec.rb index 90c1467..29f6dd8 100644 --- a/spec/integration/accountify/invoice/test_lifecycle_spec.rb +++ b/spec/integration/accountify/invoice/test_lifecycle_spec.rb @@ -7,9 +7,9 @@ begin load Rails.root.join('script/accountify/invoice/test_lifecycle.rb') - expect(Accountify::Models::Organisation.count).to eq(1) - expect(Accountify::Models::Contact.count).to eq(1) - expect(Accountify::Models::Invoice.count).to eq(1) + expect(Accountify::Organisation.count).to eq(1) + expect(Accountify::Contact.count).to eq(1) + expect(Accountify::Invoice.count).to eq(1) ensure Sidekiq::Testing.fake! end diff --git a/spec/jobs/accountify/invoice/deleted_job_spec.rb b/spec/jobs/accountify/invoice/deleted_job_spec.rb deleted file mode 100644 index 2424e6d..0000000 --- a/spec/jobs/accountify/invoice/deleted_job_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ - -require 'rails_helper' - -module Accountify - module Invoice - RSpec.describe DeletedJob, type: :job do - let(:current_time) { Time.now } - - let(:user_id) { 123 } - let(:tenant_id) { 456 } - - 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({ 'event_id' => event.id }) - end - - it 'performs Accountify::InvoiceStatusSummary::RegenerateJob async' do - expect(Accountify::InvoiceStatusSummary::RegenerateJob.jobs).to match([ - hash_including( - 'args' => [ - hash_including( - 'event_id' => event.id )])]) - 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 deleted file mode 100644 index 77e1eda..0000000 --- a/spec/jobs/accountify/invoice/drafted_job_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ - -require 'rails_helper' - -module Accountify - module Invoice - RSpec.describe DraftedJob, type: :job do - let(:current_time) { Time.now } - - let(:user_id) { 123 } - let(:tenant_id) { 456 } - - 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({ 'event_id' => event.id }) - end - - it 'performs Accountify::InvoiceStatusSummary::RegenerateJob async' do - expect(Accountify::InvoiceStatusSummary::RegenerateJob.jobs).to match([ - hash_including( - 'args' => [ - hash_including( - 'event_id' => event.id )])]) - 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 deleted file mode 100644 index f3aaba0..0000000 --- a/spec/jobs/accountify/invoice/issued_job_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ - -require 'rails_helper' - -module Accountify - module Invoice - RSpec.describe IssuedJob, type: :job do - let(:current_time) { Time.now } - - let(:user_id) { 123 } - let(:tenant_id) { 456 } - - 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({ 'event_id' => event.id }) - end - - it 'performs Accountify::InvoiceStatusSummary::RegenerateJob async' do - expect(Accountify::InvoiceStatusSummary::RegenerateJob.jobs).to match([ - hash_including( - 'args' => [ - hash_including( - 'event_id' => event.id )])]) - 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 deleted file mode 100644 index 93cc275..0000000 --- a/spec/jobs/accountify/invoice/paid_job_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ - -require 'rails_helper' - -module Accountify - module Invoice - RSpec.describe PaidJob, type: :job do - let(:current_time) { Time.now } - - let(:user_id) { 123 } - let(:tenant_id) { 456 } - - 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({ 'event_id' => event.id }) - end - - it 'performs Accountify::InvoiceStatusSummary::RegenerateJob async' do - expect(Accountify::InvoiceStatusSummary::RegenerateJob.jobs).to match([ - hash_including( - 'args' => [ - hash_including( - 'event_id' => event.id )])]) - 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 deleted file mode 100644 index a1eb56b..0000000 --- a/spec/jobs/accountify/invoice/updated_job_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ - -require 'rails_helper' - -module Accountify - module Invoice - RSpec.describe UpdatedJob, type: :job do - let(:current_time) { Time.now } - - let(:user_id) { 123 } - let(:tenant_id) { 456 } - - 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({ 'event_id' => event.id }) - end - - it 'performs Accountify::InvoiceStatusSummary::RegenerateJob async' do - expect(Accountify::InvoiceStatusSummary::RegenerateJob.jobs).to match([ - hash_including( - 'args' => [ - hash_including( - 'event_id' => event.id )])]) - 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 deleted file mode 100644 index 763ac67..0000000 --- a/spec/jobs/accountify/invoice/voided_job_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ - -require 'rails_helper' - -module Accountify - module Invoice - RSpec.describe VoidedJob, type: :job do - let(:current_time) { Time.now } - - let(:user_id) { 123 } - let(:tenant_id) { 456 } - - 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({ 'event_id' => event.id }) - end - - it 'performs Accountify::InvoiceStatusSummary::RegenerateJob async' do - expect(Accountify::InvoiceStatusSummary::RegenerateJob.jobs).to match([ - hash_including( - 'args' => [ - hash_including( - 'event_id' => event.id )])]) - end - end - 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..ab4ded5 --- /dev/null +++ b/spec/jobs/accountify/invoice_deleted_job_spec.rb @@ -0,0 +1,50 @@ + +require 'rails_helper' + +module Accountify + RSpec.describe InvoiceDeletedJob, type: :job do + let(:current_time) { Time.now } + + let(:user_id) { 123 } + let(:tenant_id) { 456 } + + 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::InvoiceDeletedEvent' 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 + InvoiceDeletedJob.new.perform({ 'event_id' => event.id }) + end + + it 'performs Accountify::InvoiceStatusSummary::RegenerateJob async' do + expect(Accountify::RegenerateInvoiceStatusSummaryJob.jobs).to match([ + hash_including( + 'args' => [ + hash_including( + 'event_id' => event.id )])]) + 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..10befdb --- /dev/null +++ b/spec/jobs/accountify/invoice_drafted_job_spec.rb @@ -0,0 +1,50 @@ + +require 'rails_helper' + +module Accountify + RSpec.describe InvoiceDraftedJob, type: :job do + let(:current_time) { Time.now } + + let(:user_id) { 123 } + let(:tenant_id) { 456 } + + 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::InvoiceDraftedEvent' 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 + InvoiceDraftedJob.new.perform({ 'event_id' => event.id }) + end + + it 'performs Accountify::RegenerateInvoiceStatusSummaryJob async' do + expect(Accountify::RegenerateInvoiceStatusSummaryJob.jobs).to match([ + hash_including( + 'args' => [ + hash_including( + 'event_id' => event.id )])]) + 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..22d77b2 --- /dev/null +++ b/spec/jobs/accountify/invoice_issued_job_spec.rb @@ -0,0 +1,50 @@ + +require 'rails_helper' + +module Accountify + RSpec.describe InvoiceIssuedJob, type: :job do + let(:current_time) { Time.now } + + let(:user_id) { 123 } + let(:tenant_id) { 456 } + + 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::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 + InvoiceIssuedJob.new.perform({ 'event_id' => event.id }) + end + + it 'performs Accountify::RegenerateInvoiceStatusSummaryJob async' do + expect(Accountify::RegenerateInvoiceStatusSummaryJob.jobs).to match([ + hash_including( + 'args' => [ + hash_including( + 'event_id' => event.id )])]) + 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..698170d --- /dev/null +++ b/spec/jobs/accountify/invoice_paid_job_spec.rb @@ -0,0 +1,50 @@ + +require 'rails_helper' + +module Accountify + RSpec.describe InvoicePaidJob, type: :job do + let(:current_time) { Time.now } + + let(:user_id) { 123 } + let(:tenant_id) { 456 } + + 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::InvoicePaidEvent' 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 + InvoicePaidJob.new.perform({ 'event_id' => event.id }) + end + + it 'performs Accountify::RegenerateInvoiceStatusSummaryJob async' do + expect(Accountify::RegenerateInvoiceStatusSummaryJob.jobs).to match([ + hash_including( + 'args' => [ + hash_including( + 'event_id' => event.id )])]) + 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..eb25a6a --- /dev/null +++ b/spec/jobs/accountify/invoice_updated_job_spec.rb @@ -0,0 +1,50 @@ + +require 'rails_helper' + +module Accountify + RSpec.describe InvoiceUpdatedJob, type: :job do + let(:current_time) { Time.now } + + let(:user_id) { 123 } + let(:tenant_id) { 456 } + + 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::InvoiceUpdatedEvent' 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 + InvoiceUpdatedJob.new.perform({ 'event_id' => event.id }) + end + + it 'performs Accountify::RegenerateInvoiceStatusSummaryJob async' do + expect(Accountify::RegenerateInvoiceStatusSummaryJob.jobs).to match([ + hash_including( + 'args' => [ + hash_including( + 'event_id' => event.id )])]) + 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..7ad2da3 --- /dev/null +++ b/spec/jobs/accountify/invoice_voided_job_spec.rb @@ -0,0 +1,50 @@ + +require 'rails_helper' + +module Accountify + RSpec.describe InvoiceVoidedJob, type: :job do + let(:current_time) { Time.now } + + let(:user_id) { 123 } + let(:tenant_id) { 456 } + + 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::InvoiceVoidedEvent' 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 + InvoiceVoidedJob.new.perform({ 'event_id' => event.id }) + end + + it 'performs Accountify::RegenerateInvoiceStatusSummaryJob async' do + expect(Accountify::RegenerateInvoiceStatusSummaryJob.jobs).to match([ + hash_including( + 'args' => [ + hash_including( + 'event_id' => event.id )])]) + end + end + end +end diff --git a/spec/jobs/accountify/organisation/created_job_spec.rb b/spec/jobs/accountify/organisation/created_job_spec.rb deleted file mode 100644 index 5248d53..0000000 --- a/spec/jobs/accountify/organisation/created_job_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'rails_helper' - -module Accountify - module Organisation - RSpec.describe CreatedJob, type: :job do - let(:current_time) { Time.now } - - let(:user_id) { 123 } - let(:tenant_id) { 456 } - - let(:accountify_organisation) do - create(:accountify_organisation, tenant_id: tenant_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({ 'event_id' => event.id }) - end - - it 'performs Accountify::InvoiceStatusSummary::GenerateJob async' do - expect(Accountify::InvoiceStatusSummary::GenerateJob.jobs).to match([ - hash_including( - 'args' => [ - hash_including( - 'event_id' => event.id )])]) - 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..b67e4e0 --- /dev/null +++ b/spec/jobs/accountify/organisation_created_job_spec.rb @@ -0,0 +1,37 @@ +require 'rails_helper' + +module Accountify + RSpec.describe OrganisationCreatedJob, type: :job do + let(:current_time) { Time.now } + + let(:user_id) { 123 } + let(:tenant_id) { 456 } + + let(:accountify_organisation) do + create(:accountify_organisation, tenant_id: tenant_id) + end + + describe 'when Accountify::OrganisationCreatedEvent' 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 + OrganisationCreatedJob.new.perform({ 'event_id' => event.id }) + end + + it 'performs Accountify::InvoiceStatusSummary::GenerateJob async' do + expect(Accountify::GenerateInvoiceStatusSummaryJob.jobs).to match([ + hash_including( + 'args' => [ + hash_including( + 'event_id' => event.id )])]) + 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 deleted file mode 100644 index faff478..0000000 --- a/spec/jobs/outboxer_integration/message/publish_job_spec.rb +++ /dev/null @@ -1,60 +0,0 @@ -require 'rails_helper' - -module OutboxerIntegration - module Message - RSpec.describe PublishJob, type: :job do - 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 - - context 'when job class does not exist' do - let(:args) do - { - 'messageable_type' => 'Accountify::Models::Invoice::NonexistentEvent', - 'messageable_id' => '123' - } - end - - it 'completes gracefully without raising an error' do - allow_any_instance_of(String) - .to receive(:constantize) - .and_raise(NameError.new("uninitialized constant")) - - expect { - PublishJob.new.perform(args) - }.not_to raise_error - end - end - end - end - end -end diff --git a/spec/lib/accountify/contact/create_spec.rb b/spec/services/accountify/contact_service/create_spec.rb similarity index 88% rename from spec/lib/accountify/contact/create_spec.rb rename to spec/services/accountify/contact_service/create_spec.rb index d2daa50..486d716 100644 --- a/spec/lib/accountify/contact/create_spec.rb +++ b/spec/services/accountify/contact_service/create_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' module Accountify - RSpec.describe Contact do + RSpec.describe ContactService do let(:user_id) { 12 } let(:tenant_id) { 4 } @@ -12,7 +12,7 @@ module Accountify let(:email) { 'john.doe@example.com' } let!(:contact) do - Contact.create( + ContactService.create( user_id: user_id, tenant_id: tenant_id, organisation_id: organisation.id, @@ -22,11 +22,11 @@ module Accountify end let(:contact_model) do - Models::Contact.where(tenant_id: tenant_id).find_by!(id: contact[:id]) + Contact.where(tenant_id: tenant_id).find_by!(id: contact[:id]) end let(:event_model) do - Models::Contact::CreatedEvent + ContactCreatedEvent .where(tenant_id: tenant_id) .find_by!(id: contact[:events].last[:id]) end diff --git a/spec/lib/accountify/contact/delete_spec.rb b/spec/services/accountify/contact_service/delete_spec.rb similarity index 85% rename from spec/lib/accountify/contact/delete_spec.rb rename to spec/services/accountify/contact_service/delete_spec.rb index 2a327f9..215016e 100644 --- a/spec/lib/accountify/contact/delete_spec.rb +++ b/spec/services/accountify/contact_service/delete_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' module Accountify - RSpec.describe Contact do + RSpec.describe ContactService do let(:user_id) { 12 } let(:tenant_id) { 4 } @@ -24,15 +24,15 @@ module Accountify end let!(:contact) do - Contact.delete(user_id: user_id, tenant_id: tenant_id, id: id) + ContactService.delete(user_id: user_id, tenant_id: tenant_id, id: id) end let(:contact_model) do - Models::Contact.where(tenant_id: tenant_id).find_by!(id: id) + Contact.where(tenant_id: tenant_id).find_by!(id: id) end let(:event_model) do - Models::Contact::DeletedEvent + ContactDeletedEvent .where(tenant_id: tenant_id) .find_by!(id: contact[:events].last[:id]) end diff --git a/spec/lib/accountify/contact/find_by_id_spec.rb b/spec/services/accountify/contact_service/find_by_id_spec.rb similarity index 87% rename from spec/lib/accountify/contact/find_by_id_spec.rb rename to spec/services/accountify/contact_service/find_by_id_spec.rb index f8a9906..8eea5c4 100644 --- a/spec/lib/accountify/contact/find_by_id_spec.rb +++ b/spec/services/accountify/contact_service/find_by_id_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' module Accountify - RSpec.describe Contact do + RSpec.describe ContactService do let(:user_id) { 12 } let(:tenant_id) { 4 } @@ -23,7 +23,7 @@ module Accountify end let(:contact) do - Contact.find_by_id(user_id: user_id, tenant_id: tenant_id, id: id) + ContactService.find_by_id(user_id: user_id, tenant_id: tenant_id, id: id) end describe '.find_by_id' do diff --git a/spec/lib/accountify/contact/update_spec.rb b/spec/services/accountify/contact_service/update_spec.rb similarity index 90% rename from spec/lib/accountify/contact/update_spec.rb rename to spec/services/accountify/contact_service/update_spec.rb index 209fbad..9299102 100644 --- a/spec/lib/accountify/contact/update_spec.rb +++ b/spec/services/accountify/contact_service/update_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' module Accountify - RSpec.describe Contact do + RSpec.describe ContactService do let(:user_id) { 12 } let(:tenant_id) { 4 } @@ -22,7 +22,7 @@ module Accountify end let!(:contact) do - Contact.update( + ContactService.update( user_id: user_id, tenant_id: tenant_id, id: id, @@ -32,11 +32,11 @@ module Accountify end let(:contact_model) do - Models::Contact.where(tenant_id: tenant_id).find_by!(id: contact[:id]) + Contact.where(tenant_id: tenant_id).find_by!(id: contact[:id]) end let(:event_model) do - Models::Contact::UpdatedEvent + ContactUpdatedEvent .where(tenant_id: tenant_id) .find_by!(id: contact[:events].last[:id]) end diff --git a/spec/lib/accountify/invoice/delete_spec.rb b/spec/services/accountify/invoice_service/delete_spec.rb similarity index 86% rename from spec/lib/accountify/invoice/delete_spec.rb rename to spec/services/accountify/invoice_service/delete_spec.rb index aa06cbf..962d1d7 100644 --- a/spec/lib/accountify/invoice/delete_spec.rb +++ b/spec/services/accountify/invoice_service/delete_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' module Accountify - RSpec.describe Invoice do + RSpec.describe InvoiceService do let(:current_date) { Date.today } let(:user_id) { 12 } @@ -51,13 +51,13 @@ module Accountify let!(:line_items) { [line_item_1, line_item_2] } let!(:invoice) do - Invoice.delete(user_id: user_id, tenant_id: tenant_id, id: id) + InvoiceService.delete(user_id: user_id, tenant_id: tenant_id, id: id) end - let(:invoice_model) { Models::Invoice.where(tenant_id: tenant_id).find_by!(id: id) } + let(:invoice_model) { Invoice.where(tenant_id: tenant_id).find_by!(id: id) } let(:event_model) do - Models::Invoice::DeletedEvent.where(tenant_id: tenant_id).find_by!(id: invoice[:events].last[:id]) + InvoiceDeletedEvent.where(tenant_id: tenant_id).find_by!(id: invoice[:events].last[:id]) end describe '.delete' do diff --git a/spec/lib/accountify/invoice/draft_spec.rb b/spec/services/accountify/invoice_service/draft_spec.rb similarity index 94% rename from spec/lib/accountify/invoice/draft_spec.rb rename to spec/services/accountify/invoice_service/draft_spec.rb index 35ab738..a6b06fd 100644 --- a/spec/lib/accountify/invoice/draft_spec.rb +++ b/spec/services/accountify/invoice_service/draft_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' module Accountify - RSpec.describe Invoice do + RSpec.describe InvoiceService do let(:current_date) { Date.today } let(:user_id) { 12 } @@ -18,7 +18,7 @@ module Accountify end let(:invoice) do - Invoice.draft( + InvoiceService.draft( user_id: user_id, tenant_id: tenant_id, organisation_id: organisation.id, @@ -40,11 +40,11 @@ module Accountify end let(:invoice_model) do - Models::Invoice.where(tenant_id: tenant_id).find_by!(id: invoice[:id]) + Invoice.where(tenant_id: tenant_id).find_by!(id: invoice[:id]) end let(:event_model) do - Models::Invoice::DraftedEvent + InvoiceDraftedEvent .where(tenant_id: tenant_id).find_by!(id: invoice[:events].last[:id]) end diff --git a/spec/lib/accountify/invoice/find_by_id_spec.rb b/spec/services/accountify/invoice_service/find_by_id_spec.rb similarity index 94% rename from spec/lib/accountify/invoice/find_by_id_spec.rb rename to spec/services/accountify/invoice_service/find_by_id_spec.rb index dc012f7..c481433 100644 --- a/spec/lib/accountify/invoice/find_by_id_spec.rb +++ b/spec/services/accountify/invoice_service/find_by_id_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' module Accountify - RSpec.describe Invoice do + RSpec.describe InvoiceService do let(:current_date) { Date.today } let(:user_id) { 12 } @@ -51,7 +51,7 @@ module Accountify let!(:line_items) { [line_item_1, line_item_2] } let(:invoice) do - Invoice.find_by_id(user_id: user_id, tenant_id: tenant_id, id: id) + InvoiceService.find_by_id(user_id: user_id, tenant_id: tenant_id, id: id) end describe '.find_by_id' do diff --git a/spec/lib/accountify/invoice/issue_spec.rb b/spec/services/accountify/invoice_service/issue_spec.rb similarity index 90% rename from spec/lib/accountify/invoice/issue_spec.rb rename to spec/services/accountify/invoice_service/issue_spec.rb index 156ee27..ad6ae1f 100644 --- a/spec/lib/accountify/invoice/issue_spec.rb +++ b/spec/services/accountify/invoice_service/issue_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' module Accountify - RSpec.describe Invoice do + RSpec.describe InvoiceService do let(:current_date) { Date.today } let(:user_id) { 12 } @@ -51,13 +51,13 @@ module Accountify let!(:line_items) { [line_item_1, line_item_2] } let!(:invoice) do - Invoice.issue(user_id: user_id, tenant_id: tenant_id, id: id) + InvoiceService.issue(user_id: user_id, tenant_id: tenant_id, id: id) end - let(:invoice_model) { Models::Invoice.where(tenant_id: tenant_id).find_by!(id: id) } + let(:invoice_model) { Invoice.where(tenant_id: tenant_id).find_by!(id: id) } let(:event_model) do - Models::Invoice::IssuedEvent + InvoiceIssuedEvent .where(tenant_id: tenant_id).find_by!(id: invoice[:events].last[:id]) end diff --git a/spec/lib/accountify/invoice/paid_spec.rb b/spec/services/accountify/invoice_service/paid_spec.rb similarity index 87% rename from spec/lib/accountify/invoice/paid_spec.rb rename to spec/services/accountify/invoice_service/paid_spec.rb index 60b42f5..2c9a104 100644 --- a/spec/lib/accountify/invoice/paid_spec.rb +++ b/spec/services/accountify/invoice_service/paid_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' module Accountify - RSpec.describe Invoice do + RSpec.describe InvoiceService do let(:current_date) { Date.today } let(:user_id) { 12 } @@ -42,15 +42,15 @@ module Accountify end let!(:invoice) do - Invoice.paid(user_id: user_id, tenant_id: tenant_id, id: id) + InvoiceService.paid(user_id: user_id, tenant_id: tenant_id, id: id) end let(:invoice_model) do - Models::Invoice.where(tenant_id: tenant_id).find_by!(id: id) + Invoice.where(tenant_id: tenant_id).find_by!(id: id) end let(:event_model) do - Models::Invoice::PaidEvent.where(tenant_id: tenant_id).find_by!(id: invoice[:events].last[:id]) + InvoicePaidEvent.where(tenant_id: tenant_id).find_by!(id: invoice[:events].last[:id]) end describe '.paid' do diff --git a/spec/lib/accountify/invoice/update_spec.rb b/spec/services/accountify/invoice_service/update_spec.rb similarity index 96% rename from spec/lib/accountify/invoice/update_spec.rb rename to spec/services/accountify/invoice_service/update_spec.rb index 1ebeb93..cd8a0b9 100644 --- a/spec/lib/accountify/invoice/update_spec.rb +++ b/spec/services/accountify/invoice_service/update_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' module Accountify - RSpec.describe Invoice do + RSpec.describe InvoiceService do let(:current_date) { Date.today } let(:user_id) { 12 } @@ -60,7 +60,7 @@ module Accountify let!(:line_items) { [line_item_1, line_item_2] } let!(:invoice) do - Invoice.update( + InvoiceService.update( user_id: user_id, tenant_id: tenant_id, id: id, @@ -82,11 +82,11 @@ module Accountify end let(:invoice_model) do - Models::Invoice.where(tenant_id: tenant_id).find_by!(id: invoice[:id]) + Invoice.where(tenant_id: tenant_id).find_by!(id: invoice[:id]) end let(:event_model) do - Models::Invoice::UpdatedEvent + InvoiceUpdatedEvent .where(tenant_id: tenant_id) .find_by!(id: invoice[:events].last[:id]) end diff --git a/spec/lib/accountify/invoice/void_spec.rb b/spec/services/accountify/invoice_service/void_spec.rb similarity index 89% rename from spec/lib/accountify/invoice/void_spec.rb rename to spec/services/accountify/invoice_service/void_spec.rb index f428166..c266a7b 100644 --- a/spec/lib/accountify/invoice/void_spec.rb +++ b/spec/services/accountify/invoice_service/void_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' module Accountify - RSpec.describe Invoice do + RSpec.describe InvoiceService do let(:current_date) { Date.today } let(:user_id) { 12 } @@ -51,13 +51,13 @@ module Accountify let!(:line_items) { [line_item_1, line_item_2] } let!(:invoice) do - Invoice.void(user_id: user_id, tenant_id: tenant_id, id: id) + InvoiceService.void(user_id: user_id, tenant_id: tenant_id, id: id) end - let(:invoice_model) { Models::Invoice.where(tenant_id: tenant_id).find_by!(id: id) } + let(:invoice_model) { Invoice.where(tenant_id: tenant_id).find_by!(id: id) } let(:event_model) do - Models::Invoice::VoidedEvent + InvoiceVoidedEvent .where(tenant_id: tenant_id).find_by!(id: invoice[:events].last[:id]) end diff --git a/spec/lib/accountify/invoice_status_summary/generate_spec.rb b/spec/services/accountify/invoice_status_summary_service/generate_spec.rb similarity index 76% rename from spec/lib/accountify/invoice_status_summary/generate_spec.rb rename to spec/services/accountify/invoice_status_summary_service/generate_spec.rb index 474177a..55634da 100644 --- a/spec/lib/accountify/invoice_status_summary/generate_spec.rb +++ b/spec/services/accountify/invoice_status_summary_service/generate_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' module Accountify - RSpec.describe InvoiceStatusSummary do + RSpec.describe InvoiceStatusSummaryService do describe '.generate' do let(:current_utc_time) { ::Time.now.utc } let(:time) { double('Time', now: double('Time', utc: current_utc_time)) } @@ -21,12 +21,12 @@ module Accountify it 'creates a new invoice status summary' do expect do - InvoiceStatusSummary.generate(event_id: event.id) - end.to change { Models::InvoiceStatusSummary.count }.by(1) + InvoiceStatusSummaryService.generate(event_id: event.id) + end.to change { InvoiceStatusSummary.count }.by(1) end it 'creates a summary with the correct counts' do - summary = InvoiceStatusSummary.generate(event_id: event.id) + summary = InvoiceStatusSummaryService.generate(event_id: event.id) expect(summary[:drafted_count]).to eq(0) expect(summary[:issued_count]).to eq(0) @@ -35,7 +35,7 @@ module Accountify end it 'uses the current time as the generated_at time' do - summary = InvoiceStatusSummary.generate(event_id: event.id, time: time) + summary = InvoiceStatusSummaryService.generate(event_id: event.id, time: time) expect(summary[:generated_at]).to be_within(1.second).of(current_utc_time) end diff --git a/spec/lib/accountify/invoice_status_summary/regenerate_spec.rb b/spec/services/accountify/invoice_status_summary_service/regenerate_spec.rb similarity index 86% rename from spec/lib/accountify/invoice_status_summary/regenerate_spec.rb rename to spec/services/accountify/invoice_status_summary_service/regenerate_spec.rb index 4c1d345..ffe556d 100644 --- a/spec/lib/accountify/invoice_status_summary/regenerate_spec.rb +++ b/spec/services/accountify/invoice_status_summary_service/regenerate_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' module Accountify - RSpec.describe InvoiceStatusSummary do + RSpec.describe InvoiceStatusSummaryService do describe '.regenerate' do let(:user_id) { 1 } let(:tenant_id) { 1 } @@ -72,10 +72,10 @@ module Accountify it 'updates the existing invoice status summary' do expect do - InvoiceStatusSummary.regenerate(event_id: event.id, time: time) - end.to change { Models::InvoiceStatusSummary.count }.by(0) + InvoiceStatusSummaryService.regenerate(event_id: event.id, time: time) + end.to change { InvoiceStatusSummary.count }.by(0) - summary = Models::InvoiceStatusSummary.find(invoice_status_summary.id) + summary = InvoiceStatusSummary.find(invoice_status_summary.id) expect(summary.generated_at).to be_within(1.second).of(current_utc_time) expect(summary.drafted_count).to eq(1) expect(summary.issued_count).to eq(1) @@ -84,7 +84,7 @@ module Accountify end it 'returns the summary if not updated' do - summary = InvoiceStatusSummary.regenerate( + summary = InvoiceStatusSummaryService.regenerate( event_id: event.id, invoice_updated_at: current_utc_time - 2.days, time: time) @@ -93,11 +93,11 @@ module Accountify end it 'raises Accountify::NotAvailable error on lock wait timeout' do - allow(Models::InvoiceStatusSummary).to receive(:find_by!) + allow(InvoiceStatusSummary).to receive(:find_by!) .and_raise(ActiveRecord::LockWaitTimeout) expect do - InvoiceStatusSummary.regenerate( + InvoiceStatusSummaryService.regenerate( event_id: event.id, invoice_updated_at: invoice_updated_at, time: time) @@ -105,11 +105,11 @@ module Accountify end it 'raises ActiveRecord::RecordNotFound error when summary is not found' do - allow(Models::InvoiceStatusSummary).to receive(:find_by!) + allow(InvoiceStatusSummary).to receive(:find_by!) .and_raise(ActiveRecord::RecordNotFound) expect do - InvoiceStatusSummary.regenerate( + InvoiceStatusSummaryService.regenerate( event_id: event.id, invoice_updated_at: invoice_updated_at, time: time) diff --git a/spec/lib/accountify/organisation/create_spec.rb b/spec/services/accountify/organisation_service/create_spec.rb similarity index 82% rename from spec/lib/accountify/organisation/create_spec.rb rename to spec/services/accountify/organisation_service/create_spec.rb index d9ef4f9..b817d2c 100644 --- a/spec/lib/accountify/organisation/create_spec.rb +++ b/spec/services/accountify/organisation_service/create_spec.rb @@ -1,23 +1,23 @@ require 'rails_helper' module Accountify - RSpec.describe Organisation do + RSpec.describe OrganisationService do let(:user_id) { 12 } let(:tenant_id) { 4 } let(:name) { 'Big Bin Corp' } let(:organisation) do - Organisation.create( + OrganisationService.create( user_id: user_id, tenant_id: tenant_id, name: name) end let(:organisation_model) do - Models::Organisation.where(tenant_id: tenant_id).find_by!(id: organisation[:id]) + Organisation.where(tenant_id: tenant_id).find_by!(id: organisation[:id]) end let(:event_model) do - Models::Organisation::CreatedEvent + OrganisationCreatedEvent .where(tenant_id: tenant_id) .find_by!(id: organisation[:events].last[:id]) end diff --git a/spec/lib/accountify/organisation/delete_spec.rb b/spec/services/accountify/organisation_service/delete_spec.rb similarity index 80% rename from spec/lib/accountify/organisation/delete_spec.rb rename to spec/services/accountify/organisation_service/delete_spec.rb index 272afff..b34e4ad 100644 --- a/spec/lib/accountify/organisation/delete_spec.rb +++ b/spec/services/accountify/organisation_service/delete_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' module Accountify - RSpec.describe Organisation do + RSpec.describe OrganisationService do let(:user_id) { 12 } let(:tenant_id) { 4 } @@ -13,15 +13,15 @@ module Accountify end let!(:organisation) do - Organisation.delete(user_id: user_id, tenant_id: tenant_id, id: id) + OrganisationService.delete(user_id: user_id, tenant_id: tenant_id, id: id) end let(:organisation_model) do - Models::Organisation.where(tenant_id: tenant_id).find_by!(id: id) + Organisation.where(tenant_id: tenant_id).find_by!(id: id) end let(:event_model) do - Models::Organisation::DeletedEvent + OrganisationDeletedEvent .where(tenant_id: tenant_id) .find_by!(id: organisation[:events].last[:id]) end diff --git a/spec/lib/accountify/organisation/find_by_id_spec.rb b/spec/services/accountify/organisation_service/find_by_id_spec.rb similarity index 77% rename from spec/lib/accountify/organisation/find_by_id_spec.rb rename to spec/services/accountify/organisation_service/find_by_id_spec.rb index 99380e8..2cd8ef0 100644 --- a/spec/lib/accountify/organisation/find_by_id_spec.rb +++ b/spec/services/accountify/organisation_service/find_by_id_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' module Accountify - RSpec.describe Organisation do + RSpec.describe OrganisationService do let(:user_id) { 12 } let(:tenant_id) { 4 } @@ -13,7 +13,7 @@ module Accountify end let(:organisation) do - Organisation.find_by_id(user_id: user_id, tenant_id: tenant_id, id: id) + OrganisationService.find_by_id(user_id: user_id, tenant_id: tenant_id, id: id) end describe '.find_by_id' do diff --git a/spec/lib/accountify/organisation/update_spec.rb b/spec/services/accountify/organisation_service/update_spec.rb similarity index 84% rename from spec/lib/accountify/organisation/update_spec.rb rename to spec/services/accountify/organisation_service/update_spec.rb index fa72086..3e13ad2 100644 --- a/spec/lib/accountify/organisation/update_spec.rb +++ b/spec/services/accountify/organisation_service/update_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' module Accountify - RSpec.describe Organisation do + RSpec.describe OrganisationService do let(:user_id) { 12 } let(:tenant_id) { 4 } @@ -11,17 +11,17 @@ module Accountify end let!(:organisation) do - Organisation.update( + OrganisationService.update( user_id: user_id, tenant_id: tenant_id, id: id, name: 'Big Bin Corp updated') end let(:organisation_model) do - Models::Organisation.where(tenant_id: tenant_id).find_by!(id: id) + Organisation.where(tenant_id: tenant_id).find_by!(id: id) end let(:event_model) do - Models::Organisation::UpdatedEvent + OrganisationUpdatedEvent .where(tenant_id: tenant_id) .find_by!(id: organisation[:events].last[:id]) end