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.
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,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