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
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe AuctionFunCore::Operations::AuctionContext::PreAuction::AuctionStartReminderOperation, type: :operation do
|
|
6
|
+
describe ".call(attributes, &block)" do
|
|
7
|
+
let(:operation) { described_class }
|
|
8
|
+
|
|
9
|
+
context "when block is given" do
|
|
10
|
+
context "when operation happens with success" do
|
|
11
|
+
let(:auction) { Factory[:auction, :default_scheduled_standard, started_at: 3.hours.from_now] }
|
|
12
|
+
let(:participant) { Factory[:user] }
|
|
13
|
+
let(:attributes) { {auction_id: auction.id} }
|
|
14
|
+
|
|
15
|
+
before do
|
|
16
|
+
Factory[:bid, user_id: participant.id, auction_id: auction.id, value_cents: auction.minimal_bid_cents]
|
|
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 include([participant.id])
|
|
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[:auction_id]).to include(I18n.t("contracts.errors.key?"))
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
describe "#call(attributes)" do
|
|
53
|
+
subject(:operation) { described_class.new.call(attributes) }
|
|
54
|
+
|
|
55
|
+
context "when contract is invalid" do
|
|
56
|
+
let(:attributes) { Dry::Core::Constants::EMPTY_HASH }
|
|
57
|
+
|
|
58
|
+
it "expect return failure with error messages" do
|
|
59
|
+
expect(operation.failure[:auction_id]).to include(I18n.t("contracts.errors.key?"))
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
context "when contract is valid" do
|
|
64
|
+
let(:auction) { Factory[:auction, :default_scheduled_standard, started_at: 3.hours.from_now] }
|
|
65
|
+
let(:attributes) { {auction_id: auction.id} }
|
|
66
|
+
|
|
67
|
+
context "when the auction has no participants" do
|
|
68
|
+
it "expect not to schedule a reminder email to the participant" do
|
|
69
|
+
allow(AuctionFunCore::Workers::Services::Mail::AuctionContext::PreAuction::AuctionStartReminderMailerJob)
|
|
70
|
+
.to receive(:perform_async)
|
|
71
|
+
|
|
72
|
+
operation
|
|
73
|
+
|
|
74
|
+
expect(AuctionFunCore::Workers::Services::Mail::AuctionContext::PreAuction::AuctionStartReminderMailerJob)
|
|
75
|
+
.not_to have_received(:perform_async)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
context "when the auction has participants" do
|
|
80
|
+
let(:participant) { Factory[:user] }
|
|
81
|
+
|
|
82
|
+
before do
|
|
83
|
+
Factory[:bid, user_id: participant.id, auction_id: auction.id, value_cents: auction.minimal_bid_cents]
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it "expects to schedule a reminder email to the participant" do
|
|
87
|
+
allow(AuctionFunCore::Workers::Services::Mail::AuctionContext::PreAuction::AuctionStartReminderMailerJob)
|
|
88
|
+
.to receive(:perform_async).with(auction.id, participant.id)
|
|
89
|
+
|
|
90
|
+
operation
|
|
91
|
+
|
|
92
|
+
expect(AuctionFunCore::Workers::Services::Mail::AuctionContext::PreAuction::AuctionStartReminderMailerJob)
|
|
93
|
+
.to have_received(:perform_async).with(auction.id, participant.id).once
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
data/spec/auction_fun_core/operations/auction_context/processor/finish/closed_operation_spec.rb
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe AuctionFunCore::Operations::AuctionContext::Processor::Finish::ClosedOperation, type: :operation do
|
|
6
|
+
let(:auction_repository) { AuctionFunCore::Repos::AuctionContext::AuctionRepository.new }
|
|
7
|
+
let(:auction) { Factory[:auction, :default_running_closed, finished_at: Time.current] }
|
|
8
|
+
|
|
9
|
+
describe ".call(auction_id, &block)" do
|
|
10
|
+
let(:operation) { described_class }
|
|
11
|
+
|
|
12
|
+
context "when block is given" do
|
|
13
|
+
context "when operation happens with success" do
|
|
14
|
+
let(:attributes) { {auction_id: auction.id} }
|
|
15
|
+
it "expect result success matching block" do
|
|
16
|
+
matched_success = nil
|
|
17
|
+
matched_failure = nil
|
|
18
|
+
|
|
19
|
+
operation.call(attributes) do |o|
|
|
20
|
+
o.success { |v| matched_success = v }
|
|
21
|
+
o.failure { |f| matched_failure = f }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
expect(matched_success.id).to eq(auction.id)
|
|
25
|
+
expect(matched_success.status).to eq("finished")
|
|
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
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
describe "#call" do
|
|
50
|
+
subject(:operation) { described_class.new.call(attributes) }
|
|
51
|
+
|
|
52
|
+
context "when contract is invalid" do
|
|
53
|
+
let(:attributes) { Dry::Core::Constants::EMPTY_HASH }
|
|
54
|
+
|
|
55
|
+
it "expect not change auction status" do
|
|
56
|
+
expect { operation }.not_to change { auction_repository.by_id(auction.id).status }
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "expect return failure with error messages" do
|
|
60
|
+
expect(operation.failure[:auction_id]).to include(I18n.t("contracts.errors.key?"))
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
context "when contract is valid" do
|
|
65
|
+
let(:attributes) { {auction_id: auction.id} }
|
|
66
|
+
|
|
67
|
+
it "expect update status auction record on database" do
|
|
68
|
+
expect { operation }
|
|
69
|
+
.to change { auction_repository.by_id(auction.id).status }
|
|
70
|
+
.from("running")
|
|
71
|
+
.to("finished")
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "expect publish the auction finish event" do
|
|
75
|
+
allow(AuctionFunCore::Application[:event]).to receive(:publish)
|
|
76
|
+
|
|
77
|
+
operation
|
|
78
|
+
|
|
79
|
+
expect(AuctionFunCore::Application[:event]).to have_received(:publish).once
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
context "when the auction has a winning bid with other participations" do
|
|
83
|
+
let(:participant) { Factory[:user] }
|
|
84
|
+
let(:winner) { Factory[:user] }
|
|
85
|
+
|
|
86
|
+
before do
|
|
87
|
+
Factory[:bid, auction: auction, user: winner, value_cents: (auction.minimal_bid_cents * 2)]
|
|
88
|
+
Factory[:bid, auction: auction, user: participant, value_cents: auction.minimal_bid_cents]
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "expect call winner operation and participant operation jobs" do
|
|
92
|
+
allow(AuctionFunCore::Workers::Operations::AuctionContext::PostAuction::WinnerOperationJob)
|
|
93
|
+
.to receive(:perform_async).with(auction.id, winner.id)
|
|
94
|
+
allow(AuctionFunCore::Workers::Operations::AuctionContext::PostAuction::ParticipantOperationJob)
|
|
95
|
+
.to receive(:perform_async).with(auction.id, participant.id)
|
|
96
|
+
|
|
97
|
+
operation
|
|
98
|
+
|
|
99
|
+
expect(AuctionFunCore::Workers::Operations::AuctionContext::PostAuction::WinnerOperationJob)
|
|
100
|
+
.to have_received(:perform_async).with(auction.id, winner.id).once
|
|
101
|
+
expect(AuctionFunCore::Workers::Operations::AuctionContext::PostAuction::ParticipantOperationJob)
|
|
102
|
+
.to have_received(:perform_async).with(auction.id, participant.id).once
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
data/spec/auction_fun_core/operations/auction_context/processor/finish/penny_operation_spec.rb
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe AuctionFunCore::Operations::AuctionContext::Processor::Finish::PennyOperation, type: :operation do
|
|
6
|
+
let(:auction_repository) { AuctionFunCore::Repos::AuctionContext::AuctionRepository.new }
|
|
7
|
+
let(:auction) { Factory[:auction, :default_running_penny, finished_at: Time.current] }
|
|
8
|
+
|
|
9
|
+
describe ".call(auction_id, &block)" do
|
|
10
|
+
let(:operation) { described_class }
|
|
11
|
+
|
|
12
|
+
context "when block is given" do
|
|
13
|
+
context "when operation happens with success" do
|
|
14
|
+
let(:attributes) { {auction_id: auction.id} }
|
|
15
|
+
it "expect result success matching block" do
|
|
16
|
+
matched_success = nil
|
|
17
|
+
matched_failure = nil
|
|
18
|
+
|
|
19
|
+
operation.call(attributes) do |o|
|
|
20
|
+
o.success { |v| matched_success = v }
|
|
21
|
+
o.failure { |f| matched_failure = f }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
expect(matched_success.id).to eq(auction.id)
|
|
25
|
+
expect(matched_success.status).to eq("finished")
|
|
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
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
describe "#call" do
|
|
50
|
+
subject(:operation) { described_class.new.call(attributes) }
|
|
51
|
+
|
|
52
|
+
context "when contract is invalid" do
|
|
53
|
+
let(:attributes) { Dry::Core::Constants::EMPTY_HASH }
|
|
54
|
+
|
|
55
|
+
it "expect not change auction status" do
|
|
56
|
+
expect { operation }.not_to change { auction_repository.by_id(auction.id).status }
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "expect return failure with error messages" do
|
|
60
|
+
expect(operation.failure[:auction_id]).to include(I18n.t("contracts.errors.key?"))
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
context "when contract is valid" do
|
|
65
|
+
let(:attributes) { {auction_id: auction.id} }
|
|
66
|
+
|
|
67
|
+
it "expect update status auction record on database" do
|
|
68
|
+
expect { operation }
|
|
69
|
+
.to change { auction_repository.by_id(auction.id).status }
|
|
70
|
+
.from("running")
|
|
71
|
+
.to("finished")
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "expect publish the auction finish event" do
|
|
75
|
+
allow(AuctionFunCore::Application[:event]).to receive(:publish)
|
|
76
|
+
|
|
77
|
+
operation
|
|
78
|
+
|
|
79
|
+
expect(AuctionFunCore::Application[:event]).to have_received(:publish).once
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
context "when the auction has a winning bid with other participations" do
|
|
83
|
+
let(:participant) { Factory[:user] }
|
|
84
|
+
let(:winner) { Factory[:user] }
|
|
85
|
+
|
|
86
|
+
before do
|
|
87
|
+
Factory[:bid, auction: auction, user: participant, value_cents: auction.minimal_bid_cents]
|
|
88
|
+
Factory[:bid, auction: auction, user: winner, value_cents: auction.minimal_bid_cents]
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "expect call winner operation and participant operation jobs" do
|
|
92
|
+
allow(AuctionFunCore::Workers::Operations::AuctionContext::PostAuction::WinnerOperationJob)
|
|
93
|
+
.to receive(:perform_async).with(auction.id, winner.id)
|
|
94
|
+
allow(AuctionFunCore::Workers::Operations::AuctionContext::PostAuction::ParticipantOperationJob)
|
|
95
|
+
.to receive(:perform_async).with(auction.id, participant.id)
|
|
96
|
+
|
|
97
|
+
operation
|
|
98
|
+
|
|
99
|
+
expect(AuctionFunCore::Workers::Operations::AuctionContext::PostAuction::WinnerOperationJob)
|
|
100
|
+
.to have_received(:perform_async).with(auction.id, winner.id).once
|
|
101
|
+
expect(AuctionFunCore::Workers::Operations::AuctionContext::PostAuction::ParticipantOperationJob)
|
|
102
|
+
.to have_received(:perform_async).with(auction.id, participant.id).once
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
data/spec/auction_fun_core/operations/auction_context/processor/finish/standard_operation_spec.rb
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe AuctionFunCore::Operations::AuctionContext::Processor::Finish::StandardOperation, type: :operation do
|
|
6
|
+
let(:auction_repository) { AuctionFunCore::Repos::AuctionContext::AuctionRepository.new }
|
|
7
|
+
let(:auction) { Factory[:auction, :default_running_standard, finished_at: Time.current] }
|
|
8
|
+
|
|
9
|
+
describe ".call(auction_id, &block)" do
|
|
10
|
+
let(:operation) { described_class }
|
|
11
|
+
|
|
12
|
+
context "when block is given" do
|
|
13
|
+
context "when operation happens with success" do
|
|
14
|
+
let(:attributes) { {auction_id: auction.id} }
|
|
15
|
+
it "expect result success matching block" do
|
|
16
|
+
matched_success = nil
|
|
17
|
+
matched_failure = nil
|
|
18
|
+
|
|
19
|
+
operation.call(attributes) do |o|
|
|
20
|
+
o.success { |v| matched_success = v }
|
|
21
|
+
o.failure { |f| matched_failure = f }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
expect(matched_success.id).to eq(auction.id)
|
|
25
|
+
expect(matched_success.status).to eq("finished")
|
|
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
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
describe "#call" do
|
|
50
|
+
subject(:operation) { described_class.new.call(attributes) }
|
|
51
|
+
|
|
52
|
+
context "when contract is invalid" do
|
|
53
|
+
let(:attributes) { Dry::Core::Constants::EMPTY_HASH }
|
|
54
|
+
|
|
55
|
+
it "expect not change auction status" do
|
|
56
|
+
expect { operation }.not_to change { auction_repository.by_id(auction.id).status }
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "expect return failure with error messages" do
|
|
60
|
+
expect(operation.failure[:auction_id]).to include(I18n.t("contracts.errors.key?"))
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
context "when contract is valid" do
|
|
65
|
+
let(:attributes) { {auction_id: auction.id} }
|
|
66
|
+
|
|
67
|
+
it "expect update status auction record on database" do
|
|
68
|
+
expect { operation }
|
|
69
|
+
.to change { auction_repository.by_id(auction.id).status }
|
|
70
|
+
.from("running")
|
|
71
|
+
.to("finished")
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "expect publish the auction finish event" do
|
|
75
|
+
allow(AuctionFunCore::Application[:event]).to receive(:publish)
|
|
76
|
+
|
|
77
|
+
operation
|
|
78
|
+
|
|
79
|
+
expect(AuctionFunCore::Application[:event]).to have_received(:publish).once
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
context "when the auction has a winning bid with other participations" do
|
|
83
|
+
let(:winner) { Factory[:user] }
|
|
84
|
+
|
|
85
|
+
before do
|
|
86
|
+
Factory[:bid, auction: auction, value_cents: auction.minimal_bid_cents]
|
|
87
|
+
Factory[:bid, auction: auction, user: winner, value_cents: (auction.minimal_bid_cents * 2)]
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it "expect call winner operation and participant operation jobs" do
|
|
91
|
+
allow(AuctionFunCore::Workers::Operations::AuctionContext::PostAuction::WinnerOperationJob)
|
|
92
|
+
.to receive(:perform_async)
|
|
93
|
+
allow(AuctionFunCore::Workers::Operations::AuctionContext::PostAuction::ParticipantOperationJob)
|
|
94
|
+
.to receive(:perform_async)
|
|
95
|
+
|
|
96
|
+
operation
|
|
97
|
+
|
|
98
|
+
expect(AuctionFunCore::Workers::Operations::AuctionContext::PostAuction::WinnerOperationJob)
|
|
99
|
+
.to have_received(:perform_async).once
|
|
100
|
+
expect(AuctionFunCore::Workers::Operations::AuctionContext::PostAuction::ParticipantOperationJob)
|
|
101
|
+
.to have_received(:perform_async).once
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe AuctionFunCore::Operations::AuctionContext::Processor::PauseOperation, type: :operation do
|
|
6
|
+
let(:auction_repository) { AuctionFunCore::Repos::AuctionContext::AuctionRepository.new }
|
|
7
|
+
let(:auction) { Factory[:auction, :default_running_standard] }
|
|
8
|
+
|
|
9
|
+
describe ".call(attributes, &block)" do
|
|
10
|
+
let(:operation) { described_class }
|
|
11
|
+
|
|
12
|
+
context "when block is given" do
|
|
13
|
+
context "when operation happens with success" do
|
|
14
|
+
let(:attributes) { {auction_id: auction.id} }
|
|
15
|
+
|
|
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 eq(auction.id)
|
|
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
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
describe "#call(attributes)" do
|
|
50
|
+
subject(:operation) { described_class.new.call(attributes) }
|
|
51
|
+
|
|
52
|
+
context "when contract is invalid" do
|
|
53
|
+
let(:attributes) { Dry::Core::Constants::EMPTY_HASH }
|
|
54
|
+
|
|
55
|
+
it "expect not change auction status" do
|
|
56
|
+
expect { operation }.not_to change { auction_repository.by_id(auction.id).status }
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "expect return failure with error messages" do
|
|
60
|
+
expect(operation.failure[:auction_id]).to include(I18n.t("contracts.errors.key?"))
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
context "when contract is valid" do
|
|
65
|
+
let(:attributes) { {auction_id: auction.id} }
|
|
66
|
+
|
|
67
|
+
it "expect update status auction record on database" do
|
|
68
|
+
expect { operation }
|
|
69
|
+
.to change { auction_repository.by_id(auction.id).status }
|
|
70
|
+
.from("running")
|
|
71
|
+
.to("paused")
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "expect publish the auction pause event" do
|
|
75
|
+
allow(AuctionFunCore::Application[:event]).to receive(:publish)
|
|
76
|
+
|
|
77
|
+
operation
|
|
78
|
+
|
|
79
|
+
expect(AuctionFunCore::Application[:event]).to have_received(:publish).once
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe AuctionFunCore::Operations::AuctionContext::Processor::StartOperation, type: :operation do
|
|
6
|
+
let(:auction_repository) { AuctionFunCore::Repos::AuctionContext::AuctionRepository.new }
|
|
7
|
+
let(:auction) { Factory[:auction, :default_scheduled_standard, started_at: Time.current] }
|
|
8
|
+
let(:auction_id) { auction.id }
|
|
9
|
+
let(:kind) { auction.kind }
|
|
10
|
+
let(:stopwatch) { 0 }
|
|
11
|
+
|
|
12
|
+
describe ".call(attributes, &block)" do
|
|
13
|
+
let(:operation) { described_class }
|
|
14
|
+
|
|
15
|
+
context "when block is given" do
|
|
16
|
+
context "when operation happens with success" do
|
|
17
|
+
let(:attributes) do
|
|
18
|
+
{
|
|
19
|
+
auction_id: auction.id,
|
|
20
|
+
kind: auction.kind,
|
|
21
|
+
stopwatch: auction.stopwatch
|
|
22
|
+
}
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "expect result success matching block" do
|
|
26
|
+
matched_success = nil
|
|
27
|
+
matched_failure = nil
|
|
28
|
+
|
|
29
|
+
operation.call(attributes) do |o|
|
|
30
|
+
o.success { |v| matched_success = v }
|
|
31
|
+
o.failure { |f| matched_failure = f }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
expect(matched_success.id).to eq(auction.id)
|
|
35
|
+
expect(matched_success.status).to eq("running")
|
|
36
|
+
expect(matched_failure).to be_nil
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
context "when operation happens with failure" do
|
|
41
|
+
let(:attributes) { Dry::Core::Constants::EMPTY_HASH }
|
|
42
|
+
|
|
43
|
+
it "expect result matching block" do
|
|
44
|
+
matched_success = nil
|
|
45
|
+
matched_failure = nil
|
|
46
|
+
|
|
47
|
+
operation.call(attributes) do |o|
|
|
48
|
+
o.success { |v| matched_success = v }
|
|
49
|
+
o.failure { |f| matched_failure = f }
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
expect(matched_success).to be_nil
|
|
53
|
+
expect(matched_failure[:auction_id]).to include(I18n.t("contracts.errors.key?"))
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe "#call" do
|
|
60
|
+
subject(:operation) { described_class.new.call(attributes) }
|
|
61
|
+
|
|
62
|
+
context "when contract is invalid" do
|
|
63
|
+
let(:attributes) { Dry::Core::Constants::EMPTY_HASH }
|
|
64
|
+
|
|
65
|
+
it "expect not change auction status" do
|
|
66
|
+
expect { operation }.not_to change { auction_repository.by_id(auction.id).status }
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
context "when contract is valid" do
|
|
71
|
+
let(:attributes) do
|
|
72
|
+
{
|
|
73
|
+
auction_id: auction.id,
|
|
74
|
+
kind: auction.kind,
|
|
75
|
+
stopwatch: auction.stopwatch
|
|
76
|
+
}
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "expect update status auction record on database and publish the auction start event" do
|
|
80
|
+
allow(AuctionFunCore::Application[:event]).to receive(:publish)
|
|
81
|
+
|
|
82
|
+
expect { operation }.to change { auction_repository.by_id(auction.id).status }.from("scheduled").to("running")
|
|
83
|
+
|
|
84
|
+
expect(AuctionFunCore::Application[:event]).to have_received(:publish).once
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
context "when auction kind is equal to 'standard'" do
|
|
88
|
+
it "expect create a new job to finish the standard auction" do
|
|
89
|
+
allow(AuctionFunCore::Workers::Operations::AuctionContext::Processor::Finish::StandardOperationJob).to receive(:perform_at)
|
|
90
|
+
|
|
91
|
+
operation
|
|
92
|
+
|
|
93
|
+
expect(AuctionFunCore::Workers::Operations::AuctionContext::Processor::Finish::StandardOperationJob)
|
|
94
|
+
.to have_received(:perform_at)
|
|
95
|
+
.once
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
context "when auction kind is equal to 'closed'" do
|
|
100
|
+
let(:auction) { Factory[:auction, :default_scheduled_closed, started_at: Time.current] }
|
|
101
|
+
|
|
102
|
+
it "expect create a new job to finish the closed auction" do
|
|
103
|
+
allow(AuctionFunCore::Workers::Operations::AuctionContext::Processor::Finish::ClosedOperationJob).to receive(:perform_at)
|
|
104
|
+
|
|
105
|
+
operation
|
|
106
|
+
|
|
107
|
+
expect(AuctionFunCore::Workers::Operations::AuctionContext::Processor::Finish::ClosedOperationJob)
|
|
108
|
+
.to have_received(:perform_at)
|
|
109
|
+
.once
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
context "when auction kind is equal to 'penny'" do
|
|
114
|
+
let(:auction) { Factory[:auction, :default_scheduled_closed, started_at: Time.current] }
|
|
115
|
+
let(:stopwatch) { 45 }
|
|
116
|
+
let(:old_finished_at) { auction.finished_at.strftime("%Y-%m-%d %H:%M:%S") }
|
|
117
|
+
let(:new_finished_at) { stopwatch.seconds.from_now.strftime("%Y-%m-%d %H:%M:%S") }
|
|
118
|
+
let(:attributes) do
|
|
119
|
+
{
|
|
120
|
+
auction_id: auction.id,
|
|
121
|
+
kind: "penny",
|
|
122
|
+
stopwatch: stopwatch
|
|
123
|
+
}
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
before { auction_repository.update(auction.id, kind: "penny") }
|
|
127
|
+
|
|
128
|
+
it "expect update finished_at to stopwatch seconds from now" do
|
|
129
|
+
expect { operation }
|
|
130
|
+
.to change { auction_repository.by_id(auction.id).finished_at.strftime("%Y-%m-%d %H:%M:%S") }
|
|
131
|
+
.from(old_finished_at)
|
|
132
|
+
.to(new_finished_at)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it "expect call the finish penny auction job" do
|
|
136
|
+
allow(AuctionFunCore::Workers::Operations::AuctionContext::Processor::Finish::PennyOperationJob)
|
|
137
|
+
.to receive(:perform_at)
|
|
138
|
+
|
|
139
|
+
operation
|
|
140
|
+
|
|
141
|
+
expect(AuctionFunCore::Workers::Operations::AuctionContext::Processor::Finish::PennyOperationJob)
|
|
142
|
+
.to have_received(:perform_at)
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|