auction_fun_core 0.8.7 → 0.8.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/.standard.yml +2 -0
  3. data/CHANGELOG.md +29 -0
  4. data/Procfile +1 -0
  5. data/README.md +34 -32
  6. data/Rakefile +1 -1
  7. data/auction_fun_core.gemspec +1 -1
  8. data/i18n/en-US/contracts/contracts.en-US.yml +3 -0
  9. data/i18n/en-US/mail/application.en-US.yml +7 -0
  10. data/i18n/en-US/mail/auction_context/pre_auction/auction_start_reminder.en-US.yml +11 -0
  11. data/i18n/pt-BR/contracts/contracts.pt-BR.yml +3 -0
  12. data/i18n/pt-BR/mail/application.pt-BR.yml +7 -0
  13. data/i18n/pt-BR/mail/auction_context/pre_auction/auction_start_reminder.pt-BR.yml +11 -0
  14. data/lib/auction_fun_core/business/configuration.rb +31 -0
  15. data/lib/auction_fun_core/business/token_generator.rb +19 -1
  16. data/lib/auction_fun_core/contracts/application_contract.rb +9 -1
  17. data/lib/auction_fun_core/contracts/auction_context/create_contract.rb +35 -20
  18. data/lib/auction_fun_core/contracts/auction_context/post_auction/participant_contract.rb +23 -1
  19. data/lib/auction_fun_core/contracts/auction_context/post_auction/winner_contract.rb +22 -1
  20. data/lib/auction_fun_core/contracts/auction_context/pre_auction/auction_start_reminder_contract.rb +48 -0
  21. data/lib/auction_fun_core/contracts/auction_context/processor/finish/closed_contract.rb +19 -7
  22. data/lib/auction_fun_core/contracts/auction_context/processor/finish/penny_contract.rb +19 -7
  23. data/lib/auction_fun_core/contracts/auction_context/processor/finish/standard_contract.rb +19 -7
  24. data/lib/auction_fun_core/contracts/auction_context/processor/pause_contract.rb +16 -4
  25. data/lib/auction_fun_core/contracts/auction_context/processor/start_contract.rb +17 -5
  26. data/lib/auction_fun_core/contracts/auction_context/processor/unpause_contract.rb +16 -4
  27. data/lib/auction_fun_core/contracts/bid_context/create_bid_closed_contract.rb +20 -11
  28. data/lib/auction_fun_core/contracts/bid_context/create_bid_penny_contract.rb +18 -9
  29. data/lib/auction_fun_core/contracts/bid_context/create_bid_standard_contract.rb +19 -10
  30. data/lib/auction_fun_core/contracts/staff_context/authentication_contract.rb +18 -4
  31. data/lib/auction_fun_core/contracts/staff_context/registration_contract.rb +20 -8
  32. data/lib/auction_fun_core/contracts/user_context/authentication_contract.rb +18 -4
  33. data/lib/auction_fun_core/contracts/user_context/email_confirmation_contract.rb +17 -2
  34. data/lib/auction_fun_core/contracts/user_context/phone_confirmation_contract.rb +17 -2
  35. data/lib/auction_fun_core/contracts/user_context/registration_contract.rb +26 -8
  36. data/lib/auction_fun_core/entities/auction.rb +48 -4
  37. data/lib/auction_fun_core/entities/bid.rb +3 -2
  38. data/lib/auction_fun_core/entities/staff.rb +15 -2
  39. data/lib/auction_fun_core/entities/user.rb +31 -2
  40. data/lib/auction_fun_core/events/app.rb +8 -2
  41. data/lib/auction_fun_core/events/listener.rb +19 -16
  42. data/lib/auction_fun_core/operations/auction_context/create_operation.rb +25 -9
  43. data/lib/auction_fun_core/operations/auction_context/post_auction/participant_operation.rb +36 -3
  44. data/lib/auction_fun_core/operations/auction_context/post_auction/winner_operation.rb +36 -2
  45. data/lib/auction_fun_core/operations/auction_context/pre_auction/auction_start_reminder_operation.rb +96 -0
  46. data/lib/auction_fun_core/operations/auction_context/processor/finish/closed_operation.rb +82 -10
  47. data/lib/auction_fun_core/operations/auction_context/processor/finish/penny_operation.rb +81 -10
  48. data/lib/auction_fun_core/operations/auction_context/processor/finish/standard_operation.rb +81 -12
  49. data/lib/auction_fun_core/operations/auction_context/processor/pause_operation.rb +36 -1
  50. data/lib/auction_fun_core/operations/auction_context/processor/unpause_operation.rb +36 -1
  51. data/lib/auction_fun_core/relations/auctions.rb +178 -97
  52. data/lib/auction_fun_core/relations/bids.rb +18 -0
  53. data/lib/auction_fun_core/repos/auction_context/auction_repository.rb +40 -11
  54. data/lib/auction_fun_core/repos/bid_context/bid_repository.rb +27 -5
  55. data/lib/auction_fun_core/repos/staff_context/staff_repository.rb +63 -21
  56. data/lib/auction_fun_core/repos/user_context/user_repository.rb +69 -25
  57. data/lib/auction_fun_core/services/mail/auction_context/post_auction/participant_mailer.rb +7 -1
  58. data/lib/auction_fun_core/services/mail/auction_context/post_auction/winner_mailer.rb +7 -1
  59. data/lib/auction_fun_core/services/mail/auction_context/pre_auction/auction_start_reminder_mailer.rb +35 -0
  60. data/lib/auction_fun_core/services/mail/templates/auction_context/post_auction/participant.html.erb +1 -1
  61. data/lib/auction_fun_core/services/mail/templates/auction_context/post_auction/winner.html.erb +1 -1
  62. data/lib/auction_fun_core/services/mail/templates/auction_context/pre_auction/auction_start_reminder.html.erb +192 -0
  63. data/lib/auction_fun_core/services/mail/user_context/registration_mailer.rb +6 -0
  64. data/lib/auction_fun_core/version.rb +1 -1
  65. data/lib/auction_fun_core/workers/application_job.rb +10 -0
  66. data/lib/auction_fun_core/workers/operations/auction_context/post_auction/participant_operation_job.rb +7 -2
  67. data/lib/auction_fun_core/workers/operations/auction_context/post_auction/winner_operation_job.rb +6 -2
  68. data/lib/auction_fun_core/workers/operations/auction_context/pre_auction/auction_start_reminder_operation_job.rb +44 -0
  69. data/lib/auction_fun_core/workers/operations/auction_context/processor/finish/closed_operation_job.rb +6 -3
  70. data/lib/auction_fun_core/workers/operations/auction_context/processor/finish/penny_operation_job.rb +6 -3
  71. data/lib/auction_fun_core/workers/operations/auction_context/processor/finish/standard_operation_job.rb +6 -2
  72. data/lib/auction_fun_core/workers/operations/auction_context/processor/start_operation_job.rb +6 -3
  73. data/lib/auction_fun_core/workers/services/mail/auction_context/post_auction/participant_mailer_job.rb +12 -7
  74. data/lib/auction_fun_core/workers/services/mail/auction_context/post_auction/winner_mailer_job.rb +11 -5
  75. data/lib/auction_fun_core/workers/services/mail/auction_context/pre_auction/auction_start_reminder_mailer_job.rb +48 -0
  76. data/lib/auction_fun_core/workers/services/mail/user_context/registration_mailer_job.rb +8 -6
  77. data/spec/auction_fun_core/contracts/auction_context/create_contract_spec.rb +158 -0
  78. data/spec/auction_fun_core/contracts/auction_context/post_auction/participant_contract_spec.rb +77 -0
  79. data/spec/auction_fun_core/contracts/auction_context/post_auction/winner_contract_spec.rb +76 -0
  80. data/spec/auction_fun_core/contracts/auction_context/pre_auction/auction_start_reminder_contract_spec.rb +48 -0
  81. data/spec/auction_fun_core/contracts/auction_context/processor/finish/closed_contract_spec.rb +59 -0
  82. data/spec/auction_fun_core/contracts/auction_context/processor/finish/penny_contract_spec.rb +59 -0
  83. data/spec/auction_fun_core/contracts/auction_context/processor/finish/standard_contract_spec.rb +59 -0
  84. data/spec/auction_fun_core/contracts/auction_context/processor/pause_contract_spec.rb +39 -0
  85. data/spec/auction_fun_core/contracts/auction_context/processor/start_contract_spec.rb +59 -0
  86. data/spec/auction_fun_core/contracts/auction_context/processor/unpause_contract_spec.rb +39 -0
  87. data/spec/auction_fun_core/contracts/bid_context/create_bid_closed_contract_spec.rb +130 -0
  88. data/spec/auction_fun_core/contracts/bid_context/create_bid_penny_contract_spec.rb +118 -0
  89. data/spec/auction_fun_core/contracts/bid_context/create_bid_standard_contract_spec.rb +154 -0
  90. data/spec/auction_fun_core/contracts/staff_context/authentication_contract_spec.rb +89 -0
  91. data/spec/auction_fun_core/contracts/staff_context/registration_contract_spec.rb +24 -0
  92. data/spec/auction_fun_core/contracts/user_context/authentication_contract_spec.rb +89 -0
  93. data/spec/auction_fun_core/contracts/user_context/email_confirmation_contract_spec.rb +54 -0
  94. data/spec/auction_fun_core/contracts/user_context/phone_confirmation_contract_spec.rb +54 -0
  95. data/spec/auction_fun_core/contracts/user_context/registration_contract_spec.rb +27 -0
  96. data/spec/auction_fun_core/entities/auction_spec.rb +75 -0
  97. data/spec/auction_fun_core/entities/bid_spec.rb +7 -0
  98. data/spec/auction_fun_core/entities/staff_spec.rb +38 -0
  99. data/spec/auction_fun_core/entities/user_spec.rb +106 -0
  100. data/spec/auction_fun_core/operations/auction_context/create_operation_spec.rb +126 -0
  101. data/spec/auction_fun_core/operations/auction_context/post_auction/participant_operation_spec.rb +88 -0
  102. data/spec/auction_fun_core/operations/auction_context/post_auction/winner_operation_spec.rb +76 -0
  103. data/spec/auction_fun_core/operations/auction_context/pre_auction/auction_start_reminder_operation_spec.rb +98 -0
  104. data/spec/auction_fun_core/operations/auction_context/processor/finish/closed_operation_spec.rb +107 -0
  105. data/spec/auction_fun_core/operations/auction_context/processor/finish/penny_operation_spec.rb +107 -0
  106. data/spec/auction_fun_core/operations/auction_context/processor/finish/standard_operation_spec.rb +106 -0
  107. data/spec/auction_fun_core/operations/auction_context/processor/pause_operation_spec.rb +83 -0
  108. data/spec/auction_fun_core/operations/auction_context/processor/start_operation_spec.rb +147 -0
  109. data/spec/auction_fun_core/operations/auction_context/processor/unpause_operation_spec.rb +80 -0
  110. data/spec/auction_fun_core/operations/bid_context/create_bid_closed_operation_spec.rb +95 -0
  111. data/spec/auction_fun_core/operations/bid_context/create_bid_penny_operation_spec.rb +133 -0
  112. data/spec/auction_fun_core/operations/bid_context/create_bid_standard_operation_spec.rb +95 -0
  113. data/spec/auction_fun_core/operations/staff_context/authentication_operation_spec.rb +74 -0
  114. data/spec/auction_fun_core/operations/staff_context/registration_operation_spec.rb +93 -0
  115. data/spec/auction_fun_core/operations/user_context/authentication_operation_spec.rb +74 -0
  116. data/spec/auction_fun_core/operations/user_context/email_confirmation_operation_spec.rb +76 -0
  117. data/spec/auction_fun_core/operations/user_context/phone_confirmation_operation_spec.rb +76 -0
  118. data/spec/auction_fun_core/operations/user_context/registration_operation_spec.rb +100 -0
  119. data/spec/auction_fun_core/relations/auctions_spec.rb +471 -0
  120. data/spec/auction_fun_core/repos/auction_context/auction_repository_spec.rb +64 -0
  121. data/spec/auction_fun_core/repos/bid_context/bid_repository_spec.rb +64 -0
  122. data/spec/auction_fun_core/repos/staff_context/staff_repository_spec.rb +118 -0
  123. data/spec/auction_fun_core/repos/user_context/user_repository_spec.rb +117 -0
  124. data/spec/auction_fun_core/services/mail/auction_context/post_auction/participant_mailer_spec.rb +48 -0
  125. data/spec/auction_fun_core/services/mail/auction_context/post_auction/winner_mailer_spec.rb +48 -0
  126. data/spec/auction_fun_core/services/mail/auction_context/pre_auction/auction_start_reminder_mailer_spec.rb +40 -0
  127. data/spec/auction_fun_core/services/mail/user_context/registration_mailer_spec.rb +33 -0
  128. data/spec/auction_fun_core/workers/operations/auction_context/post_auction/participation_operation_job_spec.rb +54 -0
  129. data/spec/auction_fun_core/workers/operations/auction_context/post_auction/winner_operation_job_spec.rb +48 -0
  130. data/spec/auction_fun_core/workers/operations/auction_context/pre_auction/auction_start_reminder_operation_job_spec.rb +53 -0
  131. data/spec/auction_fun_core/workers/operations/auction_context/processor/finish/closed_operation_job_spec.rb +47 -0
  132. data/spec/auction_fun_core/workers/operations/auction_context/processor/finish/penny_operation_job_spec.rb +47 -0
  133. data/spec/auction_fun_core/workers/operations/auction_context/processor/finish/standard_operation_job_spec.rb +47 -0
  134. data/spec/auction_fun_core/workers/operations/auction_context/processor/start_operation_job_spec.rb +47 -0
  135. data/spec/auction_fun_core/workers/services/mail/auction_context/post_auction/participant_mailer_job_spec.rb +62 -0
  136. data/spec/auction_fun_core/workers/services/mail/auction_context/post_auction/pre_auction/auction_start_reminder_mailer_job_spec.rb +59 -0
  137. data/spec/auction_fun_core/workers/services/mail/auction_context/post_auction/winner_mailer_job_spec.rb +62 -0
  138. data/spec/auction_fun_core/workers/services/mail/user_context/registration_mailer_job_spec.rb +53 -0
  139. data/spec/auction_fun_core_spec.rb +7 -0
  140. data/spec/spec_helper.rb +61 -0
  141. data/spec/support/background_job.rb +7 -0
  142. data/spec/support/factories/auctions.rb +143 -0
  143. data/spec/support/factories/bids.rb +6 -0
  144. data/spec/support/factories/staffs.rb +18 -0
  145. data/spec/support/factories/users.rb +43 -0
  146. data/spec/support/faker.rb +6 -0
  147. data/spec/support/mail.rb +13 -0
  148. data/spec/support/shared_examples/validate_email_contract.rb +25 -0
  149. data/spec/support/shared_examples/validate_name_contract.rb +19 -0
  150. data/spec/support/shared_examples/validate_password_confirmation_contract.rb +16 -0
  151. data/spec/support/shared_examples/validate_password_contract.rb +18 -0
  152. data/spec/support/shared_examples/validate_phone_contract.rb +25 -0
  153. data/spec/support/shared_examples/validate_stopwatch_contract.rb +32 -0
  154. data/system/providers/background_job.rb +6 -0
  155. metadata +87 -2
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe AuctionFunCore::Operations::UserContext::EmailConfirmationOperation, 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(:user) { Factory[:user, :unconfirmed, :with_email_confirmation_token] }
12
+ let(:attributes) { {email_confirmation_token: user.email_confirmation_token} }
13
+
14
+ it "expect result success matching block" do
15
+ matched_success = nil
16
+ matched_failure = nil
17
+
18
+ operation.call(attributes) do |o|
19
+ o.success { |v| matched_success = v }
20
+ o.failure { |f| matched_failure = f }
21
+ end
22
+
23
+ expect(matched_success).to be_a(AuctionFunCore::Entities::User)
24
+ expect(matched_failure).to be_nil
25
+ end
26
+ end
27
+
28
+ context "when operation happens with failure" do
29
+ let(:attributes) { Dry::Core::Constants::EMPTY_HASH }
30
+
31
+ it "expect result matching block" do
32
+ matched_success = nil
33
+ matched_failure = nil
34
+
35
+ operation.call(attributes) do |o|
36
+ o.success { |v| matched_success = v }
37
+ o.failure { |f| matched_failure = f }
38
+ end
39
+
40
+ expect(matched_success).to be_nil
41
+ expect(matched_failure[:email_confirmation_token]).to include(I18n.t("contracts.errors.key?"))
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ describe "#call(attributes)" do
48
+ subject(:operation) { described_class.new.call(attributes) }
49
+
50
+ context "when contract are invalid" do
51
+ let(:attributes) { Dry::Core::Constants::EMPTY_HASH }
52
+
53
+ it "expect return failure with error messages" do
54
+ expect(operation).to be_failure
55
+ expect(operation.failure[:email_confirmation_token]).to include(I18n.t("contracts.errors.key?"))
56
+ end
57
+ end
58
+
59
+ context "when contract are valid" do
60
+ let(:user) { Factory[:user, :unconfirmed, :with_email_confirmation_token] }
61
+ let(:attributes) { {email_confirmation_token: user.email_confirmation_token} }
62
+
63
+ before do
64
+ allow(AuctionFunCore::Application[:event]).to receive(:publish)
65
+ end
66
+
67
+ it "expect return success" do
68
+ expect(operation).to be_success
69
+ expect(operation.success).to be_email_confirmed
70
+ expect(operation.success).to be_confirmed
71
+
72
+ expect(AuctionFunCore::Application[:event]).to have_received(:publish).once
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe AuctionFunCore::Operations::UserContext::PhoneConfirmationOperation, 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(:user) { Factory[:user, :unconfirmed, :with_phone_confirmation_token] }
12
+ let(:attributes) { {phone_confirmation_token: user.phone_confirmation_token} }
13
+
14
+ it "expect result success matching block" do
15
+ matched_success = nil
16
+ matched_failure = nil
17
+
18
+ operation.call(attributes) do |o|
19
+ o.success { |v| matched_success = v }
20
+ o.failure { |f| matched_failure = f }
21
+ end
22
+
23
+ expect(matched_success).to be_a(AuctionFunCore::Entities::User)
24
+ expect(matched_failure).to be_nil
25
+ end
26
+ end
27
+
28
+ context "when operation happens with failure" do
29
+ let(:attributes) { Dry::Core::Constants::EMPTY_HASH }
30
+
31
+ it "expect result matching block" do
32
+ matched_success = nil
33
+ matched_failure = nil
34
+
35
+ operation.call(attributes) do |o|
36
+ o.success { |v| matched_success = v }
37
+ o.failure { |f| matched_failure = f }
38
+ end
39
+
40
+ expect(matched_success).to be_nil
41
+ expect(matched_failure[:phone_confirmation_token]).to include(I18n.t("contracts.errors.key?"))
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ describe "#call(attributes)" do
48
+ subject(:operation) { described_class.new.call(attributes) }
49
+
50
+ context "when contract are invalid" do
51
+ let(:attributes) { Dry::Core::Constants::EMPTY_HASH }
52
+
53
+ it "expect return failure with error messages" do
54
+ expect(operation).to be_failure
55
+ expect(operation.failure[:phone_confirmation_token]).to include(I18n.t("contracts.errors.key?"))
56
+ end
57
+ end
58
+
59
+ context "when contract are valid" do
60
+ let(:user) { Factory[:user, :unconfirmed, :with_phone_confirmation_token] }
61
+ let(:attributes) { {phone_confirmation_token: user.phone_confirmation_token} }
62
+
63
+ before do
64
+ allow(AuctionFunCore::Application[:event]).to receive(:publish)
65
+ end
66
+
67
+ it "expect return success" do
68
+ expect(operation).to be_success
69
+ expect(operation.success).to be_phone_confirmed
70
+ expect(operation.success).to be_confirmed
71
+
72
+ expect(AuctionFunCore::Application[:event]).to have_received(:publish).once
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe AuctionFunCore::Operations::UserContext::RegistrationOperation, type: :operation do
6
+ let(:user_repository) { AuctionFunCore::Repos::UserContext::UserRepository.new }
7
+
8
+ describe ".call(attributes, &block)" do
9
+ let(:operation) { described_class }
10
+
11
+ context "when block is given" do
12
+ context "when operation happens with success" do
13
+ let(:attributes) do
14
+ Factory.structs[:user]
15
+ .to_h
16
+ .except(:id, :created_at, :updated_at, :password_digest)
17
+ .merge!(password: "password", password_confirmation: "password")
18
+ end
19
+
20
+ it "expect result success matching block" do
21
+ matched_success = nil
22
+ matched_failure = nil
23
+
24
+ operation.call(attributes) do |o|
25
+ o.success { |v| matched_success = v }
26
+ o.failure { |f| matched_failure = f }
27
+ end
28
+
29
+ expect(matched_success).to be_a(AuctionFunCore::Entities::User)
30
+ expect(matched_failure).to be_nil
31
+ end
32
+ end
33
+
34
+ context "when operation happens with failure" do
35
+ let(:attributes) { Dry::Core::Constants::EMPTY_HASH }
36
+
37
+ it "expect result matching block" do
38
+ matched_success = nil
39
+ matched_failure = nil
40
+
41
+ operation.call(attributes) do |o|
42
+ o.success { |v| matched_success = v }
43
+ o.failure { |f| matched_failure = f }
44
+ end
45
+
46
+ expect(matched_success).to be_nil
47
+ expect(matched_failure[:name]).to include(I18n.t("contracts.errors.key?"))
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ describe "#call" do
54
+ subject(:operation) { described_class.new.call(attributes) }
55
+
56
+ context "when contract are not valid" do
57
+ let(:attributes) { Dry::Core::Constants::EMPTY_HASH }
58
+
59
+ it "expect not persist new user on database" do
60
+ expect(user_repository.count).to be_zero
61
+
62
+ expect { operation }.not_to change(user_repository, :count)
63
+ end
64
+
65
+ it "expect return failure with error messages" do
66
+ expect(operation).to be_failure
67
+ expect(operation.failure[:name]).to include(I18n.t("contracts.errors.key?"))
68
+ end
69
+ end
70
+
71
+ context "when contract are valid" do
72
+ let(:attributes) do
73
+ Factory.structs[:user]
74
+ .to_h
75
+ .except(:id, :created_at, :updated_at, :password_digest)
76
+ .merge!(password: "password", password_confirmation: "password")
77
+ end
78
+
79
+ before do
80
+ allow(AuctionFunCore::Application[:event]).to receive(:publish)
81
+ allow(AuctionFunCore::Workers::Services::Mail::UserContext::RegistrationMailerJob)
82
+ .to receive(:perform_async)
83
+ end
84
+
85
+ it "expect return success without error messages" do
86
+ expect(operation).to be_success
87
+ expect(operation.failure).to be_blank
88
+ end
89
+
90
+ it "expect create user with email confirmation token on database and dispatch event registration" do
91
+ expect { operation }.to change(user_repository, :count).from(0).to(1)
92
+
93
+ expect(operation.success.email_confirmation_token).to be_present
94
+ expect(AuctionFunCore::Application[:event]).to have_received(:publish).once
95
+ expect(AuctionFunCore::Workers::Services::Mail::UserContext::RegistrationMailerJob)
96
+ .to have_received(:perform_async).once
97
+ end
98
+ end
99
+ end
100
+ end