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.
- 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
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe AuctionFunCore::Contracts::AuctionContext::Processor::UnpauseContract, 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 'paused'" 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 'paused'" do
|
30
|
+
let(:auction) { Factory[:auction, :default_paused_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,130 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
RSpec.describe AuctionFunCore::Contracts::BidContext::CreateBidClosedContract, type: :contract do
|
6
|
+
describe "#call" do
|
7
|
+
subject(:contract) { described_class.new.call(attributes) }
|
8
|
+
|
9
|
+
context "when params are blank" 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
|
+
|
15
|
+
expect(contract.errors[:auction_id]).to include(I18n.t("contracts.errors.key?"))
|
16
|
+
expect(contract.errors[:user_id]).to include(I18n.t("contracts.errors.key?"))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "with foreign key user_id param" do
|
21
|
+
context "when is a invalid type" do
|
22
|
+
let(:attributes) { {user_id: "wrongvalue"} }
|
23
|
+
|
24
|
+
it "expect failure with error messages" do
|
25
|
+
expect(contract).to be_failure
|
26
|
+
|
27
|
+
expect(contract.errors[:user_id]).to include(I18n.t("contracts.errors.int?"))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when is not found on database" do
|
32
|
+
let(:attributes) { {user_id: rand(10_000..1_000_000)} }
|
33
|
+
|
34
|
+
it "expect failure with error messages" do
|
35
|
+
expect(contract).to be_failure
|
36
|
+
|
37
|
+
expect(contract.errors[:user_id]).to include(I18n.t("contracts.errors.custom.not_found"))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "when user has already placed a bid on the auction" do
|
42
|
+
let(:user) { Factory[:user] }
|
43
|
+
let(:auction) { Factory[:auction, :default_running_closed] }
|
44
|
+
let(:bid) { Factory[:bid, user: user, auction: auction, value_cents: auction.initial_bid_cents] }
|
45
|
+
let(:attributes) { {auction_id: auction.id, user_id: user.id, value_cents: (bid.value_cents * 2)} }
|
46
|
+
|
47
|
+
it "expect failure with error messages" do
|
48
|
+
expect(contract).to be_failure
|
49
|
+
|
50
|
+
expect(contract.errors[:user_id]).to include(I18n.t("contracts.errors.custom.bids.already_bidded"))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "with foreign key auction_id param" do
|
56
|
+
context "when a invalid type" do
|
57
|
+
let(:attributes) { {auction_id: "wrongvalue"} }
|
58
|
+
|
59
|
+
it "expect failure with error messages" do
|
60
|
+
expect(contract).to be_failure
|
61
|
+
|
62
|
+
expect(contract.errors[:auction_id]).to include(I18n.t("contracts.errors.int?"))
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "when is not found on database" do
|
67
|
+
let(:attributes) { {auction_id: rand(10_000..1_000_000)} }
|
68
|
+
|
69
|
+
it "expect failure with error messages" do
|
70
|
+
expect(contract).to be_failure
|
71
|
+
|
72
|
+
expect(contract.errors[:auction_id]).to include(I18n.t("contracts.errors.custom.not_found"))
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'when auction kind is different of "closed"' do
|
77
|
+
let(:auction) { Factory[:auction, :default_scheduled_penny] }
|
78
|
+
let(:attributes) { {auction_id: auction.id} }
|
79
|
+
|
80
|
+
it "expect failure with error messages" do
|
81
|
+
expect(contract).to be_failure
|
82
|
+
|
83
|
+
expect(contract.errors[:auction_id]).to include(
|
84
|
+
I18n.t("contracts.errors.custom.bids.invalid_kind", kind: "closed")
|
85
|
+
)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'when auction status is not "scheduled" or "running"' do
|
90
|
+
let(:auction) { Factory[:auction, :default_finished_standard] }
|
91
|
+
let(:attributes) { {auction_id: auction.id} }
|
92
|
+
|
93
|
+
it "expect failure with error messages" do
|
94
|
+
expect(contract).to be_failure
|
95
|
+
|
96
|
+
expect(contract.errors[:auction_id]).to include(
|
97
|
+
I18n.t("contracts.errors.custom.bids.invalid_status", status: auction.status)
|
98
|
+
)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context "with value_cents param" do
|
104
|
+
let(:user) { Factory[:user] }
|
105
|
+
let(:auction) { Factory[:auction, :default_running_closed] }
|
106
|
+
|
107
|
+
context "when value_cents is less than to auction initial bid" do
|
108
|
+
let(:value) { Money.new(auction.initial_bid_cents - 1) }
|
109
|
+
let(:attributes) { {auction_id: auction.id, user_id: user.id, value_cents: value.cents} }
|
110
|
+
|
111
|
+
it "expect failure with error messages" do
|
112
|
+
expect(contract).to be_failure
|
113
|
+
|
114
|
+
expect(contract.errors[:value_cents]).to include(
|
115
|
+
I18n.t("contracts.errors.gteq?", num: Money.new(auction.initial_bid_cents).to_f)
|
116
|
+
)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context "when value_cents is greater than or equal to auction initial bid" do
|
121
|
+
let(:value) { Money.new(auction.initial_bid_cents) }
|
122
|
+
let(:attributes) { {auction_id: auction.id, user_id: user.id, value_cents: value.cents} }
|
123
|
+
|
124
|
+
it "expect return success without error messages" do
|
125
|
+
expect(contract).to be_success
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
RSpec.describe AuctionFunCore::Contracts::BidContext::CreateBidPennyContract, type: :contract do
|
6
|
+
describe "#call" do
|
7
|
+
subject(:contract) { described_class.new.call(attributes) }
|
8
|
+
|
9
|
+
context "when params are blank" 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
|
+
|
15
|
+
expect(contract.errors[:auction_id]).to include(I18n.t("contracts.errors.key?"))
|
16
|
+
expect(contract.errors[:user_id]).to include(I18n.t("contracts.errors.key?"))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "with foreign key user_id param" do
|
21
|
+
context "when is a invalid type" do
|
22
|
+
let(:attributes) { {user_id: "wrongvalue"} }
|
23
|
+
|
24
|
+
it "expect failure with error messages" do
|
25
|
+
expect(contract).to be_failure
|
26
|
+
|
27
|
+
expect(contract.errors[:user_id]).to include(I18n.t("contracts.errors.int?"))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when is not found on database" do
|
32
|
+
let(:attributes) { {user_id: rand(10_000..1_000_000)} }
|
33
|
+
|
34
|
+
it "expect failure with error messages" do
|
35
|
+
expect(contract).to be_failure
|
36
|
+
|
37
|
+
expect(contract.errors[:user_id]).to include(I18n.t("contracts.errors.custom.not_found"))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "with foreign key auction_id param" do
|
43
|
+
context "when a invalid type" do
|
44
|
+
let(:attributes) { {auction_id: "wrongvalue"} }
|
45
|
+
|
46
|
+
it "expect failure with error messages" do
|
47
|
+
expect(contract).to be_failure
|
48
|
+
|
49
|
+
expect(contract.errors[:auction_id]).to include(I18n.t("contracts.errors.int?"))
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "when is not found on database" do
|
54
|
+
let(:attributes) { {auction_id: rand(10_000..1_000_000)} }
|
55
|
+
|
56
|
+
it "expect failure with error messages" do
|
57
|
+
expect(contract).to be_failure
|
58
|
+
|
59
|
+
expect(contract.errors[:auction_id]).to include(I18n.t("contracts.errors.custom.not_found"))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'when auction kind is different of "penny"' do
|
64
|
+
let(:auction) { Factory[:auction, :default_scheduled_standard] }
|
65
|
+
let(:attributes) { {auction_id: auction.id} }
|
66
|
+
|
67
|
+
it "expect failure with error messages" do
|
68
|
+
expect(contract).to be_failure
|
69
|
+
|
70
|
+
expect(contract.errors[:auction_id]).to include(
|
71
|
+
I18n.t("contracts.errors.custom.bids.invalid_kind", kind: "penny")
|
72
|
+
)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'when auction status is not "scheduled" or "running"' do
|
77
|
+
let(:auction) { Factory[:auction, :default_finished_standard] }
|
78
|
+
let(:attributes) { {auction_id: auction.id} }
|
79
|
+
|
80
|
+
it "expect failure with error messages" do
|
81
|
+
expect(contract).to be_failure
|
82
|
+
|
83
|
+
expect(contract.errors[:auction_id]).to include(
|
84
|
+
I18n.t("contracts.errors.custom.bids.invalid_status", status: auction.status)
|
85
|
+
)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "with user balance" do
|
91
|
+
let(:bid_cents) { 10_000 }
|
92
|
+
let(:user) { Factory[:user] }
|
93
|
+
let(:auction) { Factory[:auction, :default_running_penny, initial_bid_cents: bid_cents] }
|
94
|
+
let(:attributes) { {auction_id: auction.id, user_id: user.id} }
|
95
|
+
|
96
|
+
context "when does not have enough balance to bid" do
|
97
|
+
it "expect failure with error messages" do
|
98
|
+
expect(contract).to be_failure
|
99
|
+
expect(contract.errors[:user_id]).to include(
|
100
|
+
I18n.t("contracts.errors.custom.bids.insufficient_balance")
|
101
|
+
)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "when has enough balance to bid" do
|
106
|
+
before do
|
107
|
+
AuctionFunCore::Repos::UserContext::UserRepository.new.update(
|
108
|
+
user.id, balance_cents: (bid_cents * 10)
|
109
|
+
)
|
110
|
+
end
|
111
|
+
|
112
|
+
it "expect return success" do
|
113
|
+
expect(contract).to be_success
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
RSpec.describe AuctionFunCore::Contracts::BidContext::CreateBidStandardContract, type: :contract do
|
6
|
+
let(:auction_repo) { described_class.new.auction_repo }
|
7
|
+
|
8
|
+
describe "#call" do
|
9
|
+
subject(:contract) { described_class.new.call(attributes) }
|
10
|
+
|
11
|
+
context "when params are blank" do
|
12
|
+
let(:attributes) { Dry::Core::Constants::EMPTY_HASH }
|
13
|
+
|
14
|
+
it "expect failure with error messages" do
|
15
|
+
expect(contract).to be_failure
|
16
|
+
|
17
|
+
expect(contract.errors[:auction_id]).to include(I18n.t("contracts.errors.key?"))
|
18
|
+
expect(contract.errors[:user_id]).to include(I18n.t("contracts.errors.key?"))
|
19
|
+
expect(contract.errors[:value_cents]).to include(I18n.t("contracts.errors.key?"))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "with foreign key user_id param" do
|
24
|
+
context "when is a invalid type" do
|
25
|
+
let(:attributes) { {user_id: "wrongvalue"} }
|
26
|
+
|
27
|
+
it "expect failure with error messages" do
|
28
|
+
expect(contract).to be_failure
|
29
|
+
|
30
|
+
expect(contract.errors[:user_id]).to include(I18n.t("contracts.errors.int?"))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "when is not found on database" do
|
35
|
+
let(:attributes) { {user_id: rand(10_000..1_000_000)} }
|
36
|
+
|
37
|
+
it "expect failure with error messages" do
|
38
|
+
expect(contract).to be_failure
|
39
|
+
|
40
|
+
expect(contract.errors[:user_id]).to include(I18n.t("contracts.errors.custom.not_found"))
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "with foreign key auction_id param" do
|
46
|
+
context "when a invalid type" do
|
47
|
+
let(:attributes) { {auction_id: "wrongvalue"} }
|
48
|
+
|
49
|
+
it "expect failure with error messages" do
|
50
|
+
expect(contract).to be_failure
|
51
|
+
|
52
|
+
expect(contract.errors[:auction_id]).to include(I18n.t("contracts.errors.int?"))
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when is not found on database" do
|
57
|
+
let(:attributes) { {auction_id: rand(10_000..1_000_000)} }
|
58
|
+
|
59
|
+
it "expect failure with error messages" do
|
60
|
+
expect(contract).to be_failure
|
61
|
+
|
62
|
+
expect(contract.errors[:auction_id]).to include(I18n.t("contracts.errors.custom.not_found"))
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when auction kind is different of "standard"' do
|
67
|
+
let(:auction) { Factory[:auction, :default_scheduled_penny] }
|
68
|
+
let(:attributes) { {auction_id: auction.id} }
|
69
|
+
|
70
|
+
it "expect failure with error messages" do
|
71
|
+
expect(contract).to be_failure
|
72
|
+
|
73
|
+
expect(contract.errors[:auction_id]).to include(
|
74
|
+
I18n.t("contracts.errors.custom.bids.invalid_kind", kind: "standard")
|
75
|
+
)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'when auction status is not "scheduled" or "running"' do
|
80
|
+
let(:auction) { Factory[:auction, :default_finished_standard] }
|
81
|
+
let(:attributes) { {auction_id: auction.id} }
|
82
|
+
|
83
|
+
it "expect failure with error messages" do
|
84
|
+
expect(contract).to be_failure
|
85
|
+
|
86
|
+
expect(contract.errors[:auction_id]).to include(
|
87
|
+
I18n.t("contracts.errors.custom.bids.invalid_status", status: auction.status)
|
88
|
+
)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "with value_cents param" do
|
94
|
+
let(:user) { Factory[:user] }
|
95
|
+
let(:auction) { Factory[:auction, :default_running_standard] }
|
96
|
+
|
97
|
+
context "when auction has no bids" do
|
98
|
+
context "when value_cents is less than to auction minimal initial bid" do
|
99
|
+
let(:value) { Money.new(auction.initial_bid_cents - 1) }
|
100
|
+
let(:attributes) { {auction_id: auction.id, value_cents: value.cents} }
|
101
|
+
|
102
|
+
it "expect failure with error messages" do
|
103
|
+
expect(contract).to be_failure
|
104
|
+
|
105
|
+
expect(contract.errors[:value_cents]).to include(
|
106
|
+
I18n.t("contracts.errors.gteq?", num: Money.new(auction.initial_bid_cents).to_f)
|
107
|
+
)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context "when value_cents is greather than or equal to to minimal bid" do
|
112
|
+
let(:value) { Money.new(auction.initial_bid_cents) }
|
113
|
+
let(:attributes) { {auction_id: auction.id, user_id: user.id, value_cents: value.cents} }
|
114
|
+
|
115
|
+
it "expect return success" do
|
116
|
+
expect(contract).to be_success
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context "when auction has bids" do
|
122
|
+
let(:last_bid) { Money.new(auction.minimal_bid_cents) }
|
123
|
+
let!(:bid) { Factory[:bid, auction: auction, value_cents: last_bid.cents] }
|
124
|
+
let(:required_minimal_bid) { (last_bid.cents + (last_bid.cents * 0.1)) }
|
125
|
+
|
126
|
+
before do
|
127
|
+
auction_repo.update(auction.id, {minimal_bid_cents: required_minimal_bid.to_i})
|
128
|
+
end
|
129
|
+
|
130
|
+
context "when value_cents is less than to auction minimal bid value" do
|
131
|
+
let(:value_cents) { last_bid.cents - 1 }
|
132
|
+
let(:attributes) { {auction_id: auction.id, value_cents: value_cents} }
|
133
|
+
let(:required_minimal_bid) { (last_bid.cents + (last_bid.cents * 0.1)) }
|
134
|
+
|
135
|
+
it "expect failure with error messages" do
|
136
|
+
expect(contract).to be_failure
|
137
|
+
expect(contract.errors[:value_cents]).to include(
|
138
|
+
I18n.t("contracts.errors.gteq?", num: Money.new(required_minimal_bid).to_f)
|
139
|
+
)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
context "when value_cents is greather than or equal to ten percent of auction minimal bid value" do
|
144
|
+
let(:value_cents) { 1_100 }
|
145
|
+
let(:attributes) { {auction_id: auction.id, user_id: user.id, value_cents: value_cents} }
|
146
|
+
|
147
|
+
it "expect return success" do
|
148
|
+
expect(contract).to be_success
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
RSpec.describe AuctionFunCore::Contracts::StaffContext::AuthenticationContract, type: :contract do
|
6
|
+
describe "#call" do
|
7
|
+
subject(:contract) { described_class.new.call(attributes) }
|
8
|
+
|
9
|
+
context "when params are blank" 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[:login]).to include(I18n.t("contracts.errors.key?"))
|
15
|
+
expect(contract.errors[:password]).to include(I18n.t("contracts.errors.key?"))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when login params are invalid" do
|
20
|
+
context "when email is invalid" do
|
21
|
+
let(:attributes) { {login: "invalid_email"} }
|
22
|
+
|
23
|
+
it "expect failure with error messages" do
|
24
|
+
expect(contract).to be_failure
|
25
|
+
expect(contract.errors[:login]).to include(
|
26
|
+
I18n.t("contracts.errors.custom.macro.login_format")
|
27
|
+
)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when phone is invalid" do
|
32
|
+
let(:attributes) { {login: "12345"} }
|
33
|
+
|
34
|
+
it "expect failure with error messages" do
|
35
|
+
expect(contract).to be_failure
|
36
|
+
expect(contract.errors[:login]).to include(
|
37
|
+
I18n.t("contracts.errors.custom.macro.login_format")
|
38
|
+
)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "with database" do
|
44
|
+
context "when login is not found on database" do
|
45
|
+
let(:attributes) { {login: "notfound@staff.com", password: "example"} }
|
46
|
+
|
47
|
+
it "expect failure with error messages" do
|
48
|
+
expect(contract).to be_failure
|
49
|
+
expect(contract.errors[:base]).to include(
|
50
|
+
I18n.t("contracts.errors.custom.default.login_not_found")
|
51
|
+
)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when password doesn't match with storage password on database" do
|
56
|
+
let(:staff) { Factory[:staff] }
|
57
|
+
let(:attributes) { {login: staff.email, password: "invalid"} }
|
58
|
+
|
59
|
+
it "expect failure with error messages" do
|
60
|
+
expect(contract).to be_failure
|
61
|
+
expect(contract.errors[:base]).to include(
|
62
|
+
I18n.t("contracts.errors.custom.default.login_not_found")
|
63
|
+
)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "when credentials are valid but user is inactive" do
|
68
|
+
let(:staff) { Factory[:staff, :inactive] }
|
69
|
+
let(:attributes) { {login: staff.email, password: "password"} }
|
70
|
+
|
71
|
+
it "expect failure with error messages" do
|
72
|
+
expect(contract).to be_failure
|
73
|
+
expect(contract.errors[:base]).to include(
|
74
|
+
I18n.t("contracts.errors.custom.default.inactive_account")
|
75
|
+
)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "when credentials are valid" do
|
81
|
+
let(:staff) { Factory[:staff] }
|
82
|
+
let(:attributes) { {login: staff.email, password: "password"} }
|
83
|
+
|
84
|
+
it "expect return success" do
|
85
|
+
expect(contract).to be_success
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
RSpec.describe AuctionFunCore::Contracts::StaffContext::RegistrationContract, type: :contract do
|
6
|
+
describe "#call" do
|
7
|
+
subject(:contract) { described_class.new.call(attributes) }
|
8
|
+
|
9
|
+
context "when params are blank" 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[:name]).to include(I18n.t("contracts.errors.key?"))
|
15
|
+
expect(contract.errors[:email]).to include(I18n.t("contracts.errors.key?"))
|
16
|
+
expect(contract.errors[:phone]).to include(I18n.t("contracts.errors.key?"))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it_behaves_like "validate_name_contract", :staff
|
21
|
+
it_behaves_like "validate_email_contract", :staff
|
22
|
+
it_behaves_like "validate_phone_contract", :staff
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
RSpec.describe AuctionFunCore::Contracts::UserContext::AuthenticationContract, type: :contract do
|
6
|
+
describe "#call" do
|
7
|
+
subject(:contract) { described_class.new.call(attributes) }
|
8
|
+
|
9
|
+
context "when params are blank" 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[:login]).to include(I18n.t("contracts.errors.key?"))
|
15
|
+
expect(contract.errors[:password]).to include(I18n.t("contracts.errors.key?"))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when login params are invalid" do
|
20
|
+
context "when email is invalid" do
|
21
|
+
let(:attributes) { {login: "invalid_email"} }
|
22
|
+
|
23
|
+
it "expect failure with error messages" do
|
24
|
+
expect(contract).to be_failure
|
25
|
+
expect(contract.errors[:login]).to include(
|
26
|
+
I18n.t("contracts.errors.custom.macro.login_format")
|
27
|
+
)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when phone is invalid" do
|
32
|
+
let(:attributes) { {login: "12345"} }
|
33
|
+
|
34
|
+
it "expect failure with error messages" do
|
35
|
+
expect(contract).to be_failure
|
36
|
+
expect(contract.errors[:login]).to include(
|
37
|
+
I18n.t("contracts.errors.custom.macro.login_format")
|
38
|
+
)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "with database" do
|
44
|
+
context "when login is not found on database" do
|
45
|
+
let(:attributes) { {login: "notfound@user.com", password: "example"} }
|
46
|
+
|
47
|
+
it "expect failure with error messages" do
|
48
|
+
expect(contract).to be_failure
|
49
|
+
expect(contract.errors[:base]).to include(
|
50
|
+
I18n.t("contracts.errors.custom.default.login_not_found")
|
51
|
+
)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when password doesn't match with storage password on database" do
|
56
|
+
let(:user) { Factory[:user] }
|
57
|
+
let(:attributes) { {login: user.email, password: "invalid"} }
|
58
|
+
|
59
|
+
it "expect failure with error messages" do
|
60
|
+
expect(contract).to be_failure
|
61
|
+
expect(contract.errors[:base]).to include(
|
62
|
+
I18n.t("contracts.errors.custom.default.login_not_found")
|
63
|
+
)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "when credentials are valid but user is inactive" do
|
68
|
+
let(:user) { Factory[:user, :inactive] }
|
69
|
+
let(:attributes) { {login: user.email, password: "password"} }
|
70
|
+
|
71
|
+
it "expect failure with error messages" do
|
72
|
+
expect(contract).to be_failure
|
73
|
+
expect(contract.errors[:base]).to include(
|
74
|
+
I18n.t("contracts.errors.custom.default.inactive_account")
|
75
|
+
)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "when credentials are valid" do
|
81
|
+
let(:user) { Factory[:user] }
|
82
|
+
let(:attributes) { {login: user.email, password: "password"} }
|
83
|
+
|
84
|
+
it "expect return success" do
|
85
|
+
expect(contract).to be_success
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|