-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added service object for notify billing about change status of deposi…
…t and added tests
- Loading branch information
1 parent
3c6fa98
commit 2bc690e
Showing
6 changed files
with
125 additions
and
9 deletions.
There are no files selected for viewing
17 changes: 15 additions & 2 deletions
17
app/controllers/admin/paid_deposit/deposit_statuses_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module EisBilling | ||
class DepositStatusService | ||
include EisBilling::Request | ||
include EisBilling::BaseService | ||
|
||
attr_reader :user_uuid, :status, :domain_name | ||
|
||
def initialize(user_uuid:, status:, domain_name:) | ||
@user_uuid = user_uuid | ||
@status = status | ||
@domain_name = domain_name | ||
end | ||
|
||
def self.call(user_uuid:, status:, domain_name:) | ||
new(user_uuid: user_uuid, status: status, domain_name:).call | ||
end | ||
|
||
def call | ||
struct_response(fetch) | ||
end | ||
|
||
private | ||
|
||
def fetch | ||
post deposit_status_url, params | ||
end | ||
|
||
def params | ||
{ user_uuid: user_uuid, | ||
domain_name: domain_name, | ||
status: status } | ||
end | ||
|
||
def deposit_status_url | ||
'/api/v1/invoice_generator/deposit_status' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
require 'test_helper' | ||
|
||
class DepositStatusServiceTest < ActiveSupport::TestCase | ||
setup do | ||
@auction = auctions(:english) | ||
@user = users(:participant) | ||
|
||
@base_url = 'http://eis_billing_system:3000' | ||
end | ||
|
||
def test_call_fetches_data_from_billing_system | ||
stub_request(:post, "#{@base_url}/api/v1/invoice_generator/deposit_status") | ||
.with( | ||
body: { | ||
'user_uuid' => @user.uuid, | ||
'domain_name' => @auction.domain_name, | ||
'status' => 'returned' | ||
} | ||
) | ||
.to_return( | ||
status: 200, | ||
body: '{"message": "Status updated"}', | ||
headers: {} | ||
) | ||
|
||
d = DomainParticipateAuction.create(user_id: @user.id, auction_id: @auction.id) | ||
d.update(status: 'returned') | ||
|
||
res = d.send_deposit_status_to_billing_system | ||
|
||
assert res.result? | ||
end | ||
|
||
def test_return_errors_in_struct_format | ||
stub_request(:post, "#{@base_url}/api/v1/invoice_generator/deposit_status") | ||
.with( | ||
body: { | ||
'user_uuid' => @user.uuid, | ||
'domain_name' => @auction.domain_name, | ||
'status' => 'returned' | ||
} | ||
) | ||
.to_return( | ||
status: 422, | ||
body: '{"error": "Shit happens"}', | ||
headers: {} | ||
) | ||
|
||
d = DomainParticipateAuction.create(user_id: @user.id, auction_id: @auction.id) | ||
d.update(status: 'returned') | ||
|
||
res = d.send_deposit_status_to_billing_system | ||
|
||
refute res.result? | ||
assert_equal res.errors, "Shit happens" | ||
end | ||
end |