-
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.
Merge pull request #1148 from internetee/1130-deposit-status-change-n…
…o-effect-to-billing added service object for notify billing about change status of deposit and added tests
- Loading branch information
Showing
6 changed files
with
110 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,38 @@ | ||
require 'test_helper' | ||
|
||
class DepositStatusServiceTest < ActionDispatch::IntegrationTest | ||
include Devise::Test::IntegrationHelpers | ||
|
||
setup do | ||
@auction = auctions(:english) | ||
@user = users(:participant) | ||
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true) | ||
end | ||
|
||
def test_call_fetches_data_from_billing_system | ||
message = {"message": "Status updated"} | ||
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/deposit_status") | ||
.to_return(status: 200, body: message.to_json, 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 | ||
message = {"error": "Shit happens"} | ||
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/deposit_status") | ||
.to_return(status: 422, body: message.to_json, 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 |