Skip to content
This repository has been archived by the owner on Jul 30, 2019. It is now read-only.

Commit

Permalink
Merge 09e00ed into 1d97012
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Harris committed Sep 23, 2016
2 parents 1d97012 + 09e00ed commit c1841ef
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 2 deletions.
18 changes: 18 additions & 0 deletions app/controllers/admin/auction_mark_payments_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Admin::AuctionMarkPaymentsController < Admin::BaseController
def update
@auction = Auction.find(params[:id])

paid_auction = MarkPaidAuction.new(
auction: @auction
)

if paid_auction.perform
@auction.save!
else
error_messages = @auction.errors.full_messages.to_sentence
flash[:error] = error_messages
end

redirect_to admin_auction_path(@auction)
end
end
6 changes: 6 additions & 0 deletions app/models/admin_auction_status_presenter_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def other_purchase_card_presenter
AdminAuctionStatusPresenter::ReadyToPublish
elsif work_in_progress?
AdminAuctionStatusPresenter::WorkInProgress
elsif payment_needed?
AdminAuctionStatusPresenter::AcceptedOtherPcard
elsif !auction.pending_delivery?
Object.const_get("AdminAuctionStatusPresenter::#{delivery_status}")
else # available?
Expand All @@ -67,6 +69,10 @@ def work_in_progress?
auction.work_in_progress?
end

def payment_needed?
auction.accepted? && auction.delivery_url.present? && auction.paid_at.nil?
end

def bidding_status
@_bidding_status ||= BiddingStatus.new(auction)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class AdminAuctionStatusPresenter::AcceptedOtherPcard < AdminAuctionStatusPresenter::Base
def header
I18n.t('statuses.admin_auction_status_presenter.accepted_other_pcard.header')
end

def body
I18n.t(
'statuses.admin_auction_status_presenter.accepted_other_pcard.body',
customer_url: customer_url,
accepted_at: accepted_at,
winner_url: winner_url
)
end

def action_partial
'admin/auctions/mark_paid'
end

private

def accepted_at
DcTimePresenter.convert_and_format(auction.accepted_at)
end

def customer_url
Url.new(
link_text: customer_name,
path_name: 'admin_customer',
params: { id: customer.id }
)
end

def customer
auction.customer
end

def customer_name
customer.agency_name
end
end
11 changes: 11 additions & 0 deletions app/services/mark_paid_auction.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class MarkPaidAuction
attr_reader :auction

def initialize(auction:)
@auction = auction
end

def perform
auction.update(paid_at: Time.now)
end
end
5 changes: 5 additions & 0 deletions app/views/admin/auctions/_mark_paid.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= link_to(
I18n.t('statuses.admin_auction_status_presenter.accepted_other_pcard.actions.mark_paid'),
admin_auction_mark_payment_path(status.auction),
method: :patch,
class: 'usa-button usa-button-outline action-button') %>
14 changes: 12 additions & 2 deletions config/locales/statuses/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ en:
%{delivery_deadline}.
pending_acceptance:
body: >
%{winner_url} made a <a href=%{delivery_url}>pull request</a> and marked this auction as
delivered. If their work meets this auction's acceptance criteria, click
%{winner_url} made a <a href=%{delivery_url}>pull
request</a> and marked this auction as delivered. If their
work meets this auction's acceptance criteria, click
"accept." Otherwise, click "reject."
header: "Pending acceptance"
actions:
Expand All @@ -148,6 +149,15 @@ en:
accepted:
header: "Accepted"
body: "%{winner_url}'s delivered code was accepted on %{accepted_at}."
accepted_other_pcard:
header: Pending payment from customer
body: >
%{winner_url}'s delivered code was accepted on
%{accepted_at}. %{customer_url} has been asked to remit
payment. You must manually mark this auction as paid when it
is paid by the customer.
actions:
mark_paid: Mark as paid
rejected:
header: "Rejected"
body: "<a href=%{delivery_url}>%{winner_name}'s work</a> was rejected on %{rejected_at}."
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
resources :auction_published, only: [:update]
resources :auction_rejections, only: [:update]
resources :auction_acceptances, only: [:update]
resources :auction_mark_payments, only: [:update]
resources :user_reports, only: [:index]
resources :proposals, only: [:create]
resources :users, only: [:show, :edit, :update]
Expand Down
25 changes: 25 additions & 0 deletions features/admin_views_payment_needed_other_pcard.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Feature: Admin views an auction with payment needed from an "other" P-card
As an administrator
I want to see if an auction needs to be paid directly by a customer
So that I can notify them if there is a problem

