This repository has been archived by the owner on Jul 30, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
286 additions
and
12 deletions.
There are no files selected for viewing
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,88 @@ | ||
class AuctionAccepted | ||
def initialize(auction) | ||
@auction = auction | ||
end | ||
|
||
def perform | ||
if vendor_ineligible? | ||
auction.errors.add(:base, 'The vendor is ineligible from being paid.') | ||
else | ||
request_credit_card_form_url | ||
create_purchase_request | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :auction | ||
|
||
def request_credit_card_form_url | ||
|
||
if should_request_credit_card_form_url? | ||
RequestCreditCardFormUrlEmailSender.new(auction).perform | ||
auction.errors.add(:base, 'The vendor is missing their credit card. An email was sent to them requesting a credit card form URL.') | ||
end | ||
end | ||
|
||
def should_request_credit_card_form_url? | ||
winning_bidder_lacks_credit_card_form_url? | ||
end | ||
|
||
def create_purchase_request | ||
if should_create_cap_proposal? | ||
CreateCapProposalJob.perform_later(auction.id) | ||
end | ||
end | ||
|
||
def should_create_cap_proposal? | ||
cap_proposal_is_blank? && | ||
auction.purchase_card == "default" && | ||
winning_bidder_has_credit_card_form_url? | ||
end | ||
|
||
def vendor_ineligible? | ||
|
||
!winning_bidder_is_eligible_to_be_paid? | ||
end | ||
|
||
def cap_proposal_is_blank? | ||
auction.cap_proposal_url.blank? | ||
end | ||
|
||
def winning_bidder_is_eligible_to_be_paid? | ||
if auction_is_small_business? | ||
reckoner = SamAccountReckoner.new(winning_bidder) | ||
reckoner.set! | ||
winning_bidder.reload | ||
|
||
user_is_eligible_to_bid? | ||
else | ||
true | ||
end | ||
end | ||
|
||
def winning_bidder_has_credit_card_form_url? | ||
!winning_bidder_lacks_credit_card_form_url? | ||
end | ||
|
||
def winning_bidder_lacks_credit_card_form_url? | ||
winning_bidder.credit_card_form_url.nil? || | ||
winning_bidder.credit_card_form_url.empty? | ||
end | ||
|
||
def user_is_eligible_to_bid? | ||
auction_rules.user_is_eligible_to_bid?(winning_bidder) | ||
end | ||
|
||
def auction_rules | ||
RulesFactory.new(auction).create | ||
end | ||
|
||
def auction_is_small_business? | ||
AuctionThreshold.new(auction).small_business? | ||
end | ||
|
||
def winning_bidder | ||
WinningBid.new(auction).find.bidder | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class RequestCreditCardFormUrlEmailSender | ||
def initialize(auction) | ||
@auction = auction | ||
end | ||
|
||
def perform | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<div> | ||
<h6><%= label %></h6> | ||
<p class="auction-label-info"><%= data %></p> | ||
<p class="auction-label-info" id="auction-label-info-<%= label.split.join('-') %>"><%= data %></p> | ||
</div> |
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
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,122 @@ | ||
require 'rails_helper' | ||
|
||
describe AuctionAccepted do | ||
context 'the winning bidder lacks a credit card URL' do | ||
it 'does not call CreateCapProposalJob' do | ||
auction = create( | ||
:auction, | ||
:below_micropurchase_threshold, | ||
:winning_vendor_is_small_business, | ||
:delivery_due_at_expired | ||
) | ||
winning_bidder = WinningBid.new(auction).find.bidder | ||
winning_bidder.update(credit_card_form_url: "") | ||
|
||
allow(CreateCapProposalJob).to receive(:perform_later) | ||
.with(auction.id) | ||
.and_return(nil) | ||
|
||
AuctionAccepted.new(auction).perform | ||
|
||
expect(CreateCapProposalJob).not_to have_received(:perform_later) | ||
end | ||
|
||
it 'calls RequestCreditCardFormUrlEmailSender#perform' do | ||
auction = create( | ||
:auction, | ||
:below_micropurchase_threshold, | ||
:winning_vendor_is_small_business, | ||
:delivery_due_at_expired | ||
) | ||
|
||
winning_bidder = WinningBid.new(auction).find.bidder | ||
winning_bidder.update(credit_card_form_url: "") | ||
|
||
request_cc_form_url_double = instance_double( | ||
'RequestCreditCardFormUrlEmailSender' | ||
) | ||
allow(request_cc_form_url_double).to receive(:perform) | ||
allow(RequestCreditCardFormUrlEmailSender).to receive(:new) | ||
.with(auction) | ||
.and_return(request_cc_form_url_double) | ||
|
||
AuctionAccepted.new(auction).perform | ||
|
||
expect(request_cc_form_url_double).to have_received(:perform) | ||
end | ||
end | ||
|
||
context 'auction is below the micropurchase threshold' do | ||
it 'calls the CreateCapProposalJob' do | ||
auction = create( | ||
:auction, | ||
:below_micropurchase_threshold, | ||
:winning_vendor_is_small_business, | ||
:delivery_due_at_expired | ||
) | ||
allow(CreateCapProposalJob).to receive(:perform_later) | ||
.with(auction.id) | ||
.and_return(nil) | ||
|
||
AuctionAccepted.new(auction).perform | ||
|
||
expect(CreateCapProposalJob).to have_received(:perform_later).with(auction.id) | ||
end | ||
end | ||
|
||
context 'auction is between micropurchase and SAT threshold' do | ||
context 'winning vendor is a small business' do | ||
it 'calls the CreateCapProposalJob' do | ||
auction = create( | ||
:auction, | ||
:between_micropurchase_and_sat_threshold, | ||
:winning_vendor_is_small_business, | ||
:delivery_due_at_expired | ||
) | ||
allow(CreateCapProposalJob).to receive(:perform_later) | ||
.with(auction.id) | ||
.and_return(nil) | ||
|
||
AuctionAccepted.new(auction).perform | ||
|
||
expect(CreateCapProposalJob).to have_received(:perform_later).with(auction.id) | ||
end | ||
end | ||
|
||
context 'winning vendor is not a small business' do | ||
it 'does not call the CreateCapProposalJob' do | ||
auction = create( | ||
:auction, | ||
:between_micropurchase_and_sat_threshold, | ||
:winning_vendor_is_non_small_business, | ||
:delivery_due_at_expired | ||
) | ||
allow(CreateCapProposalJob).to receive(:perform_later) | ||
.with(auction.id) | ||
.and_return(nil) | ||
|
||
AuctionAccepted.new(auction).perform | ||
|
||
expect(CreateCapProposalJob).to_not have_received(:perform_later).with(auction.id) | ||
end | ||
end | ||
end | ||
|
||
context 'auction is for another purchase card' do | ||
it 'does not call CreateCapProposalJob' do | ||
auction = create( | ||
:auction, | ||
:below_micropurchase_threshold, | ||
:winning_vendor_is_small_business, | ||
:delivery_due_at_expired, | ||
purchase_card: :other | ||
) | ||
allow(CreateCapProposalJob).to receive(:perform_later) | ||
.with(auction.id) | ||
|
||
AuctionAccepted.new(auction).perform | ||
|
||
expect(CreateCapProposalJob).not_to have_received(:perform_later) | ||
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