auction_fun_core 0.8.9 → 0.8.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/auction_fun_core.gemspec +1 -1
  4. data/lib/auction_fun_core/version.rb +1 -1
  5. data/spec/auction_fun_core/contracts/auction_context/create_contract_spec.rb +158 -0
  6. data/spec/auction_fun_core/contracts/auction_context/post_auction/participant_contract_spec.rb +77 -0
  7. data/spec/auction_fun_core/contracts/auction_context/post_auction/winner_contract_spec.rb +76 -0
  8. data/spec/auction_fun_core/contracts/auction_context/pre_auction/auction_start_reminder_contract_spec.rb +48 -0
  9. data/spec/auction_fun_core/contracts/auction_context/processor/finish/closed_contract_spec.rb +59 -0
  10. data/spec/auction_fun_core/contracts/auction_context/processor/finish/penny_contract_spec.rb +59 -0
  11. data/spec/auction_fun_core/contracts/auction_context/processor/finish/standard_contract_spec.rb +59 -0
  12. data/spec/auction_fun_core/contracts/auction_context/processor/pause_contract_spec.rb +39 -0
  13. data/spec/auction_fun_core/contracts/auction_context/processor/start_contract_spec.rb +59 -0
  14. data/spec/auction_fun_core/contracts/auction_context/processor/unpause_contract_spec.rb +39 -0
  15. data/spec/auction_fun_core/contracts/bid_context/create_bid_closed_contract_spec.rb +130 -0
  16. data/spec/auction_fun_core/contracts/bid_context/create_bid_penny_contract_spec.rb +118 -0
  17. data/spec/auction_fun_core/contracts/bid_context/create_bid_standard_contract_spec.rb +154 -0
  18. data/spec/auction_fun_core/contracts/staff_context/authentication_contract_spec.rb +89 -0
  19. data/spec/auction_fun_core/contracts/staff_context/registration_contract_spec.rb +24 -0
  20. data/spec/auction_fun_core/contracts/user_context/authentication_contract_spec.rb +89 -0
  21. data/spec/auction_fun_core/contracts/user_context/email_confirmation_contract_spec.rb +54 -0
  22. data/spec/auction_fun_core/contracts/user_context/phone_confirmation_contract_spec.rb +54 -0
  23. data/spec/auction_fun_core/contracts/user_context/registration_contract_spec.rb +27 -0
  24. data/spec/auction_fun_core/entities/auction_spec.rb +75 -0
  25. data/spec/auction_fun_core/entities/bid_spec.rb +7 -0
  26. data/spec/auction_fun_core/entities/staff_spec.rb +38 -0
  27. data/spec/auction_fun_core/entities/user_spec.rb +106 -0
  28. data/spec/auction_fun_core/operations/auction_context/create_operation_spec.rb +126 -0
  29. data/spec/auction_fun_core/operations/auction_context/post_auction/participant_operation_spec.rb +88 -0
  30. data/spec/auction_fun_core/operations/auction_context/post_auction/winner_operation_spec.rb +76 -0
  31. data/spec/auction_fun_core/operations/auction_context/pre_auction/auction_start_reminder_operation_spec.rb +98 -0
  32. data/spec/auction_fun_core/operations/auction_context/processor/finish/closed_operation_spec.rb +107 -0
  33. data/spec/auction_fun_core/operations/auction_context/processor/finish/penny_operation_spec.rb +107 -0
  34. data/spec/auction_fun_core/operations/auction_context/processor/finish/standard_operation_spec.rb +106 -0
  35. data/spec/auction_fun_core/operations/auction_context/processor/pause_operation_spec.rb +83 -0
  36. data/spec/auction_fun_core/operations/auction_context/processor/start_operation_spec.rb +147 -0
  37. data/spec/auction_fun_core/operations/auction_context/processor/unpause_operation_spec.rb +80 -0
  38. data/spec/auction_fun_core/operations/bid_context/create_bid_closed_operation_spec.rb +95 -0
  39. data/spec/auction_fun_core/operations/bid_context/create_bid_penny_operation_spec.rb +133 -0
  40. data/spec/auction_fun_core/operations/bid_context/create_bid_standard_operation_spec.rb +95 -0
  41. data/spec/auction_fun_core/operations/staff_context/authentication_operation_spec.rb +74 -0
  42. data/spec/auction_fun_core/operations/staff_context/registration_operation_spec.rb +93 -0
  43. data/spec/auction_fun_core/operations/user_context/authentication_operation_spec.rb +74 -0
  44. data/spec/auction_fun_core/operations/user_context/email_confirmation_operation_spec.rb +76 -0
  45. data/spec/auction_fun_core/operations/user_context/phone_confirmation_operation_spec.rb +76 -0
  46. data/spec/auction_fun_core/operations/user_context/registration_operation_spec.rb +100 -0
  47. data/spec/auction_fun_core/relations/auctions_spec.rb +471 -0
  48. data/spec/auction_fun_core/repos/auction_context/auction_repository_spec.rb +64 -0
  49. data/spec/auction_fun_core/repos/bid_context/bid_repository_spec.rb +64 -0
  50. data/spec/auction_fun_core/repos/staff_context/staff_repository_spec.rb +118 -0
  51. data/spec/auction_fun_core/repos/user_context/user_repository_spec.rb +117 -0
  52. data/spec/auction_fun_core/services/mail/auction_context/post_auction/participant_mailer_spec.rb +48 -0
  53. data/spec/auction_fun_core/services/mail/auction_context/post_auction/winner_mailer_spec.rb +48 -0
  54. data/spec/auction_fun_core/services/mail/auction_context/pre_auction/auction_start_reminder_mailer_spec.rb +40 -0
  55. data/spec/auction_fun_core/services/mail/user_context/registration_mailer_spec.rb +33 -0
  56. data/spec/auction_fun_core/workers/operations/auction_context/post_auction/participation_operation_job_spec.rb +54 -0
  57. data/spec/auction_fun_core/workers/operations/auction_context/post_auction/winner_operation_job_spec.rb +48 -0
  58. data/spec/auction_fun_core/workers/operations/auction_context/pre_auction/auction_start_reminder_operation_job_spec.rb +53 -0
  59. data/spec/auction_fun_core/workers/operations/auction_context/processor/finish/closed_operation_job_spec.rb +47 -0
  60. data/spec/auction_fun_core/workers/operations/auction_context/processor/finish/penny_operation_job_spec.rb +47 -0
  61. data/spec/auction_fun_core/workers/operations/auction_context/processor/finish/standard_operation_job_spec.rb +47 -0
  62. data/spec/auction_fun_core/workers/operations/auction_context/processor/start_operation_job_spec.rb +47 -0
  63. data/spec/auction_fun_core/workers/services/mail/auction_context/post_auction/participant_mailer_job_spec.rb +62 -0
  64. data/spec/auction_fun_core/workers/services/mail/auction_context/post_auction/pre_auction/auction_start_reminder_mailer_job_spec.rb +59 -0
  65. data/spec/auction_fun_core/workers/services/mail/auction_context/post_auction/winner_mailer_job_spec.rb +62 -0
  66. data/spec/auction_fun_core/workers/services/mail/user_context/registration_mailer_job_spec.rb +53 -0
  67. data/spec/auction_fun_core_spec.rb +7 -0
  68. data/spec/spec_helper.rb +61 -0
  69. data/spec/support/background_job.rb +7 -0
  70. data/spec/support/factories/auctions.rb +143 -0
  71. data/spec/support/factories/bids.rb +6 -0
  72. data/spec/support/factories/staffs.rb +18 -0
  73. data/spec/support/factories/users.rb +43 -0
  74. data/spec/support/faker.rb +6 -0
  75. data/spec/support/mail.rb +13 -0
  76. data/spec/support/shared_examples/validate_email_contract.rb +25 -0
  77. data/spec/support/shared_examples/validate_name_contract.rb +19 -0
  78. data/spec/support/shared_examples/validate_password_confirmation_contract.rb +16 -0
  79. data/spec/support/shared_examples/validate_password_contract.rb +18 -0
  80. data/spec/support/shared_examples/validate_phone_contract.rb +25 -0
  81. data/spec/support/shared_examples/validate_stopwatch_contract.rb +32 -0
  82. metadata +79 -2