Scenario: Admin sees that accepted auction requires payment via other p-card (not 18F)
Given I am an administrator
And I sign in
And there is an accepted auction that needs payment
And the auction is for a different purchase card
And the auction has an associated customer

When I visit the admin auction page for that auction
Then I should see an admin status message that the auction needs payment from a customer

Scenario: Mark as paid
Given I am an administrator
And I sign in
And there is an accepted auction that needs payment
And the auction is for a different purchase card
And the auction has an associated customer

When I visit the admin auction page for that auction
And I mark the auction as paid
# Then I should see the C2 status for an auction with payment confirmation
14 changes: 14 additions & 0 deletions features/step_definitions/auction_create_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@
@auction = FactoryGirl.create(:auction, :with_bids, :pending_acceptance)
end

Given(/^there is an accepted auction that needs payment$/) do
@auction = FactoryGirl.create(:auction, :payment_needed)
end

Given(/^there is a complete and successful auction$/) do
@auction = FactoryGirl.create(:auction, :complete_and_successful)
end
Expand Down Expand Up @@ -176,6 +180,10 @@
@auction.update(purchase_card: :other)
end

Given(/^the auction needs payment$/) do
@auction.update(FactoryGirl.attributes_for(:auction, :payment_needed))
end

Given(/^the c2 proposal for the auction is approved$/) do
@auction.update(c2_status: :approved)
end
Expand All @@ -197,6 +205,12 @@
@auction = FactoryGirl.create(:auction, customer: @customer)
end

Given(/^the auction has an associated customer$/) do
@customer = FactoryGirl.create(:customer)
@auction.customer = @customer
@auction.save!
end

Given(/^there is an auction where the winning vendor is missing a payment method$/) do
@auction = FactoryGirl.create(:auction, :evaluation_needed)
@winning_bidder = WinningBid.new(@auction).find.bidder
Expand Down
5 changes: 5 additions & 0 deletions features/step_definitions/auction_form_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@
button = I18n.t('statuses.admin_auction_status_presenter.pending_acceptance.actions.accept')
step("I click on the \"#{button}\" button")
end

When(/^I mark the auction as paid$/) do
button = I18n.t('statuses.admin_auction_status_presenter.accepted_other_pcard.actions.mark_paid')
step("I click on the \"#{button}\" button")
end
11 changes: 11 additions & 0 deletions features/step_definitions/auction_status_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,14 @@
)
)
end

Then(/^I should see an admin status message that the auction needs payment from a customer$/) do
expect(page.html).to include(
I18n.t(
'statuses.admin_auction_status_presenter.accepted_other_pcard.body',
customer_url: customer_url,
accepted_at: accept_date,
winner_url: winner_url
)
)
end
16 changes: 16 additions & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def start_date
DcTimePresenter.convert_and_format(@auction.started_at)
end

def accept_date
DcTimePresenter.convert_and_format(@auction.accepted_at)
end

def winning_bid
WinningBid.new(@auction).find
end
Expand All @@ -61,6 +65,18 @@ def winner_name
def winner
winning_bid.bidder
end

def customer
@auction.customer
end

def customer_url
Url.new(
link_text: customer.agency_name,
path_name: 'admin_customer',
params: { id: customer.id }
)
end
end

World(AuctionHelpers)
Expand Down
9 changes: 9 additions & 0 deletions spec/models/admin_auction_status_presenter_factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@
end
end

context 'when an auction has been accepted but is for an other pcard' do
it 'should return a AdminAuctionStatusPresenter::AcceptedOtherPcard' do
auction = create(:auction, :payment_needed, purchase_card: :other)

expect(AdminAuctionStatusPresenterFactory.new(auction: auction).create)
.to be_a(AdminAuctionStatusPresenter::AcceptedOtherPcard)
end
end

context 'when the auction has been rejected' do
it 'should return a AdminAuctionStatusPresenter::Rejected' do
auction = create(:auction, :rejected)
Expand Down

0 comments on commit c1841ef

Please sign in to comment.