From d8ec84564c39d0b0a47ba1b7b4b760cd366f0d87 Mon Sep 17 00:00:00 2001 From: "Jessie A. Young" Date: Fri, 29 Jul 2016 16:42:43 -0700 Subject: [PATCH] Create closed auctions section for admin * Shows successsful and rejected auctions * Closes https://github.com/18F/micropurchase/issues/946 * Closes https://github.com/18F/micropurchase/issues/940 --- .../admin/auctions/closed_controller.rb | 5 +++ app/models/auction_query.rb | 1 - app/models/null_bidder.rb | 4 ++ app/models/rules/sealed_bid_auction.rb | 2 +- app/services/winning_bidder_email_sender.rb | 2 +- app/view_models/admin/base_view_model.rb | 4 ++ .../closed_auctions_list_item_view_model.rb | 37 ++++++++++++++++ .../admin/closed_auctions_view_model.rb | 43 +++++++++++++++++++ app/views/admin/_auctions_subnav.html.erb | 1 + .../auctions/closed/_no_rejected.html.erb | 3 ++ .../auctions/closed/_no_successful.html.erb | 3 ++ .../admin/auctions/closed/_rejected.html.erb | 22 ++++++++++ .../auctions/closed/_successful.html.erb | 22 ++++++++++ .../admin/auctions/closed/index.html.erb | 9 ++++ config/routes.rb | 7 ++- features/admin_views_action_items.feature | 8 ++-- features/admin_views_closed_auctions.feature | 22 ++++++++++ .../admin_views_action_items_steps.rb | 2 +- .../auction_attributes_steps.rb | 12 ++---- .../step_definitions/auction_create_steps.rb | 8 ++-- features/step_definitions/navigation_steps.rb | 4 ++ 21 files changed, 200 insertions(+), 21 deletions(-) create mode 100644 app/controllers/admin/auctions/closed_controller.rb create mode 100644 app/view_models/admin/closed_auctions_list_item_view_model.rb create mode 100644 app/view_models/admin/closed_auctions_view_model.rb create mode 100644 app/views/admin/auctions/closed/_no_rejected.html.erb create mode 100644 app/views/admin/auctions/closed/_no_successful.html.erb create mode 100644 app/views/admin/auctions/closed/_rejected.html.erb create mode 100644 app/views/admin/auctions/closed/_successful.html.erb create mode 100644 app/views/admin/auctions/closed/index.html.erb create mode 100644 features/admin_views_closed_auctions.feature diff --git a/app/controllers/admin/auctions/closed_controller.rb b/app/controllers/admin/auctions/closed_controller.rb new file mode 100644 index 00000000..55ee4a4b --- /dev/null +++ b/app/controllers/admin/auctions/closed_controller.rb @@ -0,0 +1,5 @@ +class Admin::Auctions::ClosedController < Admin::BaseController + def index + @view_model = Admin::ClosedAuctionsViewModel.new + end +end diff --git a/app/models/auction_query.rb b/app/models/auction_query.rb index db1fa19b..8434fc7a 100644 --- a/app/models/auction_query.rb +++ b/app/models/auction_query.rb @@ -29,7 +29,6 @@ def complete_and_successful .delivery_due_at_expired .delivered .delivery_accepted - .c2_submitted .paid end diff --git a/app/models/null_bidder.rb b/app/models/null_bidder.rb index 0e8c7e65..7fd65f53 100644 --- a/app/models/null_bidder.rb +++ b/app/models/null_bidder.rb @@ -3,6 +3,10 @@ def name nil end + def github_login + 'N/A' + end + def admin_user_page_link_partial 'components/null' end diff --git a/app/models/rules/sealed_bid_auction.rb b/app/models/rules/sealed_bid_auction.rb index 86f334ec..b7850407 100644 --- a/app/models/rules/sealed_bid_auction.rb +++ b/app/models/rules/sealed_bid_auction.rb @@ -3,7 +3,7 @@ def winning_bid if auction_available? NullBid.new else - auction.lowest_bid + auction.lowest_bid || NullBid.new end end diff --git a/app/services/winning_bidder_email_sender.rb b/app/services/winning_bidder_email_sender.rb index d05e20f8..e8cee936 100644 --- a/app/services/winning_bidder_email_sender.rb +++ b/app/services/winning_bidder_email_sender.rb @@ -16,7 +16,7 @@ def perform attr_reader :auction def auction_has_winner? - WinningBid.new(auction).find.present? + WinningBid.new(auction).find.is_a?(Bid) end def winning_bidder diff --git a/app/view_models/admin/base_view_model.rb b/app/view_models/admin/base_view_model.rb index 217a080a..45f0c852 100644 --- a/app/view_models/admin/base_view_model.rb +++ b/app/view_models/admin/base_view_model.rb @@ -3,6 +3,10 @@ def auctions_nav_class '' end + def closed_auctions_nav_class + '' + end + def vendors_nav_class '' end diff --git a/app/view_models/admin/closed_auctions_list_item_view_model.rb b/app/view_models/admin/closed_auctions_list_item_view_model.rb new file mode 100644 index 00000000..78275e0c --- /dev/null +++ b/app/view_models/admin/closed_auctions_list_item_view_model.rb @@ -0,0 +1,37 @@ +class Admin::ClosedAuctionsListItemViewModel + attr_reader :auction + + def initialize(auction) + @auction = auction + end + + def title + auction.title + end + + def id + auction.id + end + + def delivery_url + auction.delivery_url + end + + def accepted_at + DcTimePresenter.convert_and_format(auction.accepted_at) + end + + def rejected_at + DcTimePresenter.convert_and_format(auction.rejected_at) + end + + def winning_vendor_github_login + winning_bidder.github_login + end + + private + + def winning_bidder + WinningBid.new(auction).find.bidder || NullBidder.new + end +end diff --git a/app/view_models/admin/closed_auctions_view_model.rb b/app/view_models/admin/closed_auctions_view_model.rb new file mode 100644 index 00000000..de4025b4 --- /dev/null +++ b/app/view_models/admin/closed_auctions_view_model.rb @@ -0,0 +1,43 @@ +class Admin::ClosedAuctionsViewModel < Admin::BaseViewModel + def successful_partial + if successfully_delivered.any? + 'admin/auctions/closed/successful' + else + 'admin/auctions/closed/no_successful' + end + end + + def rejected_partial + if rejected.any? + 'admin/auctions/closed/rejected' + else + 'admin/auctions/closed/no_rejected' + end + end + + def successfully_delivered + @_successfully_delivered ||= complete_and_successful_auctions.map do |auction| + Admin::ClosedAuctionsListItemViewModel.new(auction) + end + end + + def rejected + @_rejected ||= rejected_auctions.map do |auction| + Admin::ClosedAuctionsListItemViewModel.new(auction) + end + end + + def closed_auctions_nav_class + 'usa-current' + end + + private + + def complete_and_successful_auctions + AuctionQuery.new.complete_and_successful + end + + def rejected_auctions + AuctionQuery.new.rejected + end +end diff --git a/app/views/admin/_auctions_subnav.html.erb b/app/views/admin/_auctions_subnav.html.erb index 236027ff..6592d3bd 100644 --- a/app/views/admin/_auctions_subnav.html.erb +++ b/app/views/admin/_auctions_subnav.html.erb @@ -5,6 +5,7 @@
  • <%= link_to 'All', admin_auctions_path, class: view_model.auctions_nav_class %>
  • <%= link_to 'Action Items', admin_action_items_path, class: view_model.action_items_nav_class %>
  • <%= link_to 'Draft Auctions', admin_drafts_path, class: view_model.drafts_nav_class %>
  • +
  • <%= link_to 'Closed', admin_auctions_closed_path, class: view_model.closed_auctions_nav_class %>
  • <%= link_to 'Add auction', new_admin_auction_path, diff --git a/app/views/admin/auctions/closed/_no_rejected.html.erb b/app/views/admin/auctions/closed/_no_rejected.html.erb new file mode 100644 index 00000000..647e61eb --- /dev/null +++ b/app/views/admin/auctions/closed/_no_rejected.html.erb @@ -0,0 +1,3 @@ +
    + No auctions have been rejected yet +
    diff --git a/app/views/admin/auctions/closed/_no_successful.html.erb b/app/views/admin/auctions/closed/_no_successful.html.erb new file mode 100644 index 00000000..3ab3274e --- /dev/null +++ b/app/views/admin/auctions/closed/_no_successful.html.erb @@ -0,0 +1,3 @@ +
    + No auctions have been successfully delivered yet +
    diff --git a/app/views/admin/auctions/closed/_rejected.html.erb b/app/views/admin/auctions/closed/_rejected.html.erb new file mode 100644 index 00000000..99598dca --- /dev/null +++ b/app/views/admin/auctions/closed/_rejected.html.erb @@ -0,0 +1,22 @@ + + + + + + + + + + + + <% @view_model.rejected.each do |auction| %> + + + + + + + + <% end %> + +
    TitleVendorDelivery URLDate rejectedActions
    <%= link_to(auction.title, admin_auction_path(auction.id)) %><%= auction.winning_vendor_github_login %><%= auction.delivery_url %><%= auction.rejected_at %><%= link_to 'edit', edit_admin_auction_path(auction.id) %>
    diff --git a/app/views/admin/auctions/closed/_successful.html.erb b/app/views/admin/auctions/closed/_successful.html.erb new file mode 100644 index 00000000..071efffe --- /dev/null +++ b/app/views/admin/auctions/closed/_successful.html.erb @@ -0,0 +1,22 @@ + + + + + + + + + + + + <% @view_model.successfully_delivered.each do |auction| %> + + + + + + + + <% end %> + +
    TitleVendorDelivery URLDate acceptedActions
    <%= link_to(auction.title, admin_auction_path(auction.id)) %><%= auction.winning_vendor_github_login %><%= auction.delivery_url %><%= auction.accepted_at %><%= link_to 'edit', edit_admin_auction_path(auction.id) %>
    diff --git a/app/views/admin/auctions/closed/index.html.erb b/app/views/admin/auctions/closed/index.html.erb new file mode 100644 index 00000000..9022de5b --- /dev/null +++ b/app/views/admin/auctions/closed/index.html.erb @@ -0,0 +1,9 @@ +<%= render partial: 'admin/auctions_subnav', locals: { view_model: @view_model } %> + +

    Successfully Delivered

    + +<%= render partial: @view_model.successful_partial, locals: { view_model: @view_model } %> + +

    Rejected Auctions

    + +<%= render partial: @view_model.rejected_partial, locals: { view_model: @view_model } %> diff --git a/config/routes.rb b/config/routes.rb index c72936e7..ec40464e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,7 +18,6 @@ get '/sign_in', to: 'sign_ins#show' namespace :admin do - resources :auctions resources :auction_reports, only: [:show] resources :user_reports, only: [:index] resources :action_items, only: [:index] @@ -26,6 +25,12 @@ resources :proposals, only: [:create] resources :users, only: [:show, :edit, :update] + namespace :auctions do + get '/closed', to: 'closed#index' + end + + resources :auctions + scope '/people' do resources :admins, only: [:index] resources :vendors, only: [:index] diff --git a/features/admin_views_action_items.feature b/features/admin_views_action_items.feature index ff96a767..1fff865b 100644 --- a/features/admin_views_action_items.feature +++ b/features/admin_views_action_items.feature @@ -8,11 +8,11 @@ Feature: Admin view action items And I sign in Scenario: Viewing the action items dashboard - Given there are complete and successful auctions - And there is an unpublished auction + Given there is a complete and successful auction + And there is also an unpublished auction When I visit the admin action items page - Then I should see the name of each dashboard auction - And I should see edit links for each dashboard auction + Then I should see the name of the auction + And I should see the edit link for the auction Scenario: Viewing the drafts dashboard Given there is an unpublished auction diff --git a/features/admin_views_closed_auctions.feature b/features/admin_views_closed_auctions.feature new file mode 100644 index 00000000..c03b147f --- /dev/null +++ b/features/admin_views_closed_auctions.feature @@ -0,0 +1,22 @@ +Feature: Admin views closed auctions in the admin panel + As an admin of the Micro-purchase system + I want to be able to view successful and rejected closed auctions + + Scenario: Viewing closed successful auctions + Given I am an administrator + And there is a complete and successful auction + And I sign in + When I visit the admin closed auctions page + Then I should see the name of the auction + And I should see the edit link for the auction + And I should see "No auctions have been rejected yet" + + Scenario: Viewing closed rejected auctions + Given I am an administrator + And there is a rejected auction + And I sign in + When I visit the admin closed auctions page + Then I should see the name of the auction + And I should see the edit link for the auction + And I should see "No auctions have been successfully delivered yet" + diff --git a/features/step_definitions/admin_views_action_items_steps.rb b/features/step_definitions/admin_views_action_items_steps.rb index 918d01f4..690c6e1c 100644 --- a/features/step_definitions/admin_views_action_items_steps.rb +++ b/features/step_definitions/admin_views_action_items_steps.rb @@ -1,5 +1,5 @@ Then(/^I should see the rejected auction as an action item$/) do - auction = Admin::ActionItemListItem.new(@rejected) + auction = Admin::ActionItemListItem.new(@auction) ['Title', 'Delivery Deadline', 'Delivery URL', 'Vendor Name', 'Rejected At'].each_with_index do |header, i| within(:xpath, th_xpath(table_id: 'table-rejected', column: i + 1)) do diff --git a/features/step_definitions/auction_attributes_steps.rb b/features/step_definitions/auction_attributes_steps.rb index 60b21540..e8f5dbd8 100644 --- a/features/step_definitions/auction_attributes_steps.rb +++ b/features/step_definitions/auction_attributes_steps.rb @@ -111,16 +111,12 @@ expect(page).to have_text(@unpublished_auction.description) end -Then(/^I should see the name of each dashboard auction$/) do - @complete_and_successful.each do |auction| - expect(page).to have_text(auction.title) - end +Then(/^I should see the name of the auction$/) do + expect(page).to have_text(@auction.title) end -Then(/^I should see edit links for each dashboard auction$/) do - @complete_and_successful.each do |auction| - expect(page).to have_link('edit', href: edit_admin_auction_path(auction.id)) - end +Then(/^I should see the edit link for the auction$/) do + expect(page).to have_link('edit', href: edit_admin_auction_path(@auction.id)) end Then(/^I should not see the unpublished auction$/) do diff --git a/features/step_definitions/auction_create_steps.rb b/features/step_definitions/auction_create_steps.rb index a526be55..017c433a 100644 --- a/features/step_definitions/auction_create_steps.rb +++ b/features/step_definitions/auction_create_steps.rb @@ -100,16 +100,16 @@ @unpublished_auction = FactoryGirl.create(:auction, published: false) end -Given(/^there are complete and successful auctions$/) do - @complete_and_successful = FactoryGirl.create_list(:auction, 2, :complete_and_successful) +Given(/^there is a complete and successful auction$/) do + @auction = FactoryGirl.create(:auction, :complete_and_successful) end Given(/^there is a rejected auction$/) do - @rejected = FactoryGirl.create(:auction, :closed, :with_bidders, :delivered, :rejected) + @auction = FactoryGirl.create(:auction, :closed, :with_bidders, :delivered, :rejected) end Given(/^there is a rejected auction with no bids$/) do - @rejected = FactoryGirl.create(:auction, :closed, :rejected) + @auction = FactoryGirl.create(:auction, :closed, :rejected) end Given(/^there is an auction where the winning vendor is not eligible to be paid$/) do diff --git a/features/step_definitions/navigation_steps.rb b/features/step_definitions/navigation_steps.rb index c6456584..9740035d 100644 --- a/features/step_definitions/navigation_steps.rb +++ b/features/step_definitions/navigation_steps.rb @@ -70,6 +70,10 @@ visit admin_skills_path end +When(/^I visit the admin closed auctions page$/) do + visit admin_auctions_closed_path +end + Then(/^I should be on the skills admin page$/) do expect(page.current_path).to eq(admin_skills_path) end