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,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
RSpec.describe AuctionFunCore::Contracts::UserContext::EmailConfirmationContract, type: :contract do
|
6
|
+
let(:generate_email_confirmation_token) { AuctionFunCore::Business::TokenService.generate_email_token }
|
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
|
+
expect(contract.errors[:email_confirmation_token]).to include(I18n.t("contracts.errors.key?"))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when email_confirmation_token is present" do
|
21
|
+
context "when token is not found on database" do
|
22
|
+
let(:attributes) { {email_confirmation_token: SecureRandom.hex(3)} }
|
23
|
+
|
24
|
+
it "expect failure with error messages" do
|
25
|
+
expect(contract).to be_failure
|
26
|
+
expect(contract.errors[:email_confirmation_token]).to include(
|
27
|
+
I18n.t("contracts.errors.custom.default.not_found")
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when credentials are valid but user is inactive" do
|
33
|
+
let(:user) { Factory[:user, :inactive, :with_email_confirmation_token] }
|
34
|
+
let(:attributes) { {email_confirmation_token: user.email_confirmation_token} }
|
35
|
+
|
36
|
+
it "expect failure with error messages" do
|
37
|
+
expect(contract).to be_failure
|
38
|
+
expect(contract.errors[:base]).to include(
|
39
|
+
I18n.t("contracts.errors.custom.default.inactive_account")
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "when email_confirmation_token is valid" do
|
46
|
+
let(:user) { Factory[:user, :unconfirmed, :with_email_confirmation_token] }
|
47
|
+
let(:attributes) { {email_confirmation_token: user.email_confirmation_token} }
|
48
|
+
|
49
|
+
it "expect return success" do
|
50
|
+
expect(contract).to be_success
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
RSpec.describe AuctionFunCore::Contracts::UserContext::PhoneConfirmationContract, type: :contract do
|
6
|
+
let(:generate_phone_confirmation_token) { AuctionFunCore::Business::TokenService.generate_phone_token }
|
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
|
+
expect(contract.errors[:phone_confirmation_token]).to include(I18n.t("contracts.errors.key?"))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when phone_confirmation_token is present" do
|
21
|
+
context "when token is not found on database" do
|
22
|
+
let(:attributes) { {phone_confirmation_token: SecureRandom.hex(3)} }
|
23
|
+
|
24
|
+
it "expect failure with error messages" do
|
25
|
+
expect(contract).to be_failure
|
26
|
+
expect(contract.errors[:phone_confirmation_token]).to include(
|
27
|
+
I18n.t("contracts.errors.custom.default.not_found")
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when credentials are valid but user is inactive" do
|
33
|
+
let(:user) { Factory[:user, :inactive, :with_phone_confirmation_token] }
|
34
|
+
let(:attributes) { {phone_confirmation_token: user.phone_confirmation_token} }
|
35
|
+
|
36
|
+
it "expect failure with error messages" do
|
37
|
+
expect(contract).to be_failure
|
38
|
+
expect(contract.errors[:base]).to include(
|
39
|
+
I18n.t("contracts.errors.custom.default.inactive_account")
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "when phone_confirmation_token is valid" do
|
46
|
+
let(:user) { Factory[:user, :unconfirmed, :with_phone_confirmation_token] }
|
47
|
+
let(:attributes) { {phone_confirmation_token: user.phone_confirmation_token} }
|
48
|
+
|
49
|
+
it "expect return success" do
|
50
|
+
expect(contract).to be_success
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
RSpec.describe AuctionFunCore::Contracts::UserContext::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
|
+
expect(contract.errors[:password]).to include(I18n.t("contracts.errors.key?"))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it_behaves_like "validate_name_contract", :user
|
22
|
+
it_behaves_like "validate_email_contract", :user
|
23
|
+
it_behaves_like "validate_phone_contract", :user
|
24
|
+
it_behaves_like "validate_password_contract", :user
|
25
|
+
it_behaves_like "validate_password_confirmation_contract", :user
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
RSpec.describe AuctionFunCore::Entities::Auction, type: :entity do
|
6
|
+
describe "#initial_bid" do
|
7
|
+
subject(:auction) { Factory.structs[:auction, :default_scheduled_standard] }
|
8
|
+
|
9
|
+
it "expect return initial bid as money object" do
|
10
|
+
expect(auction.initial_bid).to be_a_instance_of(Money)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#minimal_bid" do
|
15
|
+
subject(:auction) { Factory.structs[:auction, :default_scheduled_standard] }
|
16
|
+
|
17
|
+
it "expect return minimal bid as money object" do
|
18
|
+
expect(auction.minimal_bid).to be_a_instance_of(Money)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#winner?" do
|
23
|
+
context "when there is an associated FK" do
|
24
|
+
subject(:auction) { Factory.structs[:auction, :default_finished_standard, :with_winner, winner_id: 1] }
|
25
|
+
|
26
|
+
it "expects to return true when it has a winning user associated." do
|
27
|
+
expect(auction.winner?).to be_truthy
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when there is no associated FK" do
|
32
|
+
subject(:auction) { Factory.structs[:auction, :default_scheduled_standard] }
|
33
|
+
|
34
|
+
it "expect return a user object" do
|
35
|
+
expect(auction.winner?).to be_falsey
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#started?" do
|
41
|
+
context "when an auction has not started" do
|
42
|
+
subject(:auction) { Factory.structs[:auction, :default_scheduled_standard, started_at: 3.hours.from_now] }
|
43
|
+
|
44
|
+
it "expect return false" do
|
45
|
+
expect(auction.started?).to be_falsey
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when an auction was started" do
|
50
|
+
subject(:auction) { Factory.structs[:auction, :default_running_standard, started_at: 1.minute.ago] }
|
51
|
+
|
52
|
+
it "expect return true" do
|
53
|
+
expect(auction.started?).to be_truthy
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#not_started?" do
|
59
|
+
context "when an auction was started" do
|
60
|
+
subject(:auction) { Factory.structs[:auction, :default_running_standard, started_at: 1.minute.ago] }
|
61
|
+
|
62
|
+
it "expect return false" do
|
63
|
+
expect(auction.not_started?).to be_falsey
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "when an auction has not started" do
|
68
|
+
subject(:auction) { Factory.structs[:auction, :default_scheduled_standard, started_at: 3.hours.from_now] }
|
69
|
+
|
70
|
+
it "expect return true" do
|
71
|
+
expect(auction.not_started?).to be_truthy
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
RSpec.describe AuctionFunCore::Entities::Staff, type: :entity do
|
6
|
+
describe "#active?" do
|
7
|
+
subject(:staff) { Factory.structs[:staff] }
|
8
|
+
|
9
|
+
it "expect return true when staff is active" do
|
10
|
+
expect(staff).to be_active
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#inactive?" do
|
15
|
+
subject(:staff) { Factory.structs[:staff, :inactive] }
|
16
|
+
|
17
|
+
it "expect return false when staff is not active" do
|
18
|
+
expect(staff).to be_inactive
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#info" do
|
23
|
+
subject(:staff) { Factory.structs[:staff] }
|
24
|
+
|
25
|
+
it "expect return hash with some staff fields" do
|
26
|
+
expect(staff.info).to eq({
|
27
|
+
active: staff.active,
|
28
|
+
created_at: staff.created_at,
|
29
|
+
email: staff.email,
|
30
|
+
id: staff.id,
|
31
|
+
kind: staff.kind,
|
32
|
+
name: staff.name,
|
33
|
+
phone: staff.phone,
|
34
|
+
updated_at: staff.updated_at
|
35
|
+
})
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
RSpec.describe AuctionFunCore::Entities::User, type: :entity do
|
6
|
+
describe "#active?" do
|
7
|
+
subject(:user) { Factory.structs[:user] }
|
8
|
+
|
9
|
+
it "expect return true when user is active" do
|
10
|
+
expect(user).to be_active
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#inactive?" do
|
15
|
+
subject(:user) { Factory.structs[:user, :inactive] }
|
16
|
+
|
17
|
+
it "expect return false when user is not active" do
|
18
|
+
expect(user).to be_inactive
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#confirmed?" do
|
23
|
+
context "when confirmed_at is present" do
|
24
|
+
subject(:user) { Factory.structs[:user] }
|
25
|
+
|
26
|
+
it "expect return true" do
|
27
|
+
expect(user).to be_confirmed
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when confirmed_at is blank" do
|
32
|
+
subject(:user) { Factory.structs[:user, confirmed_at: nil] }
|
33
|
+
|
34
|
+
it "expect return false" do
|
35
|
+
expect(user).not_to be_confirmed
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#email_confirmed?" do
|
41
|
+
context "when email_confirmation_at is present" do
|
42
|
+
subject(:user) { Factory.structs[:user] }
|
43
|
+
|
44
|
+
it "expect return true" do
|
45
|
+
expect(user).to be_email_confirmed
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when email_confirmation_at is blank" do
|
50
|
+
subject(:user) { Factory.structs[:user, email_confirmation_at: nil] }
|
51
|
+
|
52
|
+
it "expect return false" do
|
53
|
+
expect(user).not_to be_email_confirmed
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#phone_confirmed?" do
|
59
|
+
context "when phone_confirmation_at is present" do
|
60
|
+
subject(:user) { Factory.structs[:user] }
|
61
|
+
|
62
|
+
it "expect return true" do
|
63
|
+
expect(user).to be_phone_confirmed
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "when phone_confirmation_at is blank" do
|
68
|
+
subject(:user) { Factory.structs[:user, phone_confirmation_at: nil] }
|
69
|
+
|
70
|
+
it "expect return false" do
|
71
|
+
expect(user).not_to be_phone_confirmed
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "#info" do
|
77
|
+
subject(:user) { Factory.structs[:user, :with_balance] }
|
78
|
+
|
79
|
+
it "expect return hash with some user fields" do
|
80
|
+
expect(user.info).to eq({
|
81
|
+
active: user.active,
|
82
|
+
balance_cents: user.balance_cents,
|
83
|
+
balance_currency: user.balance_currency,
|
84
|
+
confirmed_at: user.confirmed_at,
|
85
|
+
created_at: user.created_at,
|
86
|
+
email: user.email,
|
87
|
+
email_confirmation_at: user.email_confirmation_at,
|
88
|
+
email_confirmation_token: user.email_confirmation_token,
|
89
|
+
id: user.id,
|
90
|
+
name: user.name,
|
91
|
+
phone: user.phone,
|
92
|
+
phone_confirmation_at: user.phone_confirmation_at,
|
93
|
+
phone_confirmation_token: user.phone_confirmation_token,
|
94
|
+
updated_at: user.updated_at
|
95
|
+
})
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "#balance" do
|
100
|
+
subject(:user) { Factory.structs[:user, :with_balance] }
|
101
|
+
|
102
|
+
it "expect return false when user is not active" do
|
103
|
+
expect(user.balance).to be_a_instance_of(Money)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
RSpec.describe AuctionFunCore::Operations::AuctionContext::CreateOperation, type: :operation do
|
6
|
+
let(:auction_repository) { AuctionFunCore::Repos::AuctionContext::AuctionRepository.new }
|
7
|
+
|
8
|
+
describe ".call(attributes, &block)" do
|
9
|
+
let(:operation) { described_class }
|
10
|
+
|
11
|
+
context "when block is given" do
|
12
|
+
context "when operation happens with success" do
|
13
|
+
let(:staff) { Factory[:staff] }
|
14
|
+
let(:attributes) do
|
15
|
+
Factory.structs[:auction, :default_scheduled_standard, staff: staff]
|
16
|
+
.to_h.except(:id, :created_at, :updated_at, :staff)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "expect result success matching block" do
|
20
|
+
matched_success = nil
|
21
|
+
matched_failure = nil
|
22
|
+
|
23
|
+
operation.call(attributes) do |o|
|
24
|
+
o.success { |v| matched_success = v }
|
25
|
+
o.failure { |f| matched_failure = f }
|
26
|
+
end
|
27
|
+
|
28
|
+
expect(matched_success).to be_a(AuctionFunCore::Entities::Auction)
|
29
|
+
expect(matched_failure).to be_nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when operation happens with failure" do
|
34
|
+
let(:attributes) { Dry::Core::Constants::EMPTY_HASH }
|
35
|
+
|
36
|
+
it "expect result matching block" do
|
37
|
+
matched_success = nil
|
38
|
+
matched_failure = nil
|
39
|
+
|
40
|
+
operation.call(attributes) do |o|
|
41
|
+
o.success { |v| matched_success = v }
|
42
|
+
o.failure { |f| matched_failure = f }
|
43
|
+
end
|
44
|
+
|
45
|
+
expect(matched_success).to be_nil
|
46
|
+
expect(matched_failure[:title]).to include(I18n.t("contracts.errors.key?"))
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#call" do
|
53
|
+
subject(:operation) { described_class.new.call(attributes) }
|
54
|
+
|
55
|
+
context "when contract are invalid" do
|
56
|
+
let(:attributes) { Dry::Core::Constants::EMPTY_HASH }
|
57
|
+
|
58
|
+
it "expect not persist new auction on database" do
|
59
|
+
expect(auction_repository.count).to be_zero
|
60
|
+
|
61
|
+
expect { operation }.not_to change(auction_repository, :count)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "expect return failure with error messages" do
|
65
|
+
expect(operation).to be_failure
|
66
|
+
expect(operation.failure[:title]).to include(I18n.t("contracts.errors.key?"))
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "when contract are valid" do
|
71
|
+
let(:staff) { Factory[:staff] }
|
72
|
+
let(:attributes) do
|
73
|
+
Factory.structs[:auction, :default_scheduled_standard, staff: staff]
|
74
|
+
.to_h.except(:id, :created_at, :updated_at, :staff)
|
75
|
+
end
|
76
|
+
|
77
|
+
before do
|
78
|
+
allow(AuctionFunCore::Application[:event]).to receive(:publish)
|
79
|
+
allow(AuctionFunCore::Workers::Operations::AuctionContext::Processor::StartOperationJob)
|
80
|
+
.to receive(:perform_at)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "expect return success creating auction on database with correct status and dispatch event and processes" do
|
84
|
+
expect { operation }.to change(auction_repository, :count).from(0).to(1)
|
85
|
+
|
86
|
+
expect(operation).to be_success
|
87
|
+
expect(operation.success.status).to eq("scheduled")
|
88
|
+
expect(AuctionFunCore::Application[:event]).to have_received(:publish).once
|
89
|
+
expect(AuctionFunCore::Workers::Operations::AuctionContext::Processor::StartOperationJob)
|
90
|
+
.to have_received(:perform_at)
|
91
|
+
.once
|
92
|
+
end
|
93
|
+
|
94
|
+
context "when the start of the auction is more than 1h from the current time" do
|
95
|
+
before do
|
96
|
+
attributes[:started_at] = 2.hours.from_now
|
97
|
+
allow(AuctionFunCore::Workers::Operations::AuctionContext::PreAuction::AuctionStartReminderOperationJob)
|
98
|
+
.to receive(:perform_at)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "expect schedule reminder notification" do
|
102
|
+
operation
|
103
|
+
|
104
|
+
expect(AuctionFunCore::Workers::Operations::AuctionContext::PreAuction::AuctionStartReminderOperationJob)
|
105
|
+
.to have_received(:perform_at)
|
106
|
+
.once
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context "When the start of the auction is less than 1h from the current time" do
|
111
|
+
before do
|
112
|
+
attributes[:started_at] = 30.minutes.from_now
|
113
|
+
allow(AuctionFunCore::Workers::Operations::AuctionContext::PreAuction::AuctionStartReminderOperationJob)
|
114
|
+
.to receive(:perform_at)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "expect not schedule reminder notification" do
|
118
|
+
operation
|
119
|
+
|
120
|
+
expect(AuctionFunCore::Workers::Operations::AuctionContext::PreAuction::AuctionStartReminderOperationJob)
|
121
|
+
.not_to have_received(:perform_at)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
data/spec/auction_fun_core/operations/auction_context/post_auction/participant_operation_spec.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
RSpec.describe AuctionFunCore::Operations::AuctionContext::PostAuction::ParticipantOperation, type: :operation do
|
6
|
+
let(:auction_repository) { AuctionFunCore::Repos::AuctionContext::AuctionRepository.new }
|
7
|
+
let(:participant) { Factory[:user] }
|
8
|
+
let(:winner) { Factory[:user] }
|
9
|
+
let(:auction) { Factory[:auction, :default_finished_standard, winner_id: winner.id] }
|
10
|
+
|
11
|
+
describe ".call(auction_id, &block)" do
|
12
|
+
let(:operation) { described_class }
|
13
|
+
|
14
|
+
context "when block is given" do
|
15
|
+
context "when operation happens with success" do
|
16
|
+
let(:attributes) { {auction_id: auction.id, participant_id: participant.id} }
|
17
|
+
|
18
|
+
before do
|
19
|
+
Factory[:bid, user_id: winner.id, auction_id: auction.id, value_cents: auction.minimal_bid_cents * 2]
|
20
|
+
Factory[:bid, user_id: participant.id, auction_id: auction.id, value_cents: auction.minimal_bid_cents]
|
21
|
+
end
|
22
|
+
|
23
|
+
it "expect result success matching block" do
|
24
|
+
matched_success = nil
|
25
|
+
matched_failure = nil
|
26
|
+
|
27
|
+
operation.call(attributes) do |o|
|
28
|
+
o.success { |v| matched_success = v }
|
29
|
+
o.failure { |f| matched_failure = f }
|
30
|
+
end
|
31
|
+
|
32
|
+
expect(matched_success).to include(participant)
|
33
|
+
expect(matched_failure).to be_nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "when operation happens with failure" do
|
38
|
+
let(:attributes) { Dry::Core::Constants::EMPTY_HASH }
|
39
|
+
|
40
|
+
it "expect result matching block" do
|
41
|
+
matched_success = nil
|
42
|
+
matched_failure = nil
|
43
|
+
|
44
|
+
operation.call(attributes) do |o|
|
45
|
+
o.success { |v| matched_success = v }
|
46
|
+
o.failure { |f| matched_failure = f }
|
47
|
+
end
|
48
|
+
|
49
|
+
expect(matched_success).to be_nil
|
50
|
+
expect(matched_failure[:auction_id]).to include(I18n.t("contracts.errors.key?"))
|
51
|
+
expect(matched_failure[:participant_id]).to include(I18n.t("contracts.errors.key?"))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#call" do
|
58
|
+
subject(:operation) { described_class.new.call(attributes) }
|
59
|
+
|
60
|
+
context "when contract is invalid" do
|
61
|
+
let(:attributes) { Dry::Core::Constants::EMPTY_HASH }
|
62
|
+
|
63
|
+
it "expect return failure with error messages" do
|
64
|
+
expect(operation.failure[:auction_id]).to include(I18n.t("contracts.errors.key?"))
|
65
|
+
expect(operation.failure[:participant_id]).to include(I18n.t("contracts.errors.key?"))
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "when contract is valid" do
|
70
|
+
let(:attributes) { {auction_id: auction.id, participant_id: participant.id} }
|
71
|
+
|
72
|
+
before do
|
73
|
+
Factory[:bid, user_id: winner.id, auction_id: auction.id, value_cents: auction.minimal_bid_cents * 2]
|
74
|
+
Factory[:bid, user_id: participant.id, auction_id: auction.id, value_cents: auction.minimal_bid_cents]
|
75
|
+
end
|
76
|
+
|
77
|
+
it "expect send winning email with auction statistics and payment instructions" do
|
78
|
+
allow(AuctionFunCore::Workers::Services::Mail::AuctionContext::PostAuction::ParticipantMailerJob)
|
79
|
+
.to receive(:perform_async).with(auction.id, participant.id)
|
80
|
+
|
81
|
+
operation
|
82
|
+
|
83
|
+
expect(AuctionFunCore::Workers::Services::Mail::AuctionContext::PostAuction::ParticipantMailerJob)
|
84
|
+
.to have_received(:perform_async).with(auction.id, participant.id).once
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
RSpec.describe AuctionFunCore::Operations::AuctionContext::PostAuction::WinnerOperation, type: :operation do
|
6
|
+
let(:auction_repository) { AuctionFunCore::Repos::AuctionContext::AuctionRepository.new }
|
7
|
+
let(:winner) { Factory[:user] }
|
8
|
+
let(:auction) { Factory[:auction, :default_finished_standard, winner_id: winner.id] }
|
9
|
+
|
10
|
+
describe ".call(auction_id, &block)" do
|
11
|
+
let(:operation) { described_class }
|
12
|
+
|
13
|
+
context "when block is given" do
|
14
|
+
context "when operation happens with success" do
|
15
|
+
let(:attributes) { {auction_id: auction.id, winner_id: winner.id} }
|
16
|
+
it "expect result success matching block" do
|
17
|
+
matched_success = nil
|
18
|
+
matched_failure = nil
|
19
|
+
|
20
|
+
operation.call(attributes) do |o|
|
21
|
+
o.success { |v| matched_success = v }
|
22
|
+
o.failure { |f| matched_failure = f }
|
23
|
+
end
|
24
|
+
|
25
|
+
expect(matched_success).to include(winner)
|
26
|
+
expect(matched_failure).to be_nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when operation happens with failure" do
|
31
|
+
let(:attributes) { Dry::Core::Constants::EMPTY_HASH }
|
32
|
+
|
33
|
+
it "expect result matching block" do
|
34
|
+
matched_success = nil
|
35
|
+
matched_failure = nil
|
36
|
+
|
37
|
+
operation.call(attributes) do |o|
|
38
|
+
o.success { |v| matched_success = v }
|
39
|
+
o.failure { |f| matched_failure = f }
|
40
|
+
end
|
41
|
+
|
42
|
+
expect(matched_success).to be_nil
|
43
|
+
expect(matched_failure[:auction_id]).to include(I18n.t("contracts.errors.key?"))
|
44
|
+
expect(matched_failure[:winner_id]).to include(I18n.t("contracts.errors.key?"))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#call" do
|
51
|
+
subject(:operation) { described_class.new.call(attributes) }
|
52
|
+
|
53
|
+
context "when contract is invalid" do
|
54
|
+
let(:attributes) { Dry::Core::Constants::EMPTY_HASH }
|
55
|
+
|
56
|
+
it "expect return failure with error messages" do
|
57
|
+
expect(operation.failure[:auction_id]).to include(I18n.t("contracts.errors.key?"))
|
58
|
+
expect(operation.failure[:winner_id]).to include(I18n.t("contracts.errors.key?"))
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "when contract is valid" do
|
63
|
+
let(:attributes) { {auction_id: auction.id, winner_id: winner.id} }
|
64
|
+
|
65
|
+
it "expect send winning email with auction statistics and payment instructions" do
|
66
|
+
allow(AuctionFunCore::Workers::Services::Mail::AuctionContext::PostAuction::WinnerMailerJob)
|
67
|
+
.to receive(:perform_async).with(auction.id, winner.id)
|
68
|
+
|
69
|
+
operation
|
70
|
+
|
71
|
+
expect(AuctionFunCore::Workers::Services::Mail::AuctionContext::PostAuction::WinnerMailerJob)
|
72
|
+
.to have_received(:perform_async).with(auction.id, winner.id).once
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|