This repository has been archived by the owner on Jul 30, 2019. It is now read-only.
/
auction_create_steps.rb
184 lines (149 loc) · 5.63 KB
/
auction_create_steps.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
Given(/^there is an unpublished auction$/) do
@auction = FactoryGirl.create(:auction, :unpublished)
end
Given(/^there is a future auction$/) do
@auction = FactoryGirl.create(:auction, :future)
end
Given(/^there is a closed auction$/) do
@auction = FactoryGirl.create(:auction, :closed, :with_bidders)
end
Given(/^I am going to win an auction$/) do
@auction = FactoryGirl.build(:auction, :available, :with_bidders)
Timecop.freeze(@auction.ended_at - 15.minutes) do
bids = @auction.bids.sort_by(&:amount)
b = bids.first
b.update_attribute(:bidder_id, @user.id)
SaveAuction.new(@auction).perform
end
end
Given(/^I am going to lose an auction$/) do
@auction = FactoryGirl.build(:auction, :available, :with_bidders)
Timecop.freeze(@auction.ended_at - 15.minutes) do
bids = @auction.bids.sort_by(&:amount)
b = bids.last
b.update_attribute(:bidder_id, @user.id)
SaveAuction.new(@auction).perform
end
end
When(/^the auction ends$/) do
Timecop.return
Timecop.travel(@auction.ended_at + 5.minutes)
Delayed::Worker.new.work_off
end
Given(/^there is a closed bidless auction$/) do
@auction = FactoryGirl.create(:auction, :closed)
end
Given(/^there is an expiring auction$/) do
@auction = FactoryGirl.create(:auction, :expiring, :with_bidders)
end
Given(/^there is an open bidless auction$/) do
@auction = FactoryGirl.create(:auction)
end
Given(/^there is an open auction$/) do
@auction = FactoryGirl.create(:auction, :with_bidders)
end
Given(/^there is an open auction with some skills$/) do
@auction = FactoryGirl.create(:auction)
skills = FactoryGirl.create_list(:skill, 2)
@auction.skills << skills
end
Given(/^there is a budget approved auction$/) do
@auction = FactoryGirl.create(:auction, :c2_approved, :with_bidders)
end
Given(/^there is a sealed-bid auction$/) do
@auction = FactoryGirl.create(:auction, :running, :sealed_bid)
end
Given(/^there is a closed sealed-bid auction$/) do
@auction = FactoryGirl.create(:auction, :closed, :with_bidders, :sealed_bid)
end
Given(/^there is an auction that needs evaluation$/) do
@auction = FactoryGirl.create(:auction, :with_bidders, :evaluation_needed, :c2_approved)
end
Given(/^there is an auction within the simplified acquisition threshold$/) do
@auction = FactoryGirl.create(:auction, :between_micropurchase_and_sat_threshold, :available)
end
Given(/^there is an auction below the micropurchase threshold$/) do
@auction = FactoryGirl.create(:auction, :below_micropurchase_threshold, :available)
end
Given(/^there is an auction with a starting price between the micropurchase threshold and simplified acquisition threshold$/) do
@auction = FactoryGirl.create(
:auction,
:between_micropurchase_and_sat_threshold,
:available
)
end
Given(/^there are many different auctions$/) do
FactoryGirl.create(:auction, :closed, title: Faker::Commerce.product_name)
FactoryGirl.create(:auction, :running, title: Faker::Commerce.product_name)
FactoryGirl.create(:auction, :future)
end
Given(/^there is also an unpublished auction$/) do
@unpublished_auction = FactoryGirl.create(:auction, published: false)
end
Given(/^there is a complete and successful auction$/) do
@auction = FactoryGirl.create(:auction, :complete_and_successful)
end
Given(/^there is a rejected auction$/) do
@auction = FactoryGirl.create(:auction, :closed, :with_bidders, :delivered, :rejected)
end
Given(/^there is a rejected auction with no bids$/) do
@auction = FactoryGirl.create(:auction, :closed, :rejected)
end
Given(/^there is an auction where the winning vendor is not eligible to be paid$/) do
@auction = FactoryGirl.create(
:auction,
:between_micropurchase_and_sat_threshold,
:winning_vendor_is_non_small_business,
:evaluation_needed
)
end
Given(/^there is a paid auction$/) do
@auction = FactoryGirl.create(:auction, :closed, :accepted, :paid)
end
Given(/^the auction is for the default purchase card$/) do
@auction.update(purchase_card: :default)
end
Given(/^the auction is for a different purchase card$/) do
@auction.update(purchase_card: :other)
end
Given(/^the c2 proposal for the auction is approved$/) do
@auction.update(c2_approval_status: :approved)
end
Given(/^the c2 proposal for the auction is not approved$/) do
@auction.update(c2_approval_status: :not_requested)
end
Given(/^the auction does not have a c2 proposal url$/) do
@auction.update(c2_proposal_url: nil)
end
Given(/^the auction has a c2 proposal url$/) do
@auction.update!(c2_proposal_url: 'https://c2-dev.18f.gov/proposals/123')
end
Given(/^there is an auction with an associated customer$/) do
@customer = FactoryGirl.create(:customer)
@auction = FactoryGirl.create(:auction, customer: @customer)
end
Given(/^there is an auction where the winning vendor is missing a payment method$/) do
@auction = FactoryGirl.create(:auction, :with_bidders, :evaluation_needed)
@winning_bidder = WinningBid.new(@auction).find.bidder
@winning_bidder.update(payment_url: '')
end
Given(/^there is an accepted auction where the winning vendor is missing a payment method$/) do
@auction = FactoryGirl.create(
:auction,
:with_bidders,
:published,
result: :accepted,
accepted_at: nil,
c2_proposal_url: 'https://c2-dev.18f.gov/proposals/2486'
)
@winning_bidder = WinningBid.new(@auction).find.bidder
@winning_bidder.update(payment_url: '')
end
Given(/^there is an accepted auction$/) do
@auction = FactoryGirl.create(:auction, :accepted, :with_bidders)
end
When(/^there is another accepted auction$/) do
# not creating another @auction-like instance variable
# just creating the record without saving to a variable
FactoryGirl.create(:auction, :accepted, :with_bidders)
end