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

Commit

Permalink
Merge pull request #981 from 18F/jy-admin-auctions-closed
Browse files Browse the repository at this point in the history
Create closed auctions section for admin
  • Loading branch information
adelevie committed Aug 2, 2016
2 parents 5d3d7c6 + d8ec845 commit 7e8fd53
Show file tree
Hide file tree
Showing 21 changed files with 200 additions and 21 deletions.
5 changes: 5 additions & 0 deletions 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
1 change: 0 additions & 1 deletion app/models/auction_query.rb
Expand Up @@ -29,7 +29,6 @@ def complete_and_successful
.delivery_due_at_expired
.delivered
.delivery_accepted
.c2_submitted
.paid
end

Expand Down
4 changes: 4 additions & 0 deletions app/models/null_bidder.rb
Expand Up @@ -3,6 +3,10 @@ def name
nil
end

def github_login
'N/A'
end

def admin_user_page_link_partial
'components/null'
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/rules/sealed_bid_auction.rb
Expand Up @@ -3,7 +3,7 @@ def winning_bid
if auction_available?
NullBid.new
else
auction.lowest_bid
auction.lowest_bid || NullBid.new
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/services/winning_bidder_email_sender.rb
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions app/view_models/admin/base_view_model.rb
Expand Up @@ -3,6 +3,10 @@ def auctions_nav_class
''
end

def closed_auctions_nav_class
''
end

def vendors_nav_class
''
end
Expand Down
37 changes: 37 additions & 0 deletions 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
43 changes: 43 additions & 0 deletions 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
1 change: 1 addition & 0 deletions app/views/admin/_auctions_subnav.html.erb
Expand Up @@ -5,6 +5,7 @@
<li><%= link_to 'All', admin_auctions_path, class: view_model.auctions_nav_class %></li>
<li><%= link_to 'Action Items', admin_action_items_path, class: view_model.action_items_nav_class %></li>
<li><%= link_to 'Draft Auctions', admin_drafts_path, class: view_model.drafts_nav_class %></li>
<li><%= link_to 'Closed', admin_auctions_closed_path, class: view_model.closed_auctions_nav_class %></li>
<li class='new-button'>
<%= link_to 'Add auction',
new_admin_auction_path,
Expand Down
3 changes: 3 additions & 0 deletions app/views/admin/auctions/closed/_no_rejected.html.erb
@@ -0,0 +1,3 @@
<div>
No auctions have been rejected yet
</div>
3 changes: 3 additions & 0 deletions app/views/admin/auctions/closed/_no_successful.html.erb
@@ -0,0 +1,3 @@
<div>
No auctions have been successfully delivered yet
</div>
22 changes: 22 additions & 0 deletions app/views/admin/auctions/closed/_rejected.html.erb
@@ -0,0 +1,22 @@
<table class="usa-table-borderless">
<thead>
<tr>
<th scope="col">Title</th>
<th scope="col">Vendor</th>
<th scope="col">Delivery URL</th>
<th scope="col">Date rejected</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
<% @view_model.rejected.each do |auction| %>
<tr>
<td><%= link_to(auction.title, admin_auction_path(auction.id)) %></td>
<td><%= auction.winning_vendor_github_login %></td>
<td><%= auction.delivery_url %></td>
<td><%= auction.rejected_at %></td>
<td><%= link_to 'edit', edit_admin_auction_path(auction.id) %></td>
</tr>
<% end %>
</tbody>
</table>
22 changes: 22 additions & 0 deletions app/views/admin/auctions/closed/_successful.html.erb
@@ -0,0 +1,22 @@
<table class="usa-table-borderless">
<thead>
<tr>
<th scope="col">Title</th>
<th scope="col">Vendor</th>
<th scope="col">Delivery URL</th>
<th scope="col">Date accepted</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
<% @view_model.successfully_delivered.each do |auction| %>
<tr>
<td><%= link_to(auction.title, admin_auction_path(auction.id)) %></td>
<td><%= auction.winning_vendor_github_login %></td>
<td><%= auction.delivery_url %></td>
<td><%= auction.accepted_at %></td>
<td><%= link_to 'edit', edit_admin_auction_path(auction.id) %></td>
</tr>
<% end %>
</tbody>
</table>
9 changes: 9 additions & 0 deletions app/views/admin/auctions/closed/index.html.erb
@@ -0,0 +1,9 @@
<%= render partial: 'admin/auctions_subnav', locals: { view_model: @view_model } %>

<h2>Successfully Delivered</h2>

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

<h2>Rejected Auctions</h2>

<%= render partial: @view_model.rejected_partial, locals: { view_model: @view_model } %>
7 changes: 6 additions & 1 deletion config/routes.rb
Expand Up @@ -18,14 +18,19 @@
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]
resources :drafts, only: [:index]
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]
Expand Down
8 changes: 4 additions & 4 deletions features/admin_views_action_items.feature
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions 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"

@@ -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
Expand Down
12 changes: 4 additions & 8 deletions features/step_definitions/auction_attributes_steps.rb
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions features/step_definitions/auction_create_steps.rb
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions features/step_definitions/navigation_steps.rb
Expand Up @@ -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
Expand Down

0 comments on commit 7e8fd53

Please sign in to comment.