auction_fun_core 0.8.9 → 0.8.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/auction_fun_core.gemspec +1 -1
- data/lib/auction_fun_core/version.rb +1 -1
- data/spec/auction_fun_core/contracts/auction_context/create_contract_spec.rb +158 -0
- data/spec/auction_fun_core/contracts/auction_context/post_auction/participant_contract_spec.rb +77 -0
- data/spec/auction_fun_core/contracts/auction_context/post_auction/winner_contract_spec.rb +76 -0
- data/spec/auction_fun_core/contracts/auction_context/pre_auction/auction_start_reminder_contract_spec.rb +48 -0
- data/spec/auction_fun_core/contracts/auction_context/processor/finish/closed_contract_spec.rb +59 -0
- data/spec/auction_fun_core/contracts/auction_context/processor/finish/penny_contract_spec.rb +59 -0
- data/spec/auction_fun_core/contracts/auction_context/processor/finish/standard_contract_spec.rb +59 -0
- data/spec/auction_fun_core/contracts/auction_context/processor/pause_contract_spec.rb +39 -0
- data/spec/auction_fun_core/contracts/auction_context/processor/start_contract_spec.rb +59 -0
- data/spec/auction_fun_core/contracts/auction_context/processor/unpause_contract_spec.rb +39 -0
- data/spec/auction_fun_core/contracts/bid_context/create_bid_closed_contract_spec.rb +130 -0
- data/spec/auction_fun_core/contracts/bid_context/create_bid_penny_contract_spec.rb +118 -0
- data/spec/auction_fun_core/contracts/bid_context/create_bid_standard_contract_spec.rb +154 -0
- data/spec/auction_fun_core/contracts/staff_context/authentication_contract_spec.rb +89 -0
- data/spec/auction_fun_core/contracts/staff_context/registration_contract_spec.rb +24 -0
- data/spec/auction_fun_core/contracts/user_context/authentication_contract_spec.rb +89 -0
- data/spec/auction_fun_core/contracts/user_context/email_confirmation_contract_spec.rb +54 -0
- data/spec/auction_fun_core/contracts/user_context/phone_confirmation_contract_spec.rb +54 -0
- data/spec/auction_fun_core/contracts/user_context/registration_contract_spec.rb +27 -0
- data/spec/auction_fun_core/entities/auction_spec.rb +75 -0
- data/spec/auction_fun_core/entities/bid_spec.rb +7 -0
- data/spec/auction_fun_core/entities/staff_spec.rb +38 -0
- data/spec/auction_fun_core/entities/user_spec.rb +106 -0
- data/spec/auction_fun_core/operations/auction_context/create_operation_spec.rb +126 -0
- data/spec/auction_fun_core/operations/auction_context/post_auction/participant_operation_spec.rb +88 -0
- data/spec/auction_fun_core/operations/auction_context/post_auction/winner_operation_spec.rb +76 -0
- data/spec/auction_fun_core/operations/auction_context/pre_auction/auction_start_reminder_operation_spec.rb +98 -0
- data/spec/auction_fun_core/operations/auction_context/processor/finish/closed_operation_spec.rb +107 -0
- data/spec/auction_fun_core/operations/auction_context/processor/finish/penny_operation_spec.rb +107 -0
- data/spec/auction_fun_core/operations/auction_context/processor/finish/standard_operation_spec.rb +106 -0
- data/spec/auction_fun_core/operations/auction_context/processor/pause_operation_spec.rb +83 -0
- data/spec/auction_fun_core/operations/auction_context/processor/start_operation_spec.rb +147 -0
- data/spec/auction_fun_core/operations/auction_context/processor/unpause_operation_spec.rb +80 -0
- data/spec/auction_fun_core/operations/bid_context/create_bid_closed_operation_spec.rb +95 -0
- data/spec/auction_fun_core/operations/bid_context/create_bid_penny_operation_spec.rb +133 -0
- data/spec/auction_fun_core/operations/bid_context/create_bid_standard_operation_spec.rb +95 -0
- data/spec/auction_fun_core/operations/staff_context/authentication_operation_spec.rb +74 -0
- data/spec/auction_fun_core/operations/staff_context/registration_operation_spec.rb +93 -0
- data/spec/auction_fun_core/operations/user_context/authentication_operation_spec.rb +74 -0
- data/spec/auction_fun_core/operations/user_context/email_confirmation_operation_spec.rb +76 -0
- data/spec/auction_fun_core/operations/user_context/phone_confirmation_operation_spec.rb +76 -0
- data/spec/auction_fun_core/operations/user_context/registration_operation_spec.rb +100 -0
- data/spec/auction_fun_core/relations/auctions_spec.rb +471 -0
- data/spec/auction_fun_core/repos/auction_context/auction_repository_spec.rb +64 -0
- data/spec/auction_fun_core/repos/bid_context/bid_repository_spec.rb +64 -0
- data/spec/auction_fun_core/repos/staff_context/staff_repository_spec.rb +118 -0
- data/spec/auction_fun_core/repos/user_context/user_repository_spec.rb +117 -0
- data/spec/auction_fun_core/services/mail/auction_context/post_auction/participant_mailer_spec.rb +48 -0
- data/spec/auction_fun_core/services/mail/auction_context/post_auction/winner_mailer_spec.rb +48 -0
- data/spec/auction_fun_core/services/mail/auction_context/pre_auction/auction_start_reminder_mailer_spec.rb +40 -0
- data/spec/auction_fun_core/services/mail/user_context/registration_mailer_spec.rb +33 -0
- data/spec/auction_fun_core/workers/operations/auction_context/post_auction/participation_operation_job_spec.rb +54 -0
- data/spec/auction_fun_core/workers/operations/auction_context/post_auction/winner_operation_job_spec.rb +48 -0
- data/spec/auction_fun_core/workers/operations/auction_context/pre_auction/auction_start_reminder_operation_job_spec.rb +53 -0
- data/spec/auction_fun_core/workers/operations/auction_context/processor/finish/closed_operation_job_spec.rb +47 -0
- data/spec/auction_fun_core/workers/operations/auction_context/processor/finish/penny_operation_job_spec.rb +47 -0
- data/spec/auction_fun_core/workers/operations/auction_context/processor/finish/standard_operation_job_spec.rb +47 -0
- data/spec/auction_fun_core/workers/operations/auction_context/processor/start_operation_job_spec.rb +47 -0
- data/spec/auction_fun_core/workers/services/mail/auction_context/post_auction/participant_mailer_job_spec.rb +62 -0
- data/spec/auction_fun_core/workers/services/mail/auction_context/post_auction/pre_auction/auction_start_reminder_mailer_job_spec.rb +59 -0
- data/spec/auction_fun_core/workers/services/mail/auction_context/post_auction/winner_mailer_job_spec.rb +62 -0
- data/spec/auction_fun_core/workers/services/mail/user_context/registration_mailer_job_spec.rb +53 -0
- data/spec/auction_fun_core_spec.rb +7 -0
- data/spec/spec_helper.rb +61 -0
- data/spec/support/background_job.rb +7 -0
- data/spec/support/factories/auctions.rb +143 -0
- data/spec/support/factories/bids.rb +6 -0
- data/spec/support/factories/staffs.rb +18 -0
- data/spec/support/factories/users.rb +43 -0
- data/spec/support/faker.rb +6 -0
- data/spec/support/mail.rb +13 -0
- data/spec/support/shared_examples/validate_email_contract.rb +25 -0
- data/spec/support/shared_examples/validate_name_contract.rb +19 -0
- data/spec/support/shared_examples/validate_password_confirmation_contract.rb +16 -0
- data/spec/support/shared_examples/validate_password_contract.rb +18 -0
- data/spec/support/shared_examples/validate_phone_contract.rb +25 -0
- data/spec/support/shared_examples/validate_stopwatch_contract.rb +32 -0
- metadata +79 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 51265464431c461d76cdb8ea73db67d5c0e89b5940c40234a91bca69c8340824
|
|
4
|
+
data.tar.gz: 3412345a03d4524a63a25540a883476793c72e60acc8da1d5819168d8a9a6082
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dd567b1504d755539f5f3f277bfb763816b23b5b725aee4c84b3ccae0722be04565aba2eb4d419dd0a33e3d8c024dc49b261d152e839755b4669fe80f36f9a4a
|
|
7
|
+
data.tar.gz: c7bcec000da4c4fee6f51b4bc511b23caa89760d9b1559c7754d37f7cc9f4f3556b4e3060a6e0aba66131563da3c65a8908135c411a65f242a9b0f59042e6b26
|
data/CHANGELOG.md
CHANGED
data/auction_fun_core.gemspec
CHANGED
|
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
|
|
|
25
25
|
spec.files = Dir.chdir(__dir__) do
|
|
26
26
|
`git ls-files -z`.split("\x0").reject do |f|
|
|
27
27
|
(File.expand_path(f) == __FILE__) ||
|
|
28
|
-
f.start_with?(*%w[bin/ test/
|
|
28
|
+
f.start_with?(*%w[bin/ test/ features/ .git .github appveyor Gemfile])
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
spec.bindir = "exe"
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe AuctionFunCore::Contracts::AuctionContext::CreateContract, type: :contract do
|
|
4
|
+
let(:min) { described_class::AUCTION_MIN_TITLE_LENGTH }
|
|
5
|
+
let(:max) { described_class::AUCTION_MAX_TITLE_LENGTH }
|
|
6
|
+
let(:stopwatch_min_value) { described_class::AUCTION_STOPWATCH_MIN_VALUE }
|
|
7
|
+
let(:stopwatch_max_value) { described_class::AUCTION_STOPWATCH_MAX_VALUE }
|
|
8
|
+
let(:kinds) { described_class::AUCTION_KINDS.join(", ") }
|
|
9
|
+
|
|
10
|
+
describe "#call" do
|
|
11
|
+
subject(:contract) { described_class.new.call(attributes) }
|
|
12
|
+
|
|
13
|
+
context "when params are blank" do
|
|
14
|
+
let(:attributes) { Dry::Core::Constants::EMPTY_HASH }
|
|
15
|
+
|
|
16
|
+
it "expect failure with error messages" do
|
|
17
|
+
expect(contract).to be_failure
|
|
18
|
+
|
|
19
|
+
expect(contract.errors[:title]).to include(I18n.t("contracts.errors.key?"))
|
|
20
|
+
expect(contract.errors[:kind]).to include(I18n.t("contracts.errors.key?"))
|
|
21
|
+
expect(contract.errors[:started_at]).to include(I18n.t("contracts.errors.key?"))
|
|
22
|
+
expect(contract.errors[:staff_id]).to include(I18n.t("contracts.errors.key?"))
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
context "with default values" do
|
|
27
|
+
let(:attributes) { {initial_bid_cents: 100} }
|
|
28
|
+
|
|
29
|
+
it "expect minimal_bid_cents to be equal initial_bid_cents" do
|
|
30
|
+
expect(contract[:minimal_bid_cents]).to eq(100)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe "#staff_id" do
|
|
35
|
+
context "when staff is not found on database" do
|
|
36
|
+
let(:attributes) { {staff_id: 1} }
|
|
37
|
+
|
|
38
|
+
it "expect failure with error messages" do
|
|
39
|
+
expect(contract).to be_failure
|
|
40
|
+
expect(contract.errors[:staff_id])
|
|
41
|
+
.to include(I18n.t("contracts.errors.custom.default.not_found"))
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
describe "#title" do
|
|
47
|
+
let(:attributes) { {title: "abc"} }
|
|
48
|
+
|
|
49
|
+
context "when the characters in the title are outside the allowed range" do
|
|
50
|
+
it "expect failure with error messages" do
|
|
51
|
+
expect(subject).to be_failure
|
|
52
|
+
|
|
53
|
+
expect(subject.errors[:title]).to include(
|
|
54
|
+
I18n.t("contracts.errors.size?.value.string.arg.range", size_left: min, size_right: max)
|
|
55
|
+
)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
describe "#kind" do
|
|
61
|
+
context "when kind is outside of default list" do
|
|
62
|
+
let(:attributes) { {kind: "unknown"} }
|
|
63
|
+
|
|
64
|
+
it "expect failure with error messages" do
|
|
65
|
+
expect(contract).to be_failure
|
|
66
|
+
expect(contract.errors[:kind]).to include(
|
|
67
|
+
I18n.t("contracts.errors.included_in?.arg.default", list: kinds)
|
|
68
|
+
)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
context "when kind is standard or closed and finished_at is blank" do
|
|
73
|
+
let(:attributes) { {kind: "standard", started_at: 3.hours.from_now} }
|
|
74
|
+
|
|
75
|
+
it "expect failure with error messages" do
|
|
76
|
+
expect(contract).to be_failure
|
|
77
|
+
expect(contract.errors[:finished_at]).to include(I18n.t("contracts.errors.filled?"))
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
context "when kind is closed and finished_at is blank" do
|
|
82
|
+
let(:attributes) { {kind: "closed", started_at: 3.hours.from_now} }
|
|
83
|
+
|
|
84
|
+
it "expect failure with error messages" do
|
|
85
|
+
expect(contract).to be_failure
|
|
86
|
+
expect(contract.errors[:finished_at]).to include(I18n.t("contracts.errors.filled?"))
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
describe "#started_at" do
|
|
92
|
+
context "when is less than or equal to now" do
|
|
93
|
+
let(:attributes) { {started_at: 3.days.ago} }
|
|
94
|
+
|
|
95
|
+
it "expect failure with error messages" do
|
|
96
|
+
expect(contract).to be_failure
|
|
97
|
+
expect(contract.errors[:started_at])
|
|
98
|
+
.to include(I18n.t("contracts.errors.custom.default.future"))
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
describe "#finished_at" do
|
|
104
|
+
context "when started_at is less than or equal to finished_at" do
|
|
105
|
+
let(:same_time) { 3.hours.from_now }
|
|
106
|
+
let(:attributes) { {kind: "standard", started_at: same_time, finished_at: same_time} }
|
|
107
|
+
|
|
108
|
+
it "expect failure with error messages" do
|
|
109
|
+
expect(contract).to be_failure
|
|
110
|
+
expect(contract.errors[:finished_at])
|
|
111
|
+
.to include(I18n.t("contracts.errors.custom.auction_context.create.finished_at"))
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
describe "#initial_bid_cents" do
|
|
117
|
+
context "when kind is standard or closed and initial_bid_cents is blank" do
|
|
118
|
+
let(:attributes) { {kind: "standard"} }
|
|
119
|
+
|
|
120
|
+
it "expect failure with error messages" do
|
|
121
|
+
expect(contract).to be_failure
|
|
122
|
+
expect(contract.errors[:initial_bid_cents]).to include(I18n.t("contracts.errors.filled?"))
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
context "when kind is standard or closed and initial_bid_cents is less than or equal to zero" do
|
|
127
|
+
let(:attributes) { {kind: "standard", initial_bid_cents: 0} }
|
|
128
|
+
|
|
129
|
+
it "expect failure with error messages" do
|
|
130
|
+
expect(contract).to be_failure
|
|
131
|
+
expect(contract.errors[:initial_bid_cents]).to include(I18n.t("contracts.errors.gt?", num: 0))
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
context "when kind is penny and initial_bid_cents is blank" do
|
|
136
|
+
let(:attributes) { {kind: "penny"} }
|
|
137
|
+
|
|
138
|
+
it "expect failure without error message in field" do
|
|
139
|
+
expect(contract).to be_failure
|
|
140
|
+
expect(contract.errors[:initial_bid_cents]).to be_blank
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
context "when kind is penny and initial_bid_cents is not zero" do
|
|
145
|
+
let(:attributes) { {kind: "penny", initial_bid_cents: 1000} }
|
|
146
|
+
|
|
147
|
+
it "expect failure with error message" do
|
|
148
|
+
expect(contract).to be_failure
|
|
149
|
+
expect(contract.errors[:initial_bid_cents]).to include(I18n.t("contracts.errors.eql?", left: 0))
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
it_behaves_like "validate_stopwatch_contract" do
|
|
155
|
+
let(:auction) { Factory.structs[:auction, :with_kind_penny, :with_status_scheduled, initial_bid_cents: 1000] }
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
end
|
data/spec/auction_fun_core/contracts/auction_context/post_auction/participant_contract_spec.rb
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe AuctionFunCore::Contracts::AuctionContext::PostAuction::ParticipantContract, type: :contract do
|
|
4
|
+
let(:auction) { Factory[:auction, :default_finished_standard, :with_winner] }
|
|
5
|
+
let(:participant) { Factory[:user] }
|
|
6
|
+
|
|
7
|
+
describe "#call" do
|
|
8
|
+
subject(:contract) { described_class.new.call(attributes) }
|
|
9
|
+
|
|
10
|
+
context "when attributes are invalid" do
|
|
11
|
+
let(:attributes) { Dry::Core::Constants::EMPTY_HASH }
|
|
12
|
+
|
|
13
|
+
it "expect failure with error messages" do
|
|
14
|
+
expect(contract.errors[:auction_id]).to include(I18n.t("contracts.errors.key?"))
|
|
15
|
+
expect(contract.errors[:participant_id]).to include(I18n.t("contracts.errors.key?"))
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
context "when auction is not found on database" do
|
|
20
|
+
let(:attributes) do
|
|
21
|
+
{
|
|
22
|
+
auction_id: 2_234_231,
|
|
23
|
+
participant_id: participant.id
|
|
24
|
+
}
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "expect failure with error messages" do
|
|
28
|
+
expect(contract.errors[:auction_id]).to include(I18n.t("contracts.errors.custom.not_found"))
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
context "when participant is not found on database" do
|
|
33
|
+
let(:attributes) do
|
|
34
|
+
{
|
|
35
|
+
auction_id: auction.id,
|
|
36
|
+
participant_id: 2_234_231
|
|
37
|
+
}
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "expect failure with error messages" do
|
|
41
|
+
expect(contract.errors[:participant_id]).to include(I18n.t("contracts.errors.custom.not_found"))
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
context "when the user did not bid in the auction" do
|
|
46
|
+
let(:attributes) do
|
|
47
|
+
{
|
|
48
|
+
auction_id: auction.id,
|
|
49
|
+
participant_id: participant.id
|
|
50
|
+
}
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "expect failure with error messages" do
|
|
54
|
+
expect(contract.errors[:participant_id]).to include(I18n.t("none", scope: described_class::I18N_SCOPE))
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
context "when the user placed at least one bid in the auction" do
|
|
59
|
+
let(:attributes) do
|
|
60
|
+
{
|
|
61
|
+
auction_id: auction.id,
|
|
62
|
+
participant_id: participant.id
|
|
63
|
+
}
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
before do
|
|
67
|
+
Factory[:bid, auction: auction, user_id: participant.id, value_cents: auction.minimal_bid_cents]
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "expect return success" do
|
|
71
|
+
expect(contract).to be_success
|
|
72
|
+
expect(contract.context[:auction]).to be_a(AuctionFunCore::Entities::Auction)
|
|
73
|
+
expect(contract.context[:participant]).to be_a(AuctionFunCore::Entities::User)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe AuctionFunCore::Contracts::AuctionContext::PostAuction::WinnerContract, type: :contract do
|
|
4
|
+
let(:auction) { Factory[:auction, :default_finished_standard, :with_winner] }
|
|
5
|
+
let(:winner) { auction.winner }
|
|
6
|
+
|
|
7
|
+
describe "#call" do
|
|
8
|
+
subject(:contract) { described_class.new.call(attributes) }
|
|
9
|
+
|
|
10
|
+
context "when attributes are invalid" do
|
|
11
|
+
let(:attributes) { Dry::Core::Constants::EMPTY_HASH }
|
|
12
|
+
|
|
13
|
+
it "expect failure with error messages" do
|
|
14
|
+
expect(contract.errors[:auction_id]).to include(I18n.t("contracts.errors.key?"))
|
|
15
|
+
expect(contract.errors[:winner_id]).to include(I18n.t("contracts.errors.key?"))
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
context "when auction is not found on database" do
|
|
20
|
+
let(:attributes) do
|
|
21
|
+
{
|
|
22
|
+
auction_id: 2_234_231,
|
|
23
|
+
winner_id: winner.id
|
|
24
|
+
}
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "expect failure with error messages" do
|
|
28
|
+
expect(contract.errors[:auction_id]).to include(I18n.t("contracts.errors.custom.not_found"))
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
context "when winner is not found on database" do
|
|
33
|
+
let(:attributes) do
|
|
34
|
+
{
|
|
35
|
+
auction_id: auction.id,
|
|
36
|
+
winner_id: 2_234_231
|
|
37
|
+
}
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "expect failure with error messages" do
|
|
41
|
+
expect(contract.errors[:winner_id]).to include(I18n.t("contracts.errors.custom.not_found"))
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
context "when the informed winner is different from the one set in the auction" do
|
|
46
|
+
let(:real_winner) { Factory[:user] }
|
|
47
|
+
let(:fake_winner) { Factory[:user] }
|
|
48
|
+
let(:auction) { Factory[:auction, :default_scheduled_standard, winner_id: real_winner.id] }
|
|
49
|
+
let(:attributes) do
|
|
50
|
+
{
|
|
51
|
+
auction_id: auction.id,
|
|
52
|
+
winner_id: fake_winner.id
|
|
53
|
+
}
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "expect failure with error messages" do
|
|
57
|
+
expect(contract.errors[:winner_id]).to include(I18n.t("wrong", scope: described_class::I18N_SCOPE))
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
context "when the informed winner is the same as the one set in the auction" do
|
|
62
|
+
let(:attributes) do
|
|
63
|
+
{
|
|
64
|
+
auction_id: auction.id,
|
|
65
|
+
winner_id: winner.id
|
|
66
|
+
}
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "expect return sucess" do
|
|
70
|
+
expect(contract).to be_success
|
|
71
|
+
expect(contract.context[:auction]).to be_a(AuctionFunCore::Entities::Auction)
|
|
72
|
+
expect(contract.context[:winner]).to be_a(AuctionFunCore::Entities::User)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe AuctionFunCore::Contracts::AuctionContext::PreAuction::AuctionStartReminderContract, type: :contract do
|
|
4
|
+
describe "#call" do
|
|
5
|
+
subject(:contract) { described_class.new.call(attributes) }
|
|
6
|
+
|
|
7
|
+
describe "#call" do
|
|
8
|
+
subject(:contract) { described_class.new.call(attributes) }
|
|
9
|
+
|
|
10
|
+
context "when attributes are invalid" do
|
|
11
|
+
let(:attributes) { Dry::Core::Constants::EMPTY_HASH }
|
|
12
|
+
|
|
13
|
+
it "expect failure with error messages" do
|
|
14
|
+
expect(contract.errors[:auction_id]).to include(I18n.t("contracts.errors.key?"))
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
context "when auction is not found on database" do
|
|
19
|
+
let(:attributes) { {auction_id: 2_234_231} }
|
|
20
|
+
|
|
21
|
+
it "expect failure with error messages" do
|
|
22
|
+
expect(contract.errors[:auction_id]).to include(I18n.t("contracts.errors.custom.not_found"))
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
context "when the auction has already started" do
|
|
27
|
+
let(:auction) { Factory[:auction, :default_finished_standard, started_at: 3.hours.ago] }
|
|
28
|
+
let(:attributes) { {auction_id: auction.id} }
|
|
29
|
+
|
|
30
|
+
it "expect failure with error messages" do
|
|
31
|
+
expect(contract.errors[:base]).to include(
|
|
32
|
+
I18n.t("contracts.errors.custom.auction_context.pre_auction.auction_start_reminder.auction_already_started")
|
|
33
|
+
)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
context "when the auction has not started" do
|
|
38
|
+
let(:auction) { Factory[:auction, :default_scheduled_standard, started_at: 3.hours.from_now] }
|
|
39
|
+
let(:attributes) { {auction_id: auction.id} }
|
|
40
|
+
|
|
41
|
+
it "expect return success" do
|
|
42
|
+
expect(contract).to be_success
|
|
43
|
+
expect(contract.context[:auction]).to be_a(AuctionFunCore::Entities::Auction)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe AuctionFunCore::Contracts::AuctionContext::Processor::Finish::ClosedContract, type: :contract do
|
|
4
|
+
describe "#call" do
|
|
5
|
+
subject(:contract) { described_class.new.call(attributes) }
|
|
6
|
+
|
|
7
|
+
context "when attributes are invalid" do
|
|
8
|
+
let(:attributes) { Dry::Core::Constants::EMPTY_HASH }
|
|
9
|
+
|
|
10
|
+
it "expect failure with error messages" do
|
|
11
|
+
expect(contract).to be_failure
|
|
12
|
+
expect(contract.errors[:auction_id]).to include(I18n.t("contracts.errors.key?"))
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
context "when auction is not found on database" do
|
|
17
|
+
let(:attributes) { {auction_id: rand(10_000..1_000_000)} }
|
|
18
|
+
|
|
19
|
+
it "expect failure with error messages" do
|
|
20
|
+
expect(contract).to be_failure
|
|
21
|
+
expect(contract.errors[:auction_id]).to include(I18n.t("contracts.errors.custom.not_found"))
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
context "when auction kind is not equal to 'closed'" do
|
|
26
|
+
let(:auction) { Factory[:auction, :default_running_standard] }
|
|
27
|
+
let(:attributes) { {auction_id: auction.id} }
|
|
28
|
+
|
|
29
|
+
it "expect failure with error messages" do
|
|
30
|
+
expect(contract).to be_failure
|
|
31
|
+
expect(contract.errors[:base]).to include(
|
|
32
|
+
I18n.t("contracts.errors.custom.auction_context.processor.finish.invalid_kind")
|
|
33
|
+
)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
context "when auction status is not equal to 'running'" do
|
|
38
|
+
let(:auction) { Factory[:auction, :default_paused_standard] }
|
|
39
|
+
let(:attributes) { {auction_id: auction.id} }
|
|
40
|
+
|
|
41
|
+
it "expect failure with error messages" do
|
|
42
|
+
expect(contract).to be_failure
|
|
43
|
+
expect(contract.errors[:base]).to include(
|
|
44
|
+
I18n.t("contracts.errors.custom.auction_context.processor.finish.invalid_status")
|
|
45
|
+
)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
context "when attributes are valid" do
|
|
50
|
+
let(:auction) { Factory[:auction, :default_running_closed] }
|
|
51
|
+
let(:attributes) { {auction_id: auction.id} }
|
|
52
|
+
|
|
53
|
+
it "expect return success" do
|
|
54
|
+
expect(contract).to be_success
|
|
55
|
+
expect(contract.context[:auction]).to be_a(AuctionFunCore::Entities::Auction)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe AuctionFunCore::Contracts::AuctionContext::Processor::Finish::PennyContract, type: :contract do
|
|
4
|
+
describe "#call" do
|
|
5
|
+
subject(:contract) { described_class.new.call(attributes) }
|
|
6
|
+
|
|
7
|
+
context "when attributes are invalid" do
|
|
8
|
+
let(:attributes) { Dry::Core::Constants::EMPTY_HASH }
|
|
9
|
+
|
|
10
|
+
it "expect failure with error messages" do
|
|
11
|
+
expect(contract).to be_failure
|
|
12
|
+
expect(contract.errors[:auction_id]).to include(I18n.t("contracts.errors.key?"))
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
context "when auction is not found on database" do
|
|
17
|
+
let(:attributes) { {auction_id: rand(10_000..1_000_000)} }
|
|
18
|
+
|
|
19
|
+
it "expect failure with error messages" do
|
|
20
|
+
expect(contract).to be_failure
|
|
21
|
+
expect(contract.errors[:auction_id]).to include(I18n.t("contracts.errors.custom.not_found"))
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
context "when auction kind is not equal to 'penny'" do
|
|
26
|
+
let(:auction) { Factory[:auction, :default_running_standard] }
|
|
27
|
+
let(:attributes) { {auction_id: auction.id} }
|
|
28
|
+
|
|
29
|
+
it "expect failure with error messages" do
|
|
30
|
+
expect(contract).to be_failure
|
|
31
|
+
expect(contract.errors[:base]).to include(
|
|
32
|
+
I18n.t("contracts.errors.custom.auction_context.processor.finish.invalid_kind")
|
|
33
|
+
)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
context "when auction status is not equal to 'running'" do
|
|
38
|
+
let(:auction) { Factory[:auction, :default_paused_standard] }
|
|
39
|
+
let(:attributes) { {auction_id: auction.id} }
|
|
40
|
+
|
|
41
|
+
it "expect failure with error messages" do
|
|
42
|
+
expect(contract).to be_failure
|
|
43
|
+
expect(contract.errors[:base]).to include(
|
|
44
|
+
I18n.t("contracts.errors.custom.auction_context.processor.finish.invalid_status")
|
|
45
|
+
)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
context "when attributes are valid" do
|
|
50
|
+
let(:auction) { Factory[:auction, :default_running_penny] }
|
|
51
|
+
let(:attributes) { {auction_id: auction.id} }
|
|
52
|
+
|
|
53
|
+
it "expect return success" do
|
|
54
|
+
expect(contract).to be_success
|
|
55
|
+
expect(contract.context[:auction]).to be_a(AuctionFunCore::Entities::Auction)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
data/spec/auction_fun_core/contracts/auction_context/processor/finish/standard_contract_spec.rb
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe AuctionFunCore::Contracts::AuctionContext::Processor::Finish::StandardContract, type: :contract do
|
|
4
|
+
describe "#call" do
|
|
5
|
+
subject(:contract) { described_class.new.call(attributes) }
|
|
6
|
+
|
|
7
|
+
context "when attributes are invalid" do
|
|
8
|
+
let(:attributes) { Dry::Core::Constants::EMPTY_HASH }
|
|
9
|
+
|
|
10
|
+
it "expect failure with error messages" do
|
|
11
|
+
expect(contract).to be_failure
|
|
12
|
+
expect(contract.errors[:auction_id]).to include(I18n.t("contracts.errors.key?"))
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
context "when auction is not found on database" do
|
|
17
|
+
let(:attributes) { {auction_id: rand(10_000..1_000_000)} }
|
|
18
|
+
|
|
19
|
+
it "expect failure with error messages" do
|
|
20
|
+
expect(contract).to be_failure
|
|
21
|
+
expect(contract.errors[:auction_id]).to include(I18n.t("contracts.errors.custom.not_found"))
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
context "when auction kind is not equal to 'standard'" do
|
|
26
|
+
let(:auction) { Factory[:auction, :default_running_penny] }
|
|
27
|
+
let(:attributes) { {auction_id: auction.id} }
|
|
28
|
+
|
|
29
|
+
it "expect failure with error messages" do
|
|
30
|
+
expect(contract).to be_failure
|
|
31
|
+
expect(contract.errors[:base]).to include(
|
|
32
|
+
I18n.t("contracts.errors.custom.auction_context.processor.finish.invalid_kind")
|
|
33
|
+
)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
context "when auction status is not equal to 'running'" do
|
|
38
|
+
let(:auction) { Factory[:auction, :default_paused_standard] }
|
|
39
|
+
let(:attributes) { {auction_id: auction.id} }
|
|
40
|
+
|
|
41
|
+
it "expect failure with error messages" do
|
|
42
|
+
expect(contract).to be_failure
|
|
43
|
+
expect(contract.errors[:base]).to include(
|
|
44
|
+
I18n.t("contracts.errors.custom.auction_context.processor.finish.invalid_status")
|
|
45
|
+
)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
context "when attributes are valid" do
|
|
50
|
+
let(:auction) { Factory[:auction, :default_running_standard] }
|
|
51
|
+
let(:attributes) { {auction_id: auction.id} }
|
|
52
|
+
|
|
53
|
+
it "expect return success" do
|
|
54
|
+
expect(contract).to be_success
|
|
55
|
+
expect(contract.context[:auction]).to be_a(AuctionFunCore::Entities::Auction)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe AuctionFunCore::Contracts::AuctionContext::Processor::PauseContract, type: :contract do
|
|
4
|
+
let(:auction) { Factory[:auction, :default_scheduled_standard] }
|
|
5
|
+
|
|
6
|
+
describe "#call" do
|
|
7
|
+
subject(:contract) { described_class.new.call(attributes) }
|
|
8
|
+
|
|
9
|
+
context "when attributes are invalid" do
|
|
10
|
+
let(:attributes) { Dry::Core::Constants::EMPTY_HASH }
|
|
11
|
+
|
|
12
|
+
it "expect failure with error messages" do
|
|
13
|
+
expect(contract).to be_failure
|
|
14
|
+
expect(contract.errors[:auction_id]).to include(I18n.t("contracts.errors.key?"))
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
context "when auction status is different to 'running'" do
|
|
19
|
+
let(:attributes) { {auction_id: auction.id} }
|
|
20
|
+
|
|
21
|
+
it "expect failure with error messages" do
|
|
22
|
+
expect(contract).to be_failure
|
|
23
|
+
expect(contract.errors[:auction_id]).to include(
|
|
24
|
+
I18n.t("contracts.errors.custom.bids.invalid_status")
|
|
25
|
+
)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
context "when auction status is equal to 'running'" do
|
|
30
|
+
let(:auction) { Factory[:auction, :default_running_standard] }
|
|
31
|
+
let(:attributes) { {auction_id: auction.id} }
|
|
32
|
+
|
|
33
|
+
it "expect return success" do
|
|
34
|
+
expect(contract).to be_success
|
|
35
|
+
expect(contract.context[:auction]).to be_a(AuctionFunCore::Entities::Auction)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe AuctionFunCore::Contracts::AuctionContext::Processor::StartContract, type: :contract do
|
|
4
|
+
let(:auction) { Factory[:auction, :default_scheduled_standard] }
|
|
5
|
+
let(:kinds) { described_class::AUCTION_KINDS.join(", ") }
|
|
6
|
+
|
|
7
|
+
describe "#call" do
|
|
8
|
+
subject(:contract) { described_class.new.call(attributes) }
|
|
9
|
+
|
|
10
|
+
context "when all attributes are blank" do
|
|
11
|
+
let(:attributes) { Dry::Core::Constants::EMPTY_HASH }
|
|
12
|
+
|
|
13
|
+
it "expect failure with error messages" do
|
|
14
|
+
expect(contract).to be_failure
|
|
15
|
+
expect(contract.errors[:auction_id]).to include(I18n.t("contracts.errors.key?"))
|
|
16
|
+
expect(contract.errors[:kind]).to include(I18n.t("contracts.errors.key?"))
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it_behaves_like "validate_stopwatch_contract" do
|
|
21
|
+
let(:auction) { Factory[:auction, :default_scheduled_penny] }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
context "when auction_id is not founded on database" do
|
|
25
|
+
let(:attributes) { {auction_id: 2_234_231} }
|
|
26
|
+
|
|
27
|
+
it "expect failure with error messages" do
|
|
28
|
+
expect(contract).to be_failure
|
|
29
|
+
expect(contract.errors[:auction_id]).to include(I18n.t("contracts.errors.custom.not_found"))
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe "when auction kind is invalid" do
|
|
34
|
+
let(:attributes) { {auction_id: auction.id, auction: "invalid"} }
|
|
35
|
+
|
|
36
|
+
it "expect failure with error messages" do
|
|
37
|
+
expect(contract).to be_failure
|
|
38
|
+
expect(contract.errors[:kind]).to include(
|
|
39
|
+
I18n.t("contracts.errors.included_in?.arg.default", list: kinds)
|
|
40
|
+
)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context "when attributes are valid" do
|
|
45
|
+
let(:attributes) do
|
|
46
|
+
{
|
|
47
|
+
auction_id: auction.id,
|
|
48
|
+
kind: auction.kind,
|
|
49
|
+
stopwatch: described_class::AUCTION_STOPWATCH_MIN_VALUE
|
|
50
|
+
}
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "expect return success" do
|
|
54
|
+
expect(contract).to be_success
|
|
55
|
+
expect(contract.context[:auction]).to be_a(AuctionFunCore::Entities::Auction)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|