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,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe AuctionFunCore::Workers::Operations::AuctionContext::Processor::Finish::StandardOperationJob, type: :worker do
6
+ let(:auction_repository) { AuctionFunCore::Repos::AuctionContext::AuctionRepository.new }
7
+ let(:auction) { Factory[:auction, :default_running_standard] }
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::StartOperationJob, type: :worker do
6
+ let(:auction_repository) { AuctionFunCore::Repos::AuctionContext::AuctionRepository.new }
7
+ let(:auction) { Factory[:auction, :default_scheduled_standard] }
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("scheduled")
17
+ .to("running")
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,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe AuctionFunCore::Workers::Services::Mail::AuctionContext::PostAuction::ParticipantMailerJob, type: :worker do
6
+ let(:auction_repository) { AuctionFunCore::Repos::AuctionContext::AuctionRepository.new }
7
+ let(:user_repository) { AuctionFunCore::Repos::UserContext::UserRepository.new }
8
+ let(:relation) { AuctionFunCore::Application[:container].relations[:auctions] }
9
+ let(:participant) { Factory[:user] }
10
+ let(:auction) { Factory[:auction, :default_finished_standard, :with_winner] }
11
+ let(:statistics) { ROM::OpenStruct.new(id: auction.id, auction_total_bids: 0, winner_bid: nil, winner_total_bids: 0) }
12
+ let(:participant_mailer) { AuctionFunCore::Services::Mail::AuctionContext::PostAuction::ParticipantMailer }
13
+ let(:mailer) { participant_mailer.new(auction, participant, statistics) }
14
+
15
+ describe "#perform" do
16
+ subject(:worker) { described_class.new }
17
+
18
+ context "when attributes are valid" do
19
+ before do
20
+ allow(AuctionFunCore::Repos::AuctionContext::AuctionRepository).to receive(:new).and_return(auction_repository)
21
+ allow(AuctionFunCore::Repos::UserContext::UserRepository).to receive(:new).and_return(user_repository)
22
+ allow(auction_repository).to receive(:by_id!).with(auction.id).and_return(auction)
23
+ allow(user_repository).to receive(:by_id!).with(participant.id).and_return(participant)
24
+ allow(relation).to receive_message_chain("load_participant_statistics.call.first").and_return(statistics)
25
+ allow(participant_mailer).to receive(:new).with(auction, participant, statistics).and_return(mailer)
26
+ allow(mailer).to receive(:deliver).and_return(true)
27
+ end
28
+
29
+ it "expect trigger registration mailer service" do
30
+ worker.perform(auction.id, participant.id)
31
+
32
+ expect(mailer).to have_received(:deliver).once
33
+ end
34
+ end
35
+
36
+ context "when an exception occours but retry limit is not reached" do
37
+ before do
38
+ stub_const("::AuctionFunCore::Workers::ApplicationJob::MAX_RETRIES", 1)
39
+ allow(AuctionFunCore::Application[:logger]).to receive(:error)
40
+ end
41
+
42
+ it "expect rescue/capture exception and reschedule job" do
43
+ expect { worker.perform(nil, nil) }.to change(described_class.jobs, :size).from(0).to(1)
44
+
45
+ expect(AuctionFunCore::Application[:logger]).to have_received(:error).at_least(:once)
46
+ end
47
+ end
48
+
49
+ context "when the exception reaches the retry limit" do
50
+ before do
51
+ stub_const("::AuctionFunCore::Workers::ApplicationJob::MAX_RETRIES", 0)
52
+ allow(AuctionFunCore::Application[:logger]).to receive(:error)
53
+ end
54
+
55
+ it "expect raise exception and stop retry" do
56
+ expect { worker.perform(nil, nil) }.to raise_error(ROM::TupleCountMismatchError)
57
+
58
+ expect(AuctionFunCore::Application[:logger]).to have_received(:error).at_least(:once)
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe AuctionFunCore::Workers::Services::Mail::AuctionContext::PreAuction::AuctionStartReminderMailerJob, type: :worker do
6
+ let(:auction_repository) { AuctionFunCore::Repos::AuctionContext::AuctionRepository.new }
7
+ let(:user_repository) { AuctionFunCore::Repos::UserContext::UserRepository.new }
8
+ let(:participant) { Factory[:user] }
9
+ let(:auction) { Factory[:auction, :default_finished_standard, :with_winner] }
10
+ let(:auction_start_reminder_mailer) { AuctionFunCore::Services::Mail::AuctionContext::PreAuction::AuctionStartReminderMailer }
11
+ let(:mailer) { auction_start_reminder_mailer.new(auction, participant) }
12
+
13
+ describe "#perform" do
14
+ subject(:worker) { described_class.new }
15
+
16
+ context "when attributes are valid" do
17
+ before do
18
+ allow(AuctionFunCore::Repos::AuctionContext::AuctionRepository).to receive(:new).and_return(auction_repository)
19
+ allow(AuctionFunCore::Repos::UserContext::UserRepository).to receive(:new).and_return(user_repository)
20
+ allow(auction_repository).to receive(:by_id!).with(auction.id).and_return(auction)
21
+ allow(user_repository).to receive(:by_id!).with(participant.id).and_return(participant)
22
+ allow(auction_start_reminder_mailer).to receive(:new).with(auction, participant).and_return(mailer)
23
+ allow(mailer).to receive(:deliver).and_return(true)
24
+ end
25
+
26
+ it "expect trigger registration mailer service" do
27
+ worker.perform(auction.id, participant.id)
28
+
29
+ expect(mailer).to have_received(:deliver).once
30
+ end
31
+ end
32
+
33
+ context "when an exception occours but retry limit is not reached" do
34
+ before do
35
+ stub_const("::AuctionFunCore::Workers::ApplicationJob::MAX_RETRIES", 1)
36
+ allow(AuctionFunCore::Application[:logger]).to receive(:error)
37
+ end
38
+
39
+ it "expect rescue/capture exception and reschedule job" do
40
+ expect { worker.perform(nil, nil) }.to change(described_class.jobs, :size).from(0).to(1)
41
+
42
+ expect(AuctionFunCore::Application[:logger]).to have_received(:error).at_least(:once)
43
+ end
44
+ end
45
+
46
+ context "when the exception reaches the retry limit" do
47
+ before do
48
+ stub_const("::AuctionFunCore::Workers::ApplicationJob::MAX_RETRIES", 0)
49
+ allow(AuctionFunCore::Application[:logger]).to receive(:error)
50
+ end
51
+
52
+ it "expect raise exception and stop retry" do
53
+ expect { worker.perform(nil, nil) }.to raise_error(ROM::TupleCountMismatchError)
54
+
55
+ expect(AuctionFunCore::Application[:logger]).to have_received(:error).at_least(:once)
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe AuctionFunCore::Workers::Services::Mail::AuctionContext::PostAuction::WinnerMailerJob, type: :worker do
6
+ let(:auction_repository) { AuctionFunCore::Repos::AuctionContext::AuctionRepository.new }
7
+ let(:user_repository) { AuctionFunCore::Repos::UserContext::UserRepository.new }
8
+ let(:relation) { AuctionFunCore::Application[:container].relations[:auctions] }
9
+ let(:winner) { Factory[:user] }
10
+ let(:auction) { Factory[:auction, :default_finished_standard, :with_winner] }
11
+ let(:statistics) { ROM::OpenStruct.new(id: auction.id, auction_total_bids: 1, winner_bid: auction.minimal_bid_cents, winner_total_bids: 1) }
12
+ let(:winner_mailer) { AuctionFunCore::Services::Mail::AuctionContext::PostAuction::WinnerMailer }
13
+ let(:mailer) { winner_mailer.new(auction, winner, statistics) }
14
+
15
+ describe "#perform" do
16
+ subject(:worker) { described_class.new }
17
+
18
+ context "when attributes are valid" do
19
+ before do
20
+ allow(AuctionFunCore::Repos::AuctionContext::AuctionRepository).to receive(:new).and_return(auction_repository)
21
+ allow(AuctionFunCore::Repos::UserContext::UserRepository).to receive(:new).and_return(user_repository)
22
+ allow(auction_repository).to receive(:by_id!).with(auction.id).and_return(auction)
23
+ allow(user_repository).to receive(:by_id!).with(winner.id).and_return(winner)
24
+ allow(relation).to receive_message_chain("load_winner_statistics.call.first").and_return(statistics)
25
+ allow(winner_mailer).to receive(:new).with(auction, winner, statistics).and_return(mailer)
26
+ allow(mailer).to receive(:deliver).and_return(true)
27
+ end
28
+
29
+ it "expect trigger registration mailer service" do
30
+ worker.perform(auction.id, winner.id)
31
+
32
+ expect(mailer).to have_received(:deliver).once
33
+ end
34
+ end
35
+
36
+ context "when an exception occours but retry limit is not reached" do
37
+ before do
38
+ stub_const("::AuctionFunCore::Workers::ApplicationJob::MAX_RETRIES", 1)
39
+ allow(AuctionFunCore::Application[:logger]).to receive(:error)
40
+ end
41
+
42
+ it "expect rescue/capture exception and reschedule job" do
43
+ expect { worker.perform(nil, nil) }.to change(described_class.jobs, :size).from(0).to(1)
44
+
45
+ expect(AuctionFunCore::Application[:logger]).to have_received(:error).at_least(:once)
46
+ end
47
+ end
48
+
49
+ context "when the exception reaches the retry limit" do
50
+ before do
51
+ stub_const("::AuctionFunCore::Workers::ApplicationJob::MAX_RETRIES", 0)
52
+ allow(AuctionFunCore::Application[:logger]).to receive(:error)
53
+ end
54
+
55
+ it "expect raise exception and stop retry" do
56
+ expect { worker.perform(nil, nil) }.to raise_error(ROM::TupleCountMismatchError)
57
+
58
+ expect(AuctionFunCore::Application[:logger]).to have_received(:error).at_least(:once)
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe AuctionFunCore::Workers::Services::Mail::UserContext::RegistrationMailerJob, type: :worker do
6
+ let(:user) { Factory[:user] }
7
+ let(:user_repo) { AuctionFunCore::Repos::UserRepository.new }
8
+ let(:mailer_class) { AuctionFunCore::Services::Mail::UserContext::RegistrationMailer }
9
+ let(:mailer) { mailer_class.new(user) }
10
+
11
+ describe "#perform" do
12
+ subject(:worker) { described_class.new }
13
+
14
+ context "when attributes are valid" do
15
+ before do
16
+ allow(mailer_class).to receive(:new).with(user).and_return(mailer)
17
+ allow(mailer).to receive(:deliver).and_return(true)
18
+ end
19
+
20
+ it "expect trigger registration mailer service" do
21
+ worker.perform(user.id)
22
+
23
+ expect(mailer).to have_received(:deliver).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,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe AuctionFunCore do
4
+ it "has a version number" do
5
+ expect(AuctionFunCore::VERSION).to eq("0.8.10")
6
+ end
7
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ ENV["APP_ENV"] = "test"
4
+
5
+ if ENV["CI"]
6
+ require "simplecov"
7
+ SimpleCov.start do
8
+ add_filter "/spec"
9
+ add_group "Commands", "lib/auction_fun_core/commands"
10
+ add_group "Contracts", "lib/auction_fun_core/contracts"
11
+ add_group "Entities", "lib/auction_fun_core/entities"
12
+ add_group "Operations", "lib/auction_fun_core/operations"
13
+ add_group "Relations", "lib/auction_fun_core/relations"
14
+ add_group "Repositories", "lib/auction_fun_core/repos"
15
+ add_group "Services", "lib/auction_fun_core/services"
16
+ add_group "Workers", "lib/auction_fun_core/workers"
17
+ add_group "System", "system"
18
+ add_group "Config", "config"
19
+ end
20
+ end
21
+
22
+ require_relative "../config/application"
23
+ require "pry"
24
+ require "dotenv"
25
+ require "rom-factory"
26
+ require "database_cleaner/sequel"
27
+ require "sidekiq/testing"
28
+
29
+ AuctionFunCore::Application.start(:core)
30
+
31
+ Factory = ROM::Factory.configure do |config|
32
+ config.rom = AuctionFunCore::Application[:container]
33
+ end
34
+
35
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |file| require file }
36
+
37
+ RSpec.configure do |config|
38
+ config.add_setting :rom
39
+ config.rom = Factory.rom
40
+
41
+ # Enable flags like --only-failures and --next-failure
42
+ config.example_status_persistence_file_path = ".rspec_status"
43
+
44
+ # Disable RSpec exposing methods globally on `Module` and `main`
45
+ config.disable_monkey_patching!
46
+
47
+ config.expect_with :rspec do |c|
48
+ c.syntax = :expect
49
+ end
50
+
51
+ config.before do
52
+ DatabaseCleaner.clean
53
+ Sidekiq::Worker.clear_all
54
+ end
55
+
56
+ config.after(:suite) do
57
+ AuctionFunCore::Application.stop(:core)
58
+ end
59
+ end
60
+
61
+ DatabaseCleaner.strategy = :truncation
@@ -0,0 +1,7 @@
1
+ Sidekiq::Testing.fake!
2
+
3
+ RSpec.configure do |config|
4
+ config.before do
5
+ Sidekiq::Worker.clear_all
6
+ end
7
+ end
@@ -0,0 +1,143 @@
1
+ # frozen_string_literal: true
2
+
3
+ Factory.define(:auction, struct_namespace: AuctionFunCore::Entities) do |f|
4
+ f.association(:staff)
5
+ f.title { fake(:commerce, :product_name) }
6
+ f.description { fake(:lorem, :paragraph) }
7
+ f.initial_bid_cents { 0 }
8
+ f.initial_bid_currency { AuctionFunCore::Application[:settings].default_currency }
9
+ f.minimal_bid_cents { 0 }
10
+ f.minimal_bid_currency { AuctionFunCore::Application[:settings].default_currency }
11
+
12
+ f.trait :with_minimal_bid do |t|
13
+ end
14
+
15
+ f.trait :with_winner do |t|
16
+ f.association(:winner)
17
+ end
18
+
19
+ f.trait :with_participants do |t|
20
+ f.association(:winner)
21
+ end
22
+
23
+ f.trait :with_kind_standard do |t|
24
+ t.kind { "standard" }
25
+ end
26
+
27
+ f.trait :with_kind_penny do |t|
28
+ t.kind { "penny" }
29
+ end
30
+
31
+ f.trait :with_kind_closed do |t|
32
+ t.kind { "closed" }
33
+ end
34
+
35
+ f.trait :with_status_scheduled do |t|
36
+ t.status { "scheduled" }
37
+ end
38
+
39
+ f.trait :with_status_running do |t|
40
+ t.status { "running" }
41
+ end
42
+
43
+ f.trait :with_status_paused do |t|
44
+ t.status { "paused" }
45
+ end
46
+
47
+ f.trait :with_status_canceled do |t|
48
+ t.status { "canceled" }
49
+ end
50
+
51
+ f.trait :with_status_finished do |t|
52
+ t.status { "finished" }
53
+ end
54
+
55
+ f.trait :started_in_one_hour_from_now do |t|
56
+ t.started_at { 1.hour.from_now }
57
+ end
58
+
59
+ f.trait :started_in_one_day_from_now do |t|
60
+ t.started_at { 1.day.from_now }
61
+ end
62
+
63
+ f.trait :finished_in_two_days_from_now do |t|
64
+ t.started_at { 1.day.from_now }
65
+ t.finished_at { 2.days.from_now }
66
+ end
67
+
68
+ f.trait :default_scheduled_standard do |t|
69
+ t.kind { "standard" }
70
+ t.status { "scheduled" }
71
+
72
+ t.started_at { 1.hour.from_now }
73
+ t.finished_at { 1.week.from_now }
74
+ t.initial_bid_cents { 100 }
75
+ t.minimal_bid_cents { 100 }
76
+ end
77
+
78
+ f.trait :default_running_standard do |t|
79
+ t.kind { "standard" }
80
+ t.status { "running" }
81
+
82
+ t.started_at { 1.hour.ago }
83
+ t.finished_at { 1.day.from_now }
84
+ t.initial_bid_cents { 100 }
85
+ t.minimal_bid_cents { 100 }
86
+ end
87
+
88
+ f.trait :default_finished_standard do |t|
89
+ t.kind { "standard" }
90
+ t.status { "finished" }
91
+
92
+ t.started_at { 2.days.ago }
93
+ t.finished_at { 1.day.ago }
94
+ t.initial_bid_cents { 100 }
95
+ t.minimal_bid_cents { 100 }
96
+ end
97
+
98
+ f.trait :default_paused_standard do |t|
99
+ t.kind { "standard" }
100
+ t.status { "paused" }
101
+
102
+ t.started_at { 1.hour.ago }
103
+ t.finished_at { 1.day.from_now }
104
+ t.initial_bid_cents { 100 }
105
+ t.minimal_bid_cents { 100 }
106
+ end
107
+
108
+ f.trait :default_scheduled_penny do |t|
109
+ t.kind { "penny" }
110
+ t.status { "scheduled" }
111
+
112
+ t.stopwatch { AuctionFunCore::Business::Configuration::AUCTION_STOPWATCH_MIN_VALUE }
113
+ t.started_at { 1.hour.from_now }
114
+ t.finished_at { 1.hour.from_now + AuctionFunCore::Business::Configuration::AUCTION_STOPWATCH_MIN_VALUE }
115
+ end
116
+
117
+ f.trait :default_running_penny do |t|
118
+ t.kind { "penny" }
119
+ t.status { "running" }
120
+
121
+ t.started_at { 1.hour.ago }
122
+ t.finished_at { 60.seconds.from_now }
123
+ t.initial_bid_cents { 100 }
124
+ end
125
+
126
+ f.trait :default_scheduled_closed do |t|
127
+ t.kind { "closed" }
128
+ t.status { "scheduled" }
129
+
130
+ t.initial_bid_cents { 100 }
131
+ t.started_at { 1.hour.from_now }
132
+ t.finished_at { 1.week.from_now }
133
+ end
134
+
135
+ f.trait :default_running_closed do |t|
136
+ t.kind { "closed" }
137
+ t.status { "running" }
138
+
139
+ t.started_at { 1.hour.ago }
140
+ t.finished_at { 1.day.from_now }
141
+ t.initial_bid_cents { 100 }
142
+ end
143
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ Factory.define(:bid, struct_namespace: AuctionFunCore::Entities) do |f|
4
+ f.association(:auction, :default_scheduled_standard)
5
+ f.association(:user)
6
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ Factory.define(:staff, struct_namespace: AuctionFunCore::Entities) do |f|
4
+ f.name { fake(:name, :name) }
5
+ f.email { fake(:internet, :email) }
6
+ f.phone { fake(:phone_number, :cell_phone_in_e164).tr_s("^0-9", "") }
7
+ f.password_digest { BCrypt::Password.create("password") }
8
+ f.kind { "common" }
9
+ f.active { true }
10
+
11
+ f.trait :with_root_kind do |t|
12
+ t.kind { "root" }
13
+ end
14
+
15
+ f.trait :inactive do |t|
16
+ t.active { false }
17
+ end
18
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ Factory.define(:user, struct_namespace: AuctionFunCore::Entities) do |f|
4
+ f.name { fake(:name, :name) }
5
+ f.email { fake(:internet, :email) }
6
+ f.phone { fake(:phone_number, :cell_phone_in_e164).tr_s("^0-9", "") }
7
+ f.password_digest { BCrypt::Password.create("password") }
8
+ f.email_confirmation_at { Time.current - 1.day }
9
+ f.phone_confirmation_at { Time.current - 1.day }
10
+ f.confirmed_at { Time.current }
11
+ f.active { true }
12
+
13
+ f.trait :inactive do |t|
14
+ t.active { false }
15
+ end
16
+
17
+ f.trait :unconfirmed do |t|
18
+ t.email_confirmation_token { nil }
19
+ t.phone_confirmation_token { nil }
20
+ t.confirmed_at { nil }
21
+ end
22
+
23
+ f.trait :with_unconfirmed_email do |t|
24
+ t.email_confirmation_at { nil }
25
+ end
26
+
27
+ f.trait :with_unconfirmed_phone do |t|
28
+ t.phone_confirmation_at { nil }
29
+ end
30
+
31
+ f.trait :with_email_confirmation_token do |t|
32
+ t.email_confirmation_token { AuctionFunCore::Business::TokenGenerator.generate_email_token }
33
+ end
34
+
35
+ f.trait :with_phone_confirmation_token do |t|
36
+ t.phone_confirmation_token { AuctionFunCore::Business::TokenGenerator.generate_phone_token }
37
+ end
38
+
39
+ f.trait :with_balance do |t|
40
+ t.balance_cents { 1000 }
41
+ t.balance_currency { AuctionFunCore::Application[:settings].default_currency }
42
+ end
43
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ if defined?(Faker)
4
+ I18n.enforce_available_locales = false
5
+ Faker::Config.locale = "pt-BR"
6
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ IdleMailer.config do |config|
4
+ config.delivery_method = :test
5
+ end
6
+
7
+ RSpec.configure do |config|
8
+ config.include IdleMailer::Testing::Helpers
9
+
10
+ config.after :each do
11
+ IdleMailer::Testing.clear_mail!
12
+ end
13
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ shared_examples "validate_email_contract" do |factory_name|
4
+ let(:factory) { Factory[factory_name] }
5
+
6
+ context "when email is in wrong format" do
7
+ let(:attributes) { {email: "wrongemail"} }
8
+
9
+ it "expect failure with error messages" do
10
+ expect(subject).to be_failure
11
+
12
+ expect(subject.errors[:email]).to include(I18n.t("contracts.errors.custom.macro.email_format"))
13
+ end
14
+ end
15
+
16
+ context "when email is already exists on database" do
17
+ let(:attributes) { {email: factory.email} }
18
+
19
+ it "expect failure with error messages" do
20
+ expect(subject).to be_failure
21
+
22
+ expect(subject.errors[:email]).to include(I18n.t("contracts.errors.custom.default.taken"))
23
+ end
24
+ end
25
+ end