Skip to content

add readme specs #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,14 @@ jobs:
bundle exec rails db:create
bundle exec rails db:schema:load

- name: add Outboxer
run: |
echo "gem 'outboxer', git: 'https://github.com/fast-programmer/outboxer.git', branch: 'master'" >> Gemfile
bundle install
bin/rails g outboxer:install
bin/rake db:migrate
mkdir lib
{ sed '$d' lib/event.rb; printf "\n # callbacks\n\n after_create do |event|\n Outboxer::Message.queue(messageable: event)\n end\nend\n"; } > lib/event.tmp && mv lib/event.tmp lib/event.rb

- name: Run tests
run: bundle exec rspec
2 changes: 1 addition & 1 deletion app/jobs/accountify/generate_invoice_status_summary_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class GenerateInvoiceStatusSummaryJob
sidekiq_options queue: 'reporting', backtrace: true

def perform(args)
InvoiceStatusSummary.generate(event_id: args['event_id'])
InvoiceStatusSummaryService.generate(event_id: args['event_id'])
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class RegenerateInvoiceStatusSummaryJob
sidekiq_options queue: 'reporting', backtrace: true

def perform(args)
InvoiceStatusSummary.regenerate(event_id: args['event_id'])
InvoiceStatusSummaryService.regenerate(event_id: args['event_id'])
rescue NotAvailable
RegenerateJob.perform_in(1.minute, args)
end
Expand Down
45 changes: 27 additions & 18 deletions script/accountify/invoice/test_lifecycle.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
require_relative '../../../config/environment'

require 'open3'

require_relative '../../../config/environment'

user_id = 123

tenant_id = 456

current_date = ::Time.now.to_date

organisation = Accountify::Organisation.create(
organisation = Accountify::OrganisationService.create(
user_id: user_id,
tenant_id: tenant_id,
name: 'Debbies Debts Ltd')

contact = Accountify::Contact.create(
contact = Accountify::ContactService.create(
user_id: user_id,
tenant_id: tenant_id,
organisation_id: organisation[:id],
first_name: 'John',
last_name: 'Elliot',
email: '[email protected]')

invoice = Accountify::Invoice.draft(
invoice = Accountify::InvoiceService.draft(
user_id: user_id,
tenant_id: tenant_id,
organisation_id: organisation[:id],
Expand All @@ -41,7 +41,7 @@
currency_code: "AUD" },
quantity: 3 } ])

Accountify::Invoice.update(
Accountify::InvoiceService.update(
user_id: user_id,
tenant_id: tenant_id,
id: invoice[:id],
Expand All @@ -61,17 +61,23 @@
currency_code: "AUD" },
quantity: 4 }])

Accountify::Invoice.issue(user_id: user_id, tenant_id: tenant_id, id: invoice[:id])
Accountify::InvoiceService.issue(user_id: user_id, tenant_id: tenant_id, id: invoice[:id])

Accountify::InvoiceService.paid(user_id: user_id, tenant_id: tenant_id, id: invoice[:id])

Accountify::InvoiceService.void(user_id: user_id, tenant_id: tenant_id, id: invoice[:id])

Accountify::Invoice.paid(user_id: user_id, tenant_id: tenant_id, id: invoice[:id])
Accountify::InvoiceService.delete(user_id: user_id, tenant_id: tenant_id, id: invoice[:id])

Accountify::Invoice.void(user_id: user_id, tenant_id: tenant_id, id: invoice[:id])
outboxer_env = ENV['OUTBOXER_ENV'] || ENV['RAILS_ENV'] || 'development'

Accountify::Invoice.delete(user_id: user_id, tenant_id: tenant_id, id: invoice[:id])
sidekiq_server_cmd = "RAILS_ENV=#{outboxer_env} bundle exec sidekiq -r ./config/sidekiq.rb"
puts sidekiq_server_cmd
sidekiq_server_process = IO.popen(sidekiq_server_cmd)

puts "Starting Sidekiq..."
sidekiq_cmd = "bundle exec sidekiq -r ./config/sidekiq.rb"
sidekiq_process = IO.popen(sidekiq_cmd)
outboxer_publisher_cmd = "OUTBOXER_ENV=#{outboxer_env} bin/outboxer_publisher"
puts outboxer_publisher_cmd
outboxer_publisher_process = IO.popen(outboxer_publisher_cmd)

begin
invoice_status_summary = nil
Expand All @@ -82,7 +88,7 @@
begin
attempts += 1

invoice_status_summary = Accountify::InvoiceStatusSummary.find_by_organisation_id(
invoice_status_summary = Accountify::InvoiceStatusSummaryService.find_by_organisation_id(
tenant_id: tenant_id,
organisation_id: organisation[:id])
rescue Accountify::NotFound
Expand All @@ -93,13 +99,16 @@
end

if invoice_status_summary.nil?
raise Accountify::NotFound, "Invoice status summary not found after #{max_attempts} attempts."
raise Accountify::NotFound, "Invoice status summary not found after #{max_attempts} attempts"
end
ensure
puts "Stopping Sidekiq..."
puts "Stopping outboxer publisher..."
Process.kill("TERM", outboxer_publisher_process.pid)
Process.wait(outboxer_publisher_process.pid)

Process.kill("TERM", sidekiq_process.pid)
Process.wait(sidekiq_process.pid)
puts "Stopping sidekiq server..."
Process.kill("TERM", sidekiq_server_process.pid)
Process.wait(sidekiq_server_process.pid)
end

# bundle exec ruby script/accountify/invoice/test_lifecycle.rb
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/accountify/invoice/test_lifecycle_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'rails_helper'

RSpec.describe 'Invoice Lifecycle', type: :integration do
xit 'transitions as expected' do
it 'transitions as expected' do
Sidekiq::Testing.disable!

begin
Expand Down
2 changes: 1 addition & 1 deletion spec/jobs/accountify/organisation_created_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module Accountify
OrganisationCreatedJob.new.perform({ 'event_id' => event.id })
end

it 'performs Accountify::InvoiceStatusSummary::GenerateJob async' do
it 'performs Accountify::GenerateInvoiceStatusSummaryJob async' do
expect(Accountify::GenerateInvoiceStatusSummaryJob.jobs).to match([
hash_including(
'args' => [
Expand Down
Loading