auction_fun_core 0.8.9 → 0.8.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/auction_fun_core.gemspec +1 -1
  4. data/lib/auction_fun_core/version.rb +1 -1
  5. data/spec/auction_fun_core/contracts/auction_context/create_contract_spec.rb +158 -0
  6. data/spec/auction_fun_core/contracts/auction_context/post_auction/participant_contract_spec.rb +77 -0
  7. data/spec/auction_fun_core/contracts/auction_context/post_auction/winner_contract_spec.rb +76 -0
  8. data/spec/auction_fun_core/contracts/auction_context/pre_auction/auction_start_reminder_contract_spec.rb +48 -0
  9. data/spec/auction_fun_core/contracts/auction_context/processor/finish/closed_contract_spec.rb +59 -0
  10. data/spec/auction_fun_core/contracts/auction_context/processor/finish/penny_contract_spec.rb +59 -0
  11. data/spec/auction_fun_core/contracts/auction_context/processor/finish/standard_contract_spec.rb +59 -0
  12. data/spec/auction_fun_core/contracts/auction_context/processor/pause_contract_spec.rb +39 -0
  13. data/spec/auction_fun_core/contracts/auction_context/processor/start_contract_spec.rb +59 -0
  14. data/spec/auction_fun_core/contracts/auction_context/processor/unpause_contract_spec.rb +39 -0
  15. data/spec/auction_fun_core/contracts/bid_context/create_bid_closed_contract_spec.rb +130 -0
  16. data/spec/auction_fun_core/contracts/bid_context/create_bid_penny_contract_spec.rb +118 -0
  17. data/spec/auction_fun_core/contracts/bid_context/create_bid_standard_contract_spec.rb +154 -0
  18. data/spec/auction_fun_core/contracts/staff_context/authentication_contract_spec.rb +89 -0
  19. data/spec/auction_fun_core/contracts/staff_context/registration_contract_spec.rb +24 -0
  20. data/spec/auction_fun_core/contracts/user_context/authentication_contract_spec.rb +89 -0
  21. data/spec/auction_fun_core/contracts/user_context/email_confirmation_contract_spec.rb +54 -0
  22. data/spec/auction_fun_core/contracts/user_context/phone_confirmation_contract_spec.rb +54 -0
  23. data/spec/auction_fun_core/contracts/user_context/registration_contract_spec.rb +27 -0
  24. data/spec/auction_fun_core/entities/auction_spec.rb +75 -0
  25. data/spec/auction_fun_core/entities/bid_spec.rb +7 -0
  26. data/spec/auction_fun_core/entities/staff_spec.rb +38 -0
  27. data/spec/auction_fun_core/entities/user_spec.rb +106 -0
  28. data/spec/auction_fun_core/operations/auction_context/create_operation_spec.rb +126 -0
  29. data/spec/auction_fun_core/operations/auction_context/post_auction/participant_operation_spec.rb +88 -0
  30. data/spec/auction_fun_core/operations/auction_context/post_auction/winner_operation_spec.rb +76 -0
  31. data/spec/auction_fun_core/operations/auction_context/pre_auction/auction_start_reminder_operation_spec.rb +98 -0
  32. data/spec/auction_fun_core/operations/auction_context/processor/finish/closed_operation_spec.rb +107 -0
  33. data/spec/auction_fun_core/operations/auction_context/processor/finish/penny_operation_spec.rb +107 -0
  34. data/spec/auction_fun_core/operations/auction_context/processor/finish/standard_operation_spec.rb +106 -0
  35. data/spec/auction_fun_core/operations/auction_context/processor/pause_operation_spec.rb +83 -0
  36. data/spec/auction_fun_core/operations/auction_context/processor/start_operation_spec.rb +147 -0
  37. data/spec/auction_fun_core/operations/auction_context/processor/unpause_operation_spec.rb +80 -0
  38. data/spec/auction_fun_core/operations/bid_context/create_bid_closed_operation_spec.rb +95 -0
  39. data/spec/auction_fun_core/operations/bid_context/create_bid_penny_operation_spec.rb +133 -0
  40. data/spec/auction_fun_core/operations/bid_context/create_bid_standard_operation_spec.rb +95 -0
  41. data/spec/auction_fun_core/operations/staff_context/authentication_operation_spec.rb +74 -0
  42. data/spec/auction_fun_core/operations/staff_context/registration_operation_spec.rb +93 -0
  43. data/spec/auction_fun_core/operations/user_context/authentication_operation_spec.rb +74 -0
  44. data/spec/auction_fun_core/operations/user_context/email_confirmation_operation_spec.rb +76 -0
  45. data/spec/auction_fun_core/operations/user_context/phone_confirmation_operation_spec.rb +76 -0
  46. data/spec/auction_fun_core/operations/user_context/registration_operation_spec.rb +100 -0
  47. data/spec/auction_fun_core/relations/auctions_spec.rb +471 -0
  48. data/spec/auction_fun_core/repos/auction_context/auction_repository_spec.rb +64 -0
  49. data/spec/auction_fun_core/repos/bid_context/bid_repository_spec.rb +64 -0
  50. data/spec/auction_fun_core/repos/staff_context/staff_repository_spec.rb +118 -0
  51. data/spec/auction_fun_core/repos/user_context/user_repository_spec.rb +117 -0
  52. data/spec/auction_fun_core/services/mail/auction_context/post_auction/participant_mailer_spec.rb +48 -0
  53. data/spec/auction_fun_core/services/mail/auction_context/post_auction/winner_mailer_spec.rb +48 -0
  54. data/spec/auction_fun_core/services/mail/auction_context/pre_auction/auction_start_reminder_mailer_spec.rb +40 -0
  55. data/spec/auction_fun_core/services/mail/user_context/registration_mailer_spec.rb +33 -0
  56. data/spec/auction_fun_core/workers/operations/auction_context/post_auction/participation_operation_job_spec.rb +54 -0
  57. data/spec/auction_fun_core/workers/operations/auction_context/post_auction/winner_operation_job_spec.rb +48 -0
  58. data/spec/auction_fun_core/workers/operations/auction_context/pre_auction/auction_start_reminder_operation_job_spec.rb +53 -0
  59. data/spec/auction_fun_core/workers/operations/auction_context/processor/finish/closed_operation_job_spec.rb +47 -0
  60. data/spec/auction_fun_core/workers/operations/auction_context/processor/finish/penny_operation_job_spec.rb +47 -0
  61. data/spec/auction_fun_core/workers/operations/auction_context/processor/finish/standard_operation_job_spec.rb +47 -0
  62. data/spec/auction_fun_core/workers/operations/auction_context/processor/start_operation_job_spec.rb +47 -0
  63. data/spec/auction_fun_core/workers/services/mail/auction_context/post_auction/participant_mailer_job_spec.rb +62 -0
  64. data/spec/auction_fun_core/workers/services/mail/auction_context/post_auction/pre_auction/auction_start_reminder_mailer_job_spec.rb +59 -0
  65. data/spec/auction_fun_core/workers/services/mail/auction_context/post_auction/winner_mailer_job_spec.rb +62 -0
  66. data/spec/auction_fun_core/workers/services/mail/user_context/registration_mailer_job_spec.rb +53 -0
  67. data/spec/auction_fun_core_spec.rb +7 -0
  68. data/spec/spec_helper.rb +61 -0
  69. data/spec/support/background_job.rb +7 -0
  70. data/spec/support/factories/auctions.rb +143 -0
  71. data/spec/support/factories/bids.rb +6 -0
  72. data/spec/support/factories/staffs.rb +18 -0
  73. data/spec/support/factories/users.rb +43 -0
  74. data/spec/support/faker.rb +6 -0
  75. data/spec/support/mail.rb +13 -0
  76. data/spec/support/shared_examples/validate_email_contract.rb +25 -0
  77. data/spec/support/shared_examples/validate_name_contract.rb +19 -0
  78. data/spec/support/shared_examples/validate_password_confirmation_contract.rb +16 -0
  79. data/spec/support/shared_examples/validate_password_contract.rb +18 -0
  80. data/spec/support/shared_examples/validate_phone_contract.rb +25 -0
  81. data/spec/support/shared_examples/validate_stopwatch_contract.rb +32 -0
  82. metadata +79 -2
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe AuctionFunCore::Repos::StaffContext::StaffRepository, type: :repo do
6
+ subject(:repo) { described_class.new }
7
+
8
+ describe "#create" do
9
+ let(:attributes) { Factory.structs[:staff] }
10
+
11
+ let(:staff) do
12
+ repo.create(
13
+ name: attributes.name,
14
+ email: attributes.email,
15
+ phone: attributes.phone,
16
+ kind: "common",
17
+ password_digest: BCrypt::Password.create("password")
18
+ )
19
+ end
20
+
21
+ it "expect create a new auction on repository" do
22
+ expect(staff).to be_a(AuctionFunCore::Entities::Staff)
23
+ expect(staff.name).to eq(attributes.name)
24
+ expect(staff.email).to eq(attributes.email)
25
+ expect(staff.phone).to eq(attributes.phone)
26
+ expect(staff.password_digest).to be_present
27
+ expect(staff.created_at).not_to be_blank
28
+ expect(staff.updated_at).not_to be_blank
29
+ end
30
+ end
31
+
32
+ describe "#update" do
33
+ let(:staff) { Factory[:staff] }
34
+ let(:new_name) { "New name" }
35
+
36
+ it "expect update staff on repository" do
37
+ expect { repo.update(staff.id, name: new_name) }
38
+ .to change { repo.by_id(staff.id).name }
39
+ .from(staff.name)
40
+ .to(new_name)
41
+ end
42
+ end
43
+
44
+ describe "#delete" do
45
+ let!(:staff) { Factory[:staff] }
46
+
47
+ it "expect remove staff on repository" do
48
+ expect { repo.delete(staff.id) }
49
+ .to change(repo, :count)
50
+ .from(1).to(0)
51
+ end
52
+ end
53
+
54
+ describe "#all" do
55
+ let!(:staff) { Factory[:staff] }
56
+
57
+ it "expect return all staffs" do
58
+ expect(repo.all.size).to eq(1)
59
+ expect(repo.all.first.id).to eq(staff.id)
60
+ end
61
+ end
62
+
63
+ describe "#count" do
64
+ context "when has not staff on repository" do
65
+ it "expect return zero" do
66
+ expect(repo.count).to be_zero
67
+ end
68
+ end
69
+
70
+ context "when has staffs on repository" do
71
+ let!(:auction) { Factory[:staff] }
72
+
73
+ it "expect return total" do
74
+ expect(repo.count).to eq(1)
75
+ end
76
+ end
77
+ end
78
+
79
+ describe "#query(conditions)" do
80
+ let(:conditions) { {active: true} }
81
+
82
+ it "expect add sql conditions in query" do
83
+ expect(repo.query(conditions).dataset.sql).to include('WHERE ("active" IS TRUE)')
84
+ end
85
+ end
86
+
87
+ describe "#by_id(id)" do
88
+ context "when id is founded on repository" do
89
+ let!(:staff) { Factory[:staff] }
90
+
91
+ it "expect return rom object" do
92
+ expect(repo.by_id(staff.id)).to be_a(AuctionFunCore::Entities::Staff)
93
+ end
94
+ end
95
+
96
+ context "when id is not found on repository" do
97
+ it "expect return nil" do
98
+ expect(repo.by_id(nil)).to be_nil
99
+ end
100
+ end
101
+ end
102
+
103
+ describe "#by_id!(id)" do
104
+ context "when id is founded on repository" do
105
+ let!(:staff) { Factory[:staff] }
106
+
107
+ it "expect return rom object" do
108
+ expect(repo.by_id(staff.id)).to be_a(AuctionFunCore::Entities::Staff)
109
+ end
110
+ end
111
+
112
+ context "when id is not found on repository" do
113
+ it "expect raise exception" do
114
+ expect { repo.by_id!(nil) }.to raise_error(ROM::TupleCountMismatchError)
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,117 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe AuctionFunCore::Repos::UserContext::UserRepository, type: :repo do
6
+ subject(:repo) { described_class.new }
7
+
8
+ describe "#create" do
9
+ let(:attributes) { Factory.structs[:user] }
10
+
11
+ let(:user) do
12
+ repo.create(
13
+ name: attributes.name,
14
+ email: attributes.email,
15
+ phone: attributes.phone,
16
+ password_digest: BCrypt::Password.create("password")
17
+ )
18
+ end
19
+
20
+ it "expect create a new auction on repository" do
21
+ expect(user).to be_a(AuctionFunCore::Entities::User)
22
+ expect(user.name).to eq(attributes.name)
23
+ expect(user.email).to eq(attributes.email)
24
+ expect(user.phone).to eq(attributes.phone)
25
+ expect(user.password_digest).to be_present
26
+ expect(user.created_at).not_to be_blank
27
+ expect(user.updated_at).not_to be_blank
28
+ end
29
+ end
30
+
31
+ describe "#update" do
32
+ let(:user) { Factory[:user] }
33
+ let(:new_name) { "New name" }
34
+
35
+ it "expect update user on repository" do
36
+ expect { repo.update(user.id, name: new_name) }
37
+ .to change { repo.by_id(user.id).name }
38
+ .from(user.name)
39
+ .to(new_name)
40
+ end
41
+ end
42
+
43
+ describe "#delete" do
44
+ let!(:user) { Factory[:user] }
45
+
46
+ it "expect remove user on repository" do
47
+ expect { repo.delete(user.id) }
48
+ .to change(repo, :count)
49
+ .from(1).to(0)
50
+ end
51
+ end
52
+
53
+ describe "#all" do
54
+ let!(:user) { Factory[:user] }
55
+
56
+ it "expect return all users" do
57
+ expect(repo.all.size).to eq(1)
58
+ expect(repo.all.first.id).to eq(user.id)
59
+ end
60
+ end
61
+
62
+ describe "#count" do
63
+ context "when has not user on repository" do
64
+ it "expect return zero" do
65
+ expect(repo.count).to be_zero
66
+ end
67
+ end
68
+
69
+ context "when has users on repository" do
70
+ let!(:auction) { Factory[:user] }
71
+
72
+ it "expect return total" do
73
+ expect(repo.count).to eq(1)
74
+ end
75
+ end
76
+ end
77
+
78
+ describe "#query(conditions)" do
79
+ let(:conditions) { {active: true} }
80
+
81
+ it "expect add sql conditions in query" do
82
+ expect(repo.query(conditions).dataset.sql).to include('WHERE ("active" IS TRUE)')
83
+ end
84
+ end
85
+
86
+ describe "#by_id(id)" do
87
+ context "when id is founded on repository" do
88
+ let!(:user) { Factory[:user] }
89
+
90
+ it "expect return rom object" do
91
+ expect(repo.by_id(user.id)).to be_a(AuctionFunCore::Entities::User)
92
+ end
93
+ end
94
+
95
+ context "when id is not found on repository" do
96
+ it "expect return nil" do
97
+ expect(repo.by_id(nil)).to be_nil
98
+ end
99
+ end
100
+ end
101
+
102
+ describe "#by_id!(id)" do
103
+ context "when id is founded on repository" do
104
+ let!(:user) { Factory[:user] }
105
+
106
+ it "expect return rom object" do
107
+ expect(repo.by_id(user.id)).to be_a(AuctionFunCore::Entities::User)
108
+ end
109
+ end
110
+
111
+ context "when id is not found on repository" do
112
+ it "expect raise exception" do
113
+ expect { repo.by_id!(nil) }.to raise_error(ROM::TupleCountMismatchError)
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe AuctionFunCore::Services::Mail::AuctionContext::PostAuction::ParticipantMailer, type: :mailer do
6
+ let(:default_email_system) { AuctionFunCore::Application[:settings].default_email_system }
7
+
8
+ describe "#deliver" do
9
+ subject(:mailer) { described_class.new(auction, participant, statistics) }
10
+
11
+ context "when participant has invalid data" do
12
+ let(:participant) { Factory.structs[:user, id: 1, email: nil] }
13
+ let(:auction) { Factory.structs[:auction, :default_finished_standard, id: 1] }
14
+ let(:statistics) { OpenStruct.new(auction_date: Date.current) }
15
+
16
+ it "expect raise error" do
17
+ expect { mailer.deliver }.to raise_error(
18
+ ArgumentError, "SMTP To address may not be blank: []"
19
+ )
20
+ end
21
+ end
22
+
23
+ context "when participant has valid data" do
24
+ let(:winner) { Factory[:user] }
25
+ let(:participant) { Factory[:user] }
26
+ let(:auction) { Factory[:auction, :default_finished_standard, winner_id: winner.id] }
27
+ let(:statistics) do
28
+ OpenStruct.new(
29
+ auction_total_bids: 2, winner_bid: (auction.minimal_bid_cents * 2), winner_total_bids: 1,
30
+ auction_date: Date.current
31
+ )
32
+ end
33
+
34
+ subject(:mailer) { described_class.new(auction, participant, statistics).deliver }
35
+
36
+ it "expect send email with correct data" do
37
+ expect(mailer).to be_a_instance_of(Mail::Message)
38
+ expect(mail_from(default_email_system)).to be_truthy
39
+ expect(
40
+ sent_mail_to?(
41
+ participant.email,
42
+ I18n.t("mail.auction_context.post_auction.participant_mailer.subject", title: auction.title)
43
+ )
44
+ ).to be_truthy
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe AuctionFunCore::Services::Mail::AuctionContext::PostAuction::WinnerMailer, type: :mailer do
6
+ let(:default_email_system) { AuctionFunCore::Application[:settings].default_email_system }
7
+
8
+ describe "#deliver" do
9
+ subject(:mailer) { described_class.new(auction, winner, statistics) }
10
+
11
+ context "when winner has invalid data" do
12
+ let(:winner) { Factory.structs[:user, email: nil] }
13
+ let(:auction) { Factory.structs[:auction, :default_finished_standard, id: 1] }
14
+ let(:statistics) { OpenStruct.new(auction_date: Date.current) }
15
+
16
+ it "expect raise error" do
17
+ expect { mailer.deliver }.to raise_error(
18
+ ArgumentError, "SMTP To address may not be blank: []"
19
+ )
20
+ end
21
+ end
22
+
23
+ context "when winner has valid data" do
24
+ let(:winner) { Factory[:user] }
25
+ let(:auction) { Factory[:auction, :default_finished_standard, winner_id: winner.id] }
26
+ let(:bid) { Factory[:bid, auction_id: auction.id, user_id: winner.id, value_cents: auction.minimal_bid_cents] }
27
+ let(:statistics) do
28
+ OpenStruct.new(
29
+ auction_total_bids: 1, winner_bid: auction.minimal_bid_cents, winner_total_bids: 1,
30
+ auction_date: Date.current
31
+ )
32
+ end
33
+
34
+ subject(:mailer) { described_class.new(auction, winner, statistics).deliver }
35
+
36
+ it "expect send email with correct data" do
37
+ expect(mailer).to be_a_instance_of(Mail::Message)
38
+ expect(mail_from(default_email_system)).to be_truthy
39
+ expect(
40
+ sent_mail_to?(
41
+ winner.email,
42
+ I18n.t("mail.auction_context.post_auction.winner_mailer.subject", title: auction.title)
43
+ )
44
+ ).to be_truthy
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe AuctionFunCore::Services::Mail::AuctionContext::PreAuction::AuctionStartReminderMailer, type: :mailer do
6
+ let(:default_email_system) { AuctionFunCore::Application[:settings].default_email_system }
7
+
8
+ describe "#deliver" do
9
+ subject(:mailer) { described_class.new(auction, participant) }
10
+
11
+ let(:auction) { Factory.structs[:auction, :default_scheduled_standard, id: 1, started_at: 3.hours.from_now] }
12
+
13
+ context "when participant has invalid data" do
14
+ let(:participant) { Factory.structs[:user, id: 1, email: nil] }
15
+
16
+ it "expect raise error" do
17
+ expect { mailer.deliver }.to raise_error(
18
+ ArgumentError, "SMTP To address may not be blank: []"
19
+ )
20
+ end
21
+ end
22
+
23
+ context "when participant has valid data" do
24
+ let(:participant) { Factory[:user] }
25
+
26
+ subject(:mailer) { described_class.new(auction, participant).deliver }
27
+
28
+ it "expect send email with correct data" do
29
+ expect(mailer).to be_a_instance_of(Mail::Message)
30
+ expect(mail_from(default_email_system)).to be_truthy
31
+ expect(
32
+ sent_mail_to?(
33
+ participant.email,
34
+ I18n.t("mail.auction_context.pre_auction.auction_start_reminder_mailer.subject", title: auction.title)
35
+ )
36
+ ).to be_truthy
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe AuctionFunCore::Services::Mail::UserContext::RegistrationMailer, type: :mailer do
6
+ let(:default_email_system) { AuctionFunCore::Application[:settings].default_email_system }
7
+
8
+ describe "#deliver" do
9
+ subject(:mailer) { described_class.new(user) }
10
+
11
+ context "when user has invalid data" do
12
+ let(:user) { Factory.structs[:user, id: 1, email: nil] }
13
+
14
+ it "expect raise error" do
15
+ expect { mailer.deliver }.to raise_error(
16
+ ArgumentError, "SMTP To address may not be blank: []"
17
+ )
18
+ end
19
+ end
20
+
21
+ context "when user has valid data" do
22
+ let(:user) { Factory.structs[:user, :with_email_confirmation_token, id: 1] }
23
+
24
+ subject(:mailer) { described_class.new(user).deliver }
25
+
26
+ it "expect send email with correct data" do
27
+ expect(mailer).to be_a_instance_of(Mail::Message)
28
+ expect(mail_from(default_email_system)).to be_truthy
29
+ expect(sent_mail_to?(user.email, I18n.t("mail.user_context.registration.subject"))).to be_truthy
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe AuctionFunCore::Workers::Operations::AuctionContext::PostAuction::ParticipantOperationJob, type: :worker do
6
+ let(:auction_repository) { AuctionFunCore::Repos::AuctionContext::AuctionRepository.new }
7
+ let(:participant) { Factory[:user] }
8
+ let(:auction) { Factory[:auction, :default_finished_standard, :with_winner] }
9
+
10
+ describe "#perform" do
11
+ subject(:worker) { described_class.new }
12
+
13
+ context "when params are valid" do
14
+ before do
15
+ Factory[:bid, auction_id: auction.id, user_id: auction.winner_id]
16
+ Factory[:bid, auction_id: auction.id, user_id: participant.id]
17
+ end
18
+
19
+ it "expect execute participant mailer service" do
20
+ allow(AuctionFunCore::Workers::Services::Mail::AuctionContext::PostAuction::ParticipantMailerJob).to receive(:perform_async)
21
+
22
+ worker.perform(auction.id, participant.id)
23
+
24
+ expect(AuctionFunCore::Workers::Services::Mail::AuctionContext::PostAuction::ParticipantMailerJob).to have_received(:perform_async).once
25
+ end
26
+ end
27
+
28
+ context "when an exception occours but retry limit is not reached" do
29
+ before do
30
+ stub_const("::AuctionFunCore::Workers::ApplicationJob::MAX_RETRIES", 1)
31
+ allow(AuctionFunCore::Application[:logger]).to receive(:error)
32
+ end
33
+
34
+ it "expect rescue/capture exception and reschedule job" do
35
+ expect { worker.perform(nil, nil) }.to change(described_class.jobs, :size).from(0).to(1)
36
+
37
+ expect(AuctionFunCore::Application[:logger]).to have_received(:error).at_least(:once)
38
+ end
39
+ end
40
+
41
+ context "when the exception reaches the retry limit" do
42
+ before do
43
+ stub_const("::AuctionFunCore::Workers::ApplicationJob::MAX_RETRIES", 0)
44
+ allow(AuctionFunCore::Application[:logger]).to receive(:error)
45
+ end
46
+
47
+ it "expect raise exception and stop retry" do
48
+ expect { worker.perform(nil, nil) }.to raise_error(ROM::TupleCountMismatchError)
49
+
50
+ expect(AuctionFunCore::Application[:logger]).to have_received(:error).at_least(:once)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe AuctionFunCore::Workers::Operations::AuctionContext::PostAuction::WinnerOperationJob, type: :worker do
6
+ let(:auction_repository) { AuctionFunCore::Repos::AuctionContext::AuctionRepository.new }
7
+ let(:auction) { Factory[:auction, :default_finished_standard, :with_winner] }
8
+
9
+ describe "#perform" do
10
+ subject(:worker) { described_class.new }
11
+
12
+ context "when params are valid" do
13
+ it "expect execute winner mailer service" do
14
+ allow(AuctionFunCore::Workers::Services::Mail::AuctionContext::PostAuction::WinnerMailerJob).to receive(:perform_async)
15
+
16
+ worker.perform(auction.id, auction.winner_id)
17
+
18
+ expect(AuctionFunCore::Workers::Services::Mail::AuctionContext::PostAuction::WinnerMailerJob).to have_received(:perform_async).once
19
+ end
20
+ end
21
+
22
+ context "when an exception occours but retry limit is not reached" do
23
+ before do
24
+ stub_const("::AuctionFunCore::Workers::ApplicationJob::MAX_RETRIES", 1)
25
+ allow(AuctionFunCore::Application[:logger]).to receive(:error)
26
+ end
27
+
28
+ it "expect rescue/capture exception and reschedule job" do
29
+ expect { worker.perform(nil, nil) }.to change(described_class.jobs, :size).from(0).to(1)
30
+
31
+ expect(AuctionFunCore::Application[:logger]).to have_received(:error).at_least(:once)
32
+ end
33
+ end
34
+
35
+ context "when the exception reaches the retry limit" do
36
+ before do
37
+ stub_const("::AuctionFunCore::Workers::ApplicationJob::MAX_RETRIES", 0)
38
+ allow(AuctionFunCore::Application[:logger]).to receive(:error)
39
+ end
40
+
41
+ it "expect raise exception and stop retry" do
42
+ expect { worker.perform(nil, nil) }.to raise_error(ROM::TupleCountMismatchError)
43
+
44
+ expect(AuctionFunCore::Application[:logger]).to have_received(:error).at_least(:once)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe AuctionFunCore::Workers::Operations::AuctionContext::PreAuction::AuctionStartReminderOperationJob, type: :worker do
6
+ let(:auction) { Factory[:auction, :default_scheduled_standard, started_at: 3.hours.from_now] }
7
+ let(:operation_class) { AuctionFunCore::Operations::AuctionContext::PreAuction::AuctionStartReminderOperation }
8
+
9
+ describe "#perform" do
10
+ subject(:worker) { described_class.new }
11
+
12
+ context "when params are valid" do
13
+ it "expect execute auction start reminder operation" do
14
+ allow(AuctionFunCore::Operations::AuctionContext::PreAuction::AuctionStartReminderOperation)
15
+ .to receive(:call)
16
+ .with(auction_id: auction.id)
17
+
18
+ worker.perform(auction.id)
19
+
20
+ expect(AuctionFunCore::Operations::AuctionContext::PreAuction::AuctionStartReminderOperation)
21
+ .to have_received(:call)
22
+ .with(auction_id: auction.id)
23
+ .once
24
+ end
25
+ end
26
+
27
+ context "when an exception occours but retry limit is not reached" do
28
+ before do
29
+ stub_const("::AuctionFunCore::Workers::ApplicationJob::MAX_RETRIES", 1)
30
+ allow(AuctionFunCore::Application[:logger]).to receive(:error)
31
+ end
32
+
33
+ it "expect rescue/capture exception and reschedule job" do
34
+ expect { worker.perform(nil) }.to change(described_class.jobs, :size).from(0).to(1)
35
+
36
+ expect(AuctionFunCore::Application[:logger]).to have_received(:error).at_least(:once)
37
+ end
38
+ end
39
+
40
+ context "when the exception reaches the retry limit" do
41
+ before do
42
+ stub_const("::AuctionFunCore::Workers::ApplicationJob::MAX_RETRIES", 0)
43
+ allow(AuctionFunCore::Application[:logger]).to receive(:error)
44
+ end
45
+
46
+ it "expect raise exception and stop retry" do
47
+ expect { worker.perform(nil) }.to raise_error(ROM::TupleCountMismatchError)
48
+
49
+ expect(AuctionFunCore::Application[:logger]).to have_received(:error).at_least(:once)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe AuctionFunCore::Workers::Operations::AuctionContext::Processor::Finish::ClosedOperationJob, type: :worker do
6
+ let(:auction_repository) { AuctionFunCore::Repos::AuctionContext::AuctionRepository.new }
7
+ let(:auction) { Factory[:auction, :default_running_closed] }
8
+
9
+ describe "#perform" do
10
+ subject(:worker) { described_class.new }
11
+
12
+ context "when params are valid" do
13
+ it "expect execute auction start operation" do
14
+ expect { worker.perform(auction.id) }
15
+ .to change { auction_repository.by_id(auction.id).status }
16
+ .from("running")
17
+ .to("finished")
18
+ end
19
+ end
20
+
21
+ context "when an exception occours but retry limit is not reached" do
22
+ before do
23
+ stub_const("::AuctionFunCore::Workers::ApplicationJob::MAX_RETRIES", 1)
24
+ allow(AuctionFunCore::Application[:logger]).to receive(:error)
25
+ end
26
+
27
+ it "expect rescue/capture exception and reschedule job" do
28
+ expect { worker.perform(nil) }.to change(described_class.jobs, :size).from(0).to(1)
29
+
30
+ expect(AuctionFunCore::Application[:logger]).to have_received(:error).at_least(:once)
31
+ end
32
+ end
33
+
34
+ context "when the exception reaches the retry limit" do
35
+ before do
36
+ stub_const("::AuctionFunCore::Workers::ApplicationJob::MAX_RETRIES", 0)
37
+ allow(AuctionFunCore::Application[:logger]).to receive(:error)
38
+ end
39
+
40
+ it "expect raise exception and stop retry" do
41
+ expect { worker.perform(nil) }.to raise_error(ROM::TupleCountMismatchError)
42
+
43
+ expect(AuctionFunCore::Application[:logger]).to have_received(:error).at_least(:once)
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe AuctionFunCore::Workers::Operations::AuctionContext::Processor::Finish::PennyOperationJob, type: :worker do
6
+ let(:auction_repository) { AuctionFunCore::Repos::AuctionContext::AuctionRepository.new }
7
+ let(:auction) { Factory[:auction, :default_running_penny] }
8
+
9
+ describe "#perform" do
10
+ subject(:worker) { described_class.new }
11
+
12
+ context "when params are valid" do
13
+ it "expect execute auction start operation" do
14
+ expect { worker.perform(auction.id) }
15
+ .to change { auction_repository.by_id(auction.id).status }
16
+ .from("running")
17
+ .to("finished")
18
+ end
19
+ end
20
+
21
+ context "when an exception occours but retry limit is not reached" do
22
+ before do
23
+ stub_const("::AuctionFunCore::Workers::ApplicationJob::MAX_RETRIES", 1)
24
+ allow(AuctionFunCore::Application[:logger]).to receive(:error)
25
+ end
26
+
27
+ it "expect rescue/capture exception and reschedule job" do
28
+ expect { worker.perform(nil) }.to change(described_class.jobs, :size).from(0).to(1)
29
+
30
+ expect(AuctionFunCore::Application[:logger]).to have_received(:error).at_least(:once)
31
+ end
32
+ end
33
+
34
+ context "when the exception reaches the retry limit" do
35
+ before do
36
+ stub_const("::AuctionFunCore::Workers::ApplicationJob::MAX_RETRIES", 0)
37
+ allow(AuctionFunCore::Application[:logger]).to receive(:error)
38
+ end
39
+
40
+ it "expect raise exception and stop retry" do
41
+ expect { worker.perform(nil) }.to raise_error(ROM::TupleCountMismatchError)
42
+
43
+ expect(AuctionFunCore::Application[:logger]).to have_received(:error).at_least(:once)
44
+ end
45
+ end
46
+ end
47
+ end