@@ -0,0 +1,471 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe AuctionFunCore::Relations::Auctions, type: :relations do
6
+ subject(:relation) { AuctionFunCore::Application[:container].relations[:auctions] }
7
+
8
+ describe "#all(page = 1, per_page = 10, options = { bidders_count: 3 })" do
9
+ subject(:object) { relation.all }
10
+
11
+ context "when page argument is a invalid input" do
12
+ it "expect raise exception" do
13
+ expect { relation.all(nil, 10) }.to raise_error(RuntimeError, "Invalid argument")
14
+ end
15
+ end
16
+
17
+ context "when per_page argument is a invalid input" do
18
+ it "expect raise exception" do
19
+ expect { relation.all(1, nil) }.to raise_error(RuntimeError, "Invalid argument")
20
+ end
21
+ end
22
+
23
+ it "expect include pagination on query" do
24
+ expect(relation.all.dataset.sql).to include("LIMIT 10 OFFSET 0")
25
+ end
26
+
27
+ context "when there are no auctions available" do
28
+ subject(:results) { relation.all.to_a }
29
+
30
+ it "expect return empty data" do
31
+ expect(results).to eq(Dry::Core::Constants::EMPTY_ARRAY)
32
+ end
33
+ end
34
+
35
+ context "when there is an auction available without bids" do
36
+ subject(:result) { relation.all.first }
37
+
38
+ let!(:auction) { Factory[:auction, :default_scheduled_standard] }
39
+
40
+ it "expect return auction attributes with empty bids" do
41
+ expect(result).to be_a_instance_of(ROM::OpenStruct)
42
+ expect(result.bids).to eq({
43
+ "current" => auction.initial_bid_cents,
44
+ "minimal" => auction.minimal_bid_cents,
45
+ "bidders" => Dry::Core::Constants::EMPTY_ARRAY
46
+ })
47
+ expect(result.description).to eq(auction.description)
48
+ expect(result.finished_at).to eq(auction.finished_at)
49
+ expect(result.id).to eq(auction.id)
50
+ expect(result.initial_bid_cents).to eq(auction.initial_bid_cents)
51
+ expect(result.kind).to eq(auction.kind)
52
+ expect(result.started_at).to eq(auction.started_at)
53
+ expect(result.status).to eq(auction.status)
54
+ expect(result.stopwatch).to eq(auction.stopwatch)
55
+ expect(result.title).to eq(auction.title)
56
+ expect(result.total_bids).to be_zero
57
+ end
58
+ end
59
+
60
+ context "when there is an auction available with bids" do
61
+ subject(:result) { relation.all.first }
62
+
63
+ let!(:auction) { Factory[:auction, :default_scheduled_standard] }
64
+ let!(:winner) { Factory[:user] }
65
+ let!(:bid) do
66
+ Factory[:bid, auction: auction, user: winner, value_cents: auction.minimal_bid_cents, value_currency: auction.minimal_bid_currency]
67
+ end
68
+
69
+ it "expect return auction attributes with bids info" do
70
+ expect(result).to be_a_instance_of(ROM::OpenStruct)
71
+ expect(result.bids.to_h).to include({
72
+ "current" => bid.value_cents,
73
+ "minimal" => auction.minimal_bid_cents,
74
+ "bidders" => [{
75
+ "id" => bid.id,
76
+ "user_id" => winner.id,
77
+ "name" => winner.name,
78
+ "value" => bid.value_cents,
79
+ "date" => bid.created_at.strftime("%Y-%m-%dT%H:%M:%S.%6N")
80
+ }]
81
+ })
82
+ expect(result.description).to eq(auction.description)
83
+ expect(result.finished_at).to eq(auction.finished_at)
84
+ expect(result.id).to eq(auction.id)
85
+ expect(result.initial_bid_cents).to eq(auction.initial_bid_cents)
86
+ expect(result.kind).to eq(auction.kind)
87
+ expect(result.started_at).to eq(auction.started_at)
88
+ expect(result.status).to eq(auction.status)
89
+ expect(result.stopwatch).to eq(auction.stopwatch)
90
+ expect(result.title).to eq(auction.title)
91
+ expect(result.total_bids).to eq(1)
92
+ end
93
+ end
94
+ end
95
+
96
+ describe "#info(auction_id, options = { bidders_count: 3 })" do
97
+ subject(:object) { relation.info(auction_id) }
98
+
99
+ let(:auction) { Factory[:auction, :default_scheduled_standard] }
100
+ let(:auction_id) { auction.id }
101
+
102
+ context "when there are no auctions available" do
103
+ subject(:result) { relation.info(2_234_231).one }
104
+
105
+ it "expect return empty data" do
106
+ expect(result).to be_blank
107
+ end
108
+ end
109
+
110
+ context "when there is an auction available without bids" do
111
+ subject(:result) { relation.info(auction_id).one }
112
+
113
+ it "expect return auction attributes with empty bids" do
114
+ expect(result).to be_a_instance_of(ROM::OpenStruct)
115
+ expect(result.bids).to eq({
116
+ "current" => auction.initial_bid_cents,
117
+ "minimal" => auction.minimal_bid_cents,
118
+ "bidders" => Dry::Core::Constants::EMPTY_ARRAY
119
+ })
120
+ expect(result.description).to eq(auction.description)
121
+ expect(result.finished_at).to eq(auction.finished_at)
122
+ expect(result.id).to eq(auction.id)
123
+ expect(result.initial_bid_cents).to eq(auction.initial_bid_cents)
124
+ expect(result.kind).to eq(auction.kind)
125
+ expect(result.started_at).to eq(auction.started_at)
126
+ expect(result.status).to eq(auction.status)
127
+ expect(result.stopwatch).to eq(auction.stopwatch)
128
+ expect(result.title).to eq(auction.title)
129
+ expect(result.total_bids).to be_zero
130
+ end
131
+ end
132
+
133
+ context "when there is an auction available with bids" do
134
+ subject(:result) { relation.all.first }
135
+
136
+ let!(:auction) { Factory[:auction, :default_scheduled_standard] }
137
+ let!(:winner) { Factory[:user] }
138
+ let!(:bid) do
139
+ Factory[:bid, auction: auction, user: winner, value_cents: auction.minimal_bid_cents, value_currency: auction.minimal_bid_currency]
140
+ end
141
+
142
+ it "expect return auction attributes with bids info" do
143
+ expect(result).to be_a_instance_of(ROM::OpenStruct)
144
+ expect(result.bids.to_h).to include({
145
+ "current" => bid.value_cents,
146
+ "minimal" => auction.minimal_bid_cents,
147
+ "bidders" => [{
148
+ "id" => bid.id,
149
+ "user_id" => winner.id,
150
+ "name" => winner.name,
151
+ "value" => bid.value_cents,
152
+ "date" => bid.created_at.strftime("%Y-%m-%dT%H:%M:%S.%6N")
153
+ }]
154
+ })
155
+ expect(result.description).to eq(auction.description)
156
+ expect(result.finished_at).to eq(auction.finished_at)
157
+ expect(result.id).to eq(auction.id)
158
+ expect(result.initial_bid_cents).to eq(auction.initial_bid_cents)
159
+ expect(result.kind).to eq(auction.kind)
160
+ expect(result.started_at).to eq(auction.started_at)
161
+ expect(result.status).to eq(auction.status)
162
+ expect(result.stopwatch).to eq(auction.stopwatch)
163
+ expect(result.title).to eq(auction.title)
164
+ expect(result.total_bids).to eq(1)
165
+ end
166
+ end
167
+ end
168
+
169
+ describe "#load_standard_auction_winners_and_participants(auction_id)" do
170
+ subject(:result) { relation.load_standard_auction_winners_and_participants(auction.id).one }
171
+
172
+ context "when there are no auctions available" do
173
+ subject(:result) { relation.load_standard_auction_winners_and_participants(2_234_231).one }
174
+
175
+ it "expect return empty data" do
176
+ expect(result).to be_blank
177
+ end
178
+ end
179
+
180
+ context "when there is an auction available without bids" do
181
+ let!(:auction) { Factory[:auction, :default_finished_standard] }
182
+
183
+ it "expect return auction data without winner and participants info" do
184
+ expect(result.id).to eq(auction.id)
185
+ expect(result.kind).to eq(auction.kind)
186
+ expect(result.participant_ids).to eq(Dry::Core::Constants::EMPTY_ARRAY)
187
+ expect(result.status).to eq(auction.status)
188
+ expect(result.total_bids).to be_zero
189
+ expect(result.winner_id).to be_nil
190
+ end
191
+ end
192
+
193
+ context "when the auction has only one bid (winner)" do
194
+ let!(:auction) { Factory[:auction, :default_finished_standard] }
195
+ let!(:winner) { Factory[:user] }
196
+ let!(:bid) do
197
+ Factory[:bid, auction: auction, user: winner, value_cents: auction.minimal_bid_cents, value_currency: auction.minimal_bid_currency]
198
+ end
199
+
200
+ it "expect return auction data with winner and no participants info" do
201
+ expect(result.id).to eq(auction.id)
202
+ expect(result.kind).to eq(auction.kind)
203
+ expect(result.participant_ids).to eq(Dry::Core::Constants::EMPTY_ARRAY)
204
+ expect(result.status).to eq(auction.status)
205
+ expect(result.total_bids).to eq(1)
206
+ expect(result.winner_id).to eq(winner.id)
207
+ end
208
+ end
209
+
210
+ context "when the auction has more than one bid (winner and participants)" do
211
+ let!(:auction) { Factory[:auction, :default_finished_standard] }
212
+ let!(:winner) { Factory[:user] }
213
+ let!(:participant) { Factory[:user] }
214
+ let!(:bid) do
215
+ Factory[:bid, auction: auction, user: participant, value_cents: auction.minimal_bid_cents, value_currency: auction.minimal_bid_currency]
216
+ Factory[:bid, auction: auction, user: winner, value_cents: auction.minimal_bid_cents, value_currency: auction.minimal_bid_currency]
217
+ end
218
+
219
+ it "expect return auction data with winner with participants" do
220
+ expect(result.id).to eq(auction.id)
221
+ expect(result.kind).to eq(auction.kind)
222
+ expect(result.participant_ids).to include(participant.id)
223
+ expect(result.status).to eq(auction.status)
224
+ expect(result.total_bids).to eq(2)
225
+ expect(result.winner_id).to eq(winner.id)
226
+ end
227
+ end
228
+ end
229
+
230
+ describe "#load_penny_auction_winners_and_participants(auction_id)" do
231
+ subject(:result) { relation.load_penny_auction_winners_and_participants(auction.id).one }
232
+
233
+ context "when there are no auctions available" do
234
+ subject(:result) { relation.load_penny_auction_winners_and_participants(2_234_231).one }
235
+
236
+ it "expect return empty data" do
237
+ expect(result).to be_blank
238
+ end
239
+ end
240
+
241
+ context "when there is an auction available without bids" do
242
+ let!(:auction) { Factory[:auction, :default_finished_standard] }
243
+
244
+ it "expect return auction data without winner and participants info" do
245
+ expect(result.id).to eq(auction.id)
246
+ expect(result.kind).to eq(auction.kind)
247
+ expect(result.participant_ids).to eq(Dry::Core::Constants::EMPTY_ARRAY)
248
+ expect(result.status).to eq(auction.status)
249
+ expect(result.total_bids).to be_zero
250
+ expect(result.winner_id).to be_nil
251
+ end
252
+ end
253
+
254
+ context "when the auction has only one bid (winner)" do
255
+ let!(:auction) { Factory[:auction, :default_finished_standard] }
256
+ let!(:winner) { Factory[:user] }
257
+ let!(:bid) do
258
+ Factory[:bid, auction: auction, user: winner, value_cents: auction.minimal_bid_cents, value_currency: auction.minimal_bid_currency]
259
+ end
260
+
261
+ it "expect return auction data with winner and no participants info" do
262
+ expect(result.id).to eq(auction.id)
263
+ expect(result.kind).to eq(auction.kind)
264
+ expect(result.participant_ids).to eq(Dry::Core::Constants::EMPTY_ARRAY)
265
+ expect(result.status).to eq(auction.status)
266
+ expect(result.total_bids).to eq(1)
267
+ expect(result.winner_id).to eq(winner.id)
268
+ end
269
+ end
270
+
271
+ context "when the auction has more than one bid (winner and participants)" do
272
+ let!(:auction) { Factory[:auction, :default_finished_standard] }
273
+ let!(:winner) { Factory[:user] }
274
+ let!(:participant) { Factory[:user] }
275
+ let!(:bid) do
276
+ Factory[:bid, auction: auction, user: participant, value_cents: auction.minimal_bid_cents, value_currency: auction.minimal_bid_currency]
277
+ Factory[:bid, auction: auction, user: winner, value_cents: auction.minimal_bid_cents, value_currency: auction.minimal_bid_currency]
278
+ end
279
+
280
+ it "expect return auction data with winner with participants" do
281
+ expect(result.id).to eq(auction.id)
282
+ expect(result.kind).to eq(auction.kind)
283
+ expect(result.participant_ids).to include(participant.id)
284
+ expect(result.status).to eq(auction.status)
285
+ expect(result.total_bids).to eq(2)
286
+ expect(result.winner_id).to eq(winner.id)
287
+ end
288
+ end
289
+ end
290
+
291
+ describe "#load_closed_auction_winners_and_participants(auction_id)" do
292
+ subject(:result) { relation.load_closed_auction_winners_and_participants(auction.id).one }
293
+
294
+ context "when there are no auctions available" do
295
+ subject(:result) { relation.load_closed_auction_winners_and_participants(2_234_231).one }
296
+
297
+ it "expect return empty data" do
298
+ expect(result).to be_blank
299
+ end
300
+ end
301
+
302
+ context "when there is an auction available without bids" do
303
+ let!(:auction) { Factory[:auction, :default_finished_standard] }
304
+
305
+ it "expect return auction data without winner and participants info" do
306
+ expect(result.id).to eq(auction.id)
307
+ expect(result.kind).to eq(auction.kind)
308
+ expect(result.participant_ids).to eq(Dry::Core::Constants::EMPTY_ARRAY)
309
+ expect(result.status).to eq(auction.status)
310
+ expect(result.total_bids).to be_zero
311
+ expect(result.winner_id).to be_nil
312
+ end
313
+ end
314
+
315
+ context "when the auction has only one bid (winner)" do
316
+ let!(:auction) { Factory[:auction, :default_finished_standard] }
317
+ let!(:winner) { Factory[:user] }
318
+ let!(:bid) do
319
+ Factory[:bid, auction: auction, user: winner, value_cents: auction.minimal_bid_cents, value_currency: auction.minimal_bid_currency]
320
+ end
321
+
322
+ it "expect return auction data with winner and no participants info" do
323
+ expect(result.id).to eq(auction.id)
324
+ expect(result.kind).to eq(auction.kind)
325
+ expect(result.participant_ids).to eq(Dry::Core::Constants::EMPTY_ARRAY)
326
+ expect(result.status).to eq(auction.status)
327
+ expect(result.total_bids).to eq(1)
328
+ expect(result.winner_id).to eq(winner.id)
329
+ end
330
+ end
331
+
332
+ context "when the auction has more than one bid (winner and participants)" do
333
+ let!(:auction) { Factory[:auction, :default_finished_standard] }
334
+ let!(:winner) { Factory[:user] }
335
+ let!(:participant) { Factory[:user] }
336
+ let!(:bid) do
337
+ Factory[:bid, auction: auction, user: participant, value_cents: auction.minimal_bid_cents, value_currency: auction.minimal_bid_currency]
338
+ Factory[:bid, auction: auction, user: winner, value_cents: auction.minimal_bid_cents, value_currency: auction.minimal_bid_currency]
339
+ end
340
+
341
+ it "expect return auction data with winner with participants" do
342
+ expect(result.id).to eq(auction.id)
343
+ expect(result.kind).to eq(auction.kind)
344
+ expect(result.participant_ids).to include(participant.id)
345
+ expect(result.status).to eq(auction.status)
346
+ expect(result.total_bids).to eq(2)
347
+ expect(result.winner_id).to eq(winner.id)
348
+ end
349
+ end
350
+ end
351
+
352
+ describe "#load_winner_statistics(auction_id, winner_id)" do
353
+ context "when auction_id argument is a invalid input" do
354
+ it "expect raise exception" do
355
+ expect { relation.load_winner_statistics(nil, 10) }.to raise_error(RuntimeError, "Invalid argument")
356
+ end
357
+ end
358
+
359
+ context "when winner_id argument is a invalid input" do
360
+ it "expect raise exception" do
361
+ expect { relation.load_winner_statistics(1, nil) }.to raise_error(RuntimeError, "Invalid argument")
362
+ end
363
+ end
364
+
365
+ context "when there are no auctions available" do
366
+ subject(:result) { relation.load_winner_statistics(2_234_231, winner.id).one }
367
+
368
+ let(:winner) { Factory[:user] }
369
+
370
+ it "expect return empty data" do
371
+ expect(result).to be_blank
372
+ end
373
+ end
374
+
375
+ context "when there is no bid" do
376
+ subject(:result) { relation.load_winner_statistics(auction.id, winner.id).one }
377
+
378
+ let(:auction) { Factory[:auction, :default_finished_standard] }
379
+ let(:winner) { Factory[:user] }
380
+
381
+ it "expect return auction attributes without winner and without participants" do
382
+ expect(result.id).to eq(auction.id)
383
+ expect(result.auction_total_bids).to be_zero
384
+ expect(result.winner_total_bids).to be_zero
385
+ expect(result.winner_bid).to be_nil
386
+ end
387
+ end
388
+
389
+ context "when there is at least one bid" do
390
+ subject(:result) { relation.load_winner_statistics(auction.id, winner.id).one }
391
+
392
+ let!(:auction) { Factory[:auction, :default_finished_standard] }
393
+ let!(:winner) { Factory[:user] }
394
+ let!(:winner_bid_value) { auction.minimal_bid_cents * 2 }
395
+ let!(:participant) { Factory[:user] }
396
+ let!(:participant_bid) do
397
+ Factory[:bid, auction: auction, user: participant, value_cents: auction.minimal_bid_cents, value_currency: auction.minimal_bid_currency]
398
+ end
399
+ let!(:winner_bid) do
400
+ Factory[:bid, auction: auction, user: winner, value_cents: winner_bid_value, value_currency: auction.minimal_bid_currency]
401
+ end
402
+
403
+ it "expect return auction attributes without winner and without participants" do
404
+ expect(result.id).to eq(auction.id)
405
+ expect(result.auction_total_bids).to eq(2)
406
+ expect(result.winner_total_bids).to eq(1)
407
+ expect(result.winner_bid).to eq(winner_bid_value)
408
+ end
409
+ end
410
+ end
411
+
412
+ describe "#load_participant_statistics(auction_id, participant_id)" do
413
+ context "when auction_id argument is a invalid input" do
414
+ it "expect raise exception" do
415
+ expect { relation.load_participant_statistics(nil, 10) }.to raise_error(RuntimeError, "Invalid argument")
416
+ end
417
+ end
418
+
419
+ context "when participant_id argument is a invalid input" do
420
+ it "expect raise exception" do
421
+ expect { relation.load_participant_statistics(1, nil) }.to raise_error(RuntimeError, "Invalid argument")
422
+ end
423
+ end
424
+
425
+ context "when there are no auctions available" do
426
+ subject(:result) { relation.load_participant_statistics(2_234_231, winner.id).one }
427
+
428
+ let(:winner) { Factory[:user] }
429
+
430
+ it "expect return empty data" do
431
+ expect(result).to be_blank
432
+ end
433
+ end
434
+
435
+ context "when there is no bid" do
436
+ subject(:result) { relation.load_participant_statistics(auction.id, participant.id).one }
437
+
438
+ let(:auction) { Factory[:auction, :default_finished_standard] }
439
+ let(:participant) { Factory[:user] }
440
+
441
+ it "expect return auction attributes without winner and without participants" do
442
+ expect(result.id).to eq(auction.id)
443
+ expect(result.auction_total_bids).to be_zero
444
+ expect(result.winner_total_bids).to be_zero
445
+ expect(result.winner_bid).to be_nil
446
+ end
447
+ end
448
+
449
+ context "when there is at least one bid" do
450
+ subject(:result) { relation.load_participant_statistics(auction.id, participant.id).one }
451
+
452
+ let!(:auction) { Factory[:auction, :default_finished_standard] }
453
+ let!(:winner) { Factory[:user] }
454
+ let!(:winner_bid_value) { auction.minimal_bid_cents * 2 }
455
+ let!(:participant) { Factory[:user] }
456
+ let!(:participant_bid) do
457
+ Factory[:bid, auction: auction, user: participant, value_cents: auction.minimal_bid_cents, value_currency: auction.minimal_bid_currency]
458
+ end
459
+ let!(:winner_bid) do
460
+ Factory[:bid, auction: auction, user: winner, value_cents: winner_bid_value, value_currency: auction.minimal_bid_currency]
461
+ end
462
+
463
+ it "expect return auction attributes without winner and without participants" do
464
+ expect(result.id).to eq(auction.id)
465
+ expect(result.auction_total_bids).to eq(2)
466
+ expect(result.winner_total_bids).to eq(1)
467
+ expect(result.winner_bid).to eq(winner_bid_value)
468
+ end
469
+ end
470
+ end
471
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe AuctionFunCore::Repos::AuctionContext::AuctionRepository, type: :repo do
6
+ subject(:repo) { described_class.new }
7
+
8
+ describe "#all" do
9
+ let!(:auction) { Factory[:auction, :default_scheduled_standard] }
10
+
11
+ it "expect return all auctions" do
12
+ expect(repo.all.size).to eq(1)
13
+ expect(repo.all.first.id).to eq(auction.id)
14
+ end
15
+ end
16
+
17
+ describe "#count" do
18
+ context "when has not auction on repository" do
19
+ it "expect return zero" do
20
+ expect(repo.count).to be_zero
21
+ end
22
+ end
23
+
24
+ context "when has auctions on repository" do
25
+ let!(:auction) { Factory[:auction, :default_scheduled_standard] }
26
+
27
+ it "expect return total" do
28
+ expect(repo.count).to eq(1)
29
+ end
30
+ end
31
+ end
32
+
33
+ describe "#by_id(id)" do
34
+ context "when id is founded on repository" do
35
+ let!(:auction) { Factory[:auction, :default_scheduled_standard] }
36
+
37
+ it "expect return rom object" do
38
+ expect(repo.by_id(auction.id)).to be_a(AuctionFunCore::Entities::Auction)
39
+ end
40
+ end
41
+
42
+ context "when id is not found on repository" do
43
+ it "expect return nil" do
44
+ expect(repo.by_id(nil)).to be_nil
45
+ end
46
+ end
47
+ end
48
+
49
+ describe "#by_id!(id)" do
50
+ context "when id is founded on repository" do
51
+ let!(:auction) { Factory[:auction, :default_scheduled_standard] }
52
+
53
+ it "expect return rom object" do
54
+ expect(repo.by_id(auction.id)).to be_a(AuctionFunCore::Entities::Auction)
55
+ end
56
+ end
57
+
58
+ context "when id is not found on repository" do
59
+ it "expect raise exception" do
60
+ expect { repo.by_id!(nil) }.to raise_error(ROM::TupleCountMismatchError)
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe AuctionFunCore::Repos::BidContext::BidRepository, type: :repo do
6
+ subject(:repo) { described_class.new }
7
+
8
+ describe "#create" do
9
+ let(:auction) { Factory[:auction, :default_scheduled_standard] }
10
+ let(:user) { Factory[:user] }
11
+
12
+ let(:bid) do
13
+ repo.create(
14
+ auction_id: auction.id,
15
+ user_id: user.id,
16
+ value_cents: auction.minimal_bid_cents
17
+ )
18
+ end
19
+
20
+ it "expect create a new bid on repository" do
21
+ expect(bid).to be_a(AuctionFunCore::Entities::Bid)
22
+ expect(bid.auction_id).to eq(auction.id)
23
+ expect(bid.user_id).to eq(user.id)
24
+ expect(bid.value_cents).to eq(auction.minimal_bid_cents)
25
+ expect(bid.created_at).not_to be_blank
26
+ expect(bid.updated_at).not_to be_blank
27
+ end
28
+ end
29
+
30
+ describe "#count" do
31
+ context "when has not bids on repository" do
32
+ it "expect return zero" do
33
+ expect(repo.count).to be_zero
34
+ end
35
+ end
36
+
37
+ context "when has bids on repository" do
38
+ let!(:bid) { Factory[:bid] }
39
+
40
+ it "expect return total" do
41
+ expect(repo.count).to eq(1)
42
+ end
43
+ end
44
+ end
45
+
46
+ describe "#exists?(conditions)" do
47
+ context "when conditions finds any record" do
48
+ let(:bid) { Factory[:bid] }
49
+ let(:conditions) { {auction_id: bid.auction_id, user_id: bid.user_id} }
50
+
51
+ it "expect return true" do
52
+ expect(repo).to exist(conditions)
53
+ end
54
+ end
55
+
56
+ context "when conditions does not find any record" do
57
+ let(:conditions) { {id: -1} }
58
+
59
+ it "expect return false" do
60
+ expect(repo).not_to exist(conditions)
61
+ end
62
+ end
63
+ end
64
+ end