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

Commit

Permalink
Admin sees right status when there are no bids
Browse files Browse the repository at this point in the history
        This covers the show page for admin auctions
  • Loading branch information
Kane Baccigalupi committed Nov 22, 2016
1 parent fa73ba3 commit cd2d161
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 16 deletions.
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 @@ -18,6 +18,8 @@ def create
def default_purchase_card_presenter
if auction.archived?
AdminAuctionStatusPresenter::Archived
elsif over_and_no_bids?
AdminAuctionStatusPresenter::NoBids
elsif auction.c2_status == 'not_requested'
C2StatusPresenter::NotRequested
elsif auction.c2_status == 'sent'
Expand Down Expand Up @@ -85,6 +87,10 @@ def available?
bidding_status.available?
end

def over_and_no_bids?
over? && !bids?
end

def won?
over? && bids?
end
Expand Down
19 changes: 19 additions & 0 deletions app/presenters/admin_auction_status_presenter/no_bids.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class AdminAuctionStatusPresenter::NoBids < AdminAuctionStatusPresenter::Base
def header
I18n.t('statuses.admin_auction_status_presenter.no_bids.header')
end

def body
I18n.t(
'statuses.admin_auction_status_presenter.no_bids.body',
end_date: end_date
)
end

private

def end_date
DcTimePresenter.convert_and_format(auction.ended_at)
end
end

3 changes: 3 additions & 0 deletions config/locales/statuses/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ en:
This auction is ready to publish! Please select a start date, end
date, and delivery period for this auction.
header: "Ready to publish"
no_bids:
header: There are no bids
body: "This auction ended on %{end_date} and there were no bids."
work_not_started:
header: Ready for work
body: >
Expand Down
8 changes: 8 additions & 0 deletions features/admin_views_closed_auctions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ Feature: Admin views closed auctions in the admin panel
And I should see "No auctions have been successfully delivered yet"
And I should see "There are no auctions that have not been delivered"

Scenario: Viewing closed auction with no bids
Given I am an administrator
And there is a closed auction with no bids
And I sign in
When I visit the admin auction page for that auction
Then I should see the name of the auction
And I should see the message that the auction is closed without bids

Scenario: Viewing closed successful auctions
Given I am an administrator
And there is a complete and successful auction
Expand Down
8 changes: 8 additions & 0 deletions features/step_definitions/admin_auction_status_steps.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Then(/^I should see that approval has not been requested for the auction$/) do
I18n.t('statuses.c2_presenter.not_requested.body', link: '')
end

Then(/^I should see the message that the auction is closed without bids$/) do
expect(page).to have_content(I18n.t('bidding_status.over.no_bids'))

expect(page).to have_content(
I18n.t('statuses.admin_auction_status_presenter.no_bids.body', end_date: end_date)
)
end
30 changes: 14 additions & 16 deletions spec/models/admin_auction_status_presenter_factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

context 'when the auction has been accepted' do
it 'should return a AdminAuctionStatusPresenter::DefaultPcard::Accepted' do
auction = create(:auction, :accepted)
auction = create(:auction, :accepted, :with_bids)

expect(AdminAuctionStatusPresenterFactory.new(auction: auction).create)
.to be_a(AdminAuctionStatusPresenter::DefaultPcard::Accepted)
Expand All @@ -66,27 +66,25 @@

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

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

context 'when there are no bids' do
it 'should return a AdminAuctionStatusPresenter::NoBids' do
auction = create(:auction, :closed)

context 'rejected auction has no winner' do
it 'should return a AdminAuctionStatusPresenter::Rejected' do
auction = create(:auction, :rejected)

expect(
AdminAuctionStatusPresenterFactory.new(auction: auction).create.body
).to eq(
I18n.t(
'statuses.admin_auction_status_presenter.rejected.body',
delivery_url: auction.delivery_url,
rejected_at: DcTimePresenter.convert_and_format(auction.rejected_at),
winner_name: 'N/A'
)
expect(
AdminAuctionStatusPresenterFactory.new(auction: auction).create.body
).to eq(
I18n.t(
'statuses.admin_auction_status_presenter.no_bids.body',
end_date: DcTimePresenter.convert_and_format(auction.ended_at)
)
end
)
end
end

Expand Down

0 comments on commit cd2d161

Please sign in to comment.