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

Commit

Permalink
Merge c5e5f30 into 8616154
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Harris committed Oct 4, 2016
2 parents 8616154 + c5e5f30 commit 97d68ce
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 6 deletions.
3 changes: 2 additions & 1 deletion app/models/auction.rb
Expand Up @@ -18,7 +18,8 @@ class Auction < ActiveRecord::Base
pending_approval: 1,
budget_approved: 3,
c2_paid: 4,
payment_confirmed: 5
payment_confirmed: 5,
c2_canceled: 6
}

enum delivery_status: {
Expand Down
32 changes: 32 additions & 0 deletions app/models/c2_cancel_attributes.rb
@@ -0,0 +1,32 @@
class C2CancelAttributes
def initialize(auction)
@auction = auction
end

def to_h
{
status: 'canceled',
gsa18f_procurement: {
additional_info: additional_info
}
}
end

private

attr_accessor :auction

def additional_info
"Reason canceled: #{reason_canceled}"
end

def reason_canceled
if auction.archived?
'the auction was archived'
elsif auction.rejected?
'the auction was rejected'
else
'unknown'
end
end
end
10 changes: 10 additions & 0 deletions app/services/archive_auction.rb
Expand Up @@ -8,6 +8,7 @@ def initialize(auction:)
def perform
if auction.unpublished?
auction.published = :archived
update_c2_status
auction.save
else
false
Expand All @@ -17,4 +18,13 @@ def perform
def self.archive_submit?(params)
params.key?(:archive_auction)
end

private

def update_c2_status
return unless auction.c2_proposal_url.present?

UpdateC2ProposalJob.perform_later(auction.id, 'C2CancelAttributes')
auction.c2_status = :c2_canceled
end
end
25 changes: 25 additions & 0 deletions spec/models/c2_cancel_attributes_spec.rb
@@ -0,0 +1,25 @@
require 'rails_helper'

describe C2CancelAttributes do
describe '#to_h' do
it 'constructs the right attributes for archived auctions' do
auction = create(:auction, :archived)

attributes = C2CancelAttributes.new(auction).to_h

expect(attributes[:status]).to eq('canceled')
expect(attributes[:gsa18f_procurement][:additional_info])
.to eq('Reason canceled: the auction was archived')
end

it 'constructs the right attributes for rejected auctions' do
auction = create(:auction, :rejected)

attributes = C2CancelAttributes.new(auction).to_h

expect(attributes[:status]).to eq('canceled')
expect(attributes[:gsa18f_procurement][:additional_info])
.to eq('Reason canceled: the auction was rejected')
end
end
end
30 changes: 25 additions & 5 deletions spec/services/archive_auction_spec.rb
@@ -1,12 +1,32 @@
require 'rails_helper'

describe ArchiveAuction do
it 'should set the delivery_status to be archived' do
auction = FactoryGirl.create(:auction, :unpublished)
ArchiveAuction.new(auction: auction).perform
context 'for an unpublished auction' do
it 'should set published to be archived' do
auction = FactoryGirl.create(:auction, :unpublished)
ArchiveAuction.new(auction: auction).perform

expect(auction).to be_archived
expect(auction.published).to eq("archived")
expect(auction).to be_archived
expect(auction.published).to eq("archived")
end

context 'when the auction has a c2_proposal_url' do
it 'should set the c2_status to archived' do
auction = FactoryGirl.create(:auction, :unpublished, :c2_budget_approved)
allow(UpdateC2ProposalJob).to receive(:perform_later)
ArchiveAuction.new(auction: auction).perform

expect(auction.reload).to be_c2_canceled
end

it 'should enqueue a job to cancel the C2 proposal' do
auction = FactoryGirl.create(:auction, :unpublished, :c2_budget_approved)
allow(UpdateC2ProposalJob).to receive(:perform_later)
ArchiveAuction.new(auction: auction).perform

expect(UpdateC2ProposalJob).to have_received(:perform_later).with(auction.id, 'C2CancelAttributes')
end
end
end

it 'should not be applied if the auction is published' do
Expand Down

0 comments on commit 97d68ce

Please sign in to comment.