This repository has been archived by the owner on Jul 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
auction_steps.rb
226 lines (186 loc) · 7.44 KB
/
auction_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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# FIXME: Assign to variable based on type and use name as selector (rather than overwriting @auction)
Given(/^there is an? (.+) auction$/) do |label|
@auction = case label
when 'future'
FactoryGirl.create(:auction, :future)
when 'closed'
FactoryGirl.create(:auction, :closed, :with_bidders)
when 'closed bidless'
FactoryGirl.create(:auction, :closed)
when 'expiring'
FactoryGirl.create(:auction, :expiring, :with_bidders)
when 'open bidless'
FactoryGirl.create(:auction)
when 'open'
FactoryGirl.create(:auction, :with_bidders)
when 'single-bid'
FactoryGirl.create(:auction, :running, :single_bid)
when 'closed single-bid'
FactoryGirl.create(:auction, :closed, :with_bidders, :single_bid)
when 'needs evaluation'
FactoryGirl.create(:auction, :with_bidders, :evaluation_needed)
when 'within simplified acquisition threshold'
FactoryGirl.create(:auction, :between_micropurchase_and_sat_threshold, :available)
when 'below the micropurchase threshold'
FactoryGirl.create(:auction, :below_micropurchase_threshold, :available)
else
fail "Unrecognized auction type: #{label}"
end
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
Then(/^I should see that the auction indicates it is for small business only$/) do
auction_div = find('a', text: @auction.title)
.find(:xpath, "..")
.find(:xpath, "..")
.find(:xpath, "..")
expect(auction_div).to have_content('Small-business only')
end
Then(/^I should not see that the auction indicates it is for small business only$/) do
auction_div = find('a', text: @auction.title)
.find(:xpath, "..")
.find(:xpath, "..")
.find(:xpath, "..")
expect(auction_div).to_not have_content('Small-business only')
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
When(/^I visit the auction page$/) do
visit(auction_path(@auction.id))
end
When(/^I visit the unpublished auction$/) do
visit "/auctions/#{@unpublished_auction.id}"
end
When(/^I visit the auction bids page$/) do
visit(auction_bids_path(@auction.id))
end
Then(/^I should see the winning bid for the auction$/) do
auction = AuctionPresenter.new(@auction)
lowest_bid_amount = ApplicationController.helpers.number_to_currency(
auction.lowest_bid.amount
)
expect(page).to have_text(lowest_bid_amount)
end
Then(/^I should see the auction's (.+)$/) do |field|
if field == 'deadline'
expect(page).to have_text(
DcTimePresenter
.convert(@auction.end_datetime)
.beginning_of_day
.strftime(DcTimePresenter::FORMAT))
else
expect(page).to have_text(@auction.send(field))
end
end
Then(/^I should see when bidding starts and ends in ET$/) do
expect(page).to have_text(
DcTimePresenter.convert_and_format(@auction.start_datetime))
expect(page).to have_text(
DcTimePresenter.convert_and_format(@auction.end_datetime))
end
Then(/^I should see the delivery deadline in ET$/) do
expect(page).to have_text(
DcTimePresenter.convert_and_format(@auction.delivery_deadline))
end
Then(/^I should see the start price for the auction is \$(\d+)$/) do |price|
expect(page).to have_field('auction_start_price', with: price)
end
Then(/^I should see the number of bid for the auction$/) do
number_of_bids = "#{@auction.bids.length} bids"
expect(page).to have_content(number_of_bids)
end
Then(/^I should not see the number of bid for the auction$/) do
number_of_bids = "#{@auction.bids.length} bids"
expect(page).to_not have_content(number_of_bids)
end
When(/^I click on the link to the bids$/) do
number_of_bids = "#{@auction.bids.length} bids"
click_on(number_of_bids)
end
Then(/^I should see the bid history$/) do
h1_text = "Bids for \"#{@auction.title}\""
expect(page).to have_content(h1_text)
end
Then(/^I should not see the unpublished auction$/) do
expect(page).to_not have_content(@unpublished_auction.title)
end
Then(/^I should see a routing error$/) do
expect(response).to raise_error(ActionController::RoutingError)
end
Then(/^I should see a message about no auctions$/) do
expect(page).to have_content(
"There are no current open auctions on the site. " \
"Please check back soon to view micropurchase opportunities."
)
end
Then(/^I should see a message about no bids$/) do
expect(page).to have_content("No bids yet.")
end
When(/^I submit a bid for \$(.+)$/) do |amount|
fill_in("Your bid:", with: amount)
step('I click on the "Submit" button')
end
Then(/^I should see a current bid amount( of \$([\d\.]+))?$/) do |_, amount|
expect(page).to have_content(/Current bid: \$[\d,\.]+/)
expect(page).to have_content(amount) unless amount.nil?
end
Then(/^I should see a winning bid amount( of \$([\d\.]+))?$/) do |_, amount|
expect(page).to have_content(/Winning bid \([^\)]+\): \$[\d,\.]+/)
expect(page).to have_content(amount) unless amount.nil?
end
Then(/^I should see a link to the auction issue URL$/) do
page.find("a[href='#{@auction.issue_url}']")
end
Then(/^I should see a confirmation for \$(.+)$/) do |amount|
expect(page).to have_content("Confirm your bid: $#{amount}")
end
Then(/^I should see I have the winning bid$/) do
expect(page).to have_content("You currently have the winning bid.")
expect(page).to_not have_content("You are currently not the winning bidder.")
end
Then(/^I should see I do not have the winning bid$/) do
expect(page).not_to have_content("You are currently the winning bidder.")
expect(page).to have_content("You are currently not the winning bidder.")
end
Then(/^I should see when the auction started$/) do
expect(page).to have_text(
DcTimePresenter.convert_and_format(@auction.start_datetime))
end
Then(/^I should see when the auction ends$/) do
expect(page).to_not have_content("Auction ended at:")
expect(page).to have_content("Bid deadline: #{DcTimePresenter.convert_and_format(@auction.end_datetime)}")
end
Then(/^I should see when the auction ended$/) do
expect(page).to_not have_content("Bid deadline:")
expect(page).to have_text("Auction ended at: #{DcTimePresenter.convert_and_format(@auction.end_datetime)}")
end
Then(/^I should see the delivery deadline$/) do
expect(page).to have_content("Delivery deadline: #{DcTimePresenter.convert_and_format(@auction.delivery_deadline)}")
end
Then(/^I should see the bid button$/) do
within(:css, 'div.auction-info') do
expect(page).to have_content('BID')
end
end
Then(/^I should not see the bid button$/) do
within(:css, 'div.auction-info') do
expect(page).to_not have_content('BID')
end
end
Then(/^I should see an? (.+) status$/) do |label|
within(:css, 'div.auction-info') do
expect(page).to have_content(label)
end
end
Then(/^I should not see an? (.+) status$/) do |label|
within(:css, 'div.auction-info') do
expect(page).to_not have_content(label)
end
end