Skip to content

Commit

Permalink
fix review
Browse files Browse the repository at this point in the history
  • Loading branch information
jdenquin committed Apr 26, 2022
1 parent 33f8ed8 commit d87161d
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 26 deletions.
4 changes: 2 additions & 2 deletions app/jobs/send_webhook_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class SendWebhookJob < ApplicationJob

retry_on LagoHttpClient::HttpError, wait: :exponentially_longer, attempts: 3

def perform(webhook_type, object_id)
def perform(webhook_type, object)
case webhook_type
when :invoice
Webhooks::InvoicesService.new(object_id).call
Webhooks::InvoicesService.new(object).call
else
raise NotImplementedError
end
Expand Down
9 changes: 0 additions & 9 deletions app/serializers/webhook_serializer.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/services/invoices/create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def create

compute_amounts(invoice)

SendWebhookJob.perform_later(:invoice, invoice.id)
SendWebhookJob.perform_later(:invoice, invoice)

result.invoice = invoice
end
Expand Down
8 changes: 2 additions & 6 deletions app/services/webhooks/base_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
module Webhooks
# NOTE: Abstract Service, should not be used directly
class BaseService
def initialize(object_id)
@object = find_object(object_id)
def initialize(object)
@object = object
end

def call
Expand All @@ -21,10 +21,6 @@ def call

attr_reader :object

def find_object(object_id)
# Empty
end

def object_serializer
# Empty
end
Expand Down
4 changes: 0 additions & 4 deletions app/services/webhooks/invoices_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ module Webhooks
class InvoicesService < Webhooks::BaseService
private

def find_object(object_id)
Invoice.find(object_id)
end

def current_organization
@current_organization ||= object.organization
end
Expand Down
6 changes: 3 additions & 3 deletions spec/jobs/send_webhook_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@

it 'calls the webhook invoice service' do
allow(Webhooks::InvoicesService).to receive(:new)
.with(invoice.id)
.with(invoice)
.and_return(webhook_invoice_service)
allow(webhook_invoice_service).to receive(:call)

described_class.perform_now(:invoice, invoice.id)
described_class.perform_now(:invoice, invoice)

expect(Webhooks::InvoicesService).to have_received(:new)
expect(webhook_invoice_service).to have_received(:call)
end

context 'with not implemented webhook type' do
it 'raises a NotImplementedError' do
expect { described_class.perform_now(:subscription, invoice.id) }
expect { described_class.perform_now(:subscription, invoice) }
.to raise_error(NotImplementedError)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/services/webhooks/invoices_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'rails_helper'

RSpec.describe Webhooks::InvoicesService do
subject(:webhook_invoice_service) { described_class.new(invoice.id) }
subject(:webhook_invoice_service) { described_class.new(invoice) }

let(:organization) { create(:organization, webhook_url: 'http://foo.bar') }
let(:subscription) { create(:subscription, organization: organization) }
Expand Down

0 comments on commit d87161d

Please sign in to comment.