bscf-core 0.2.0 → 0.2.1

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 (56) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bscf/core/version.rb +1 -1
  3. metadata +2 -55
  4. data/spec/dummy/Rakefile +0 -6
  5. data/spec/dummy/app/assets/stylesheets/application.css +0 -15
  6. data/spec/dummy/app/controllers/application_controller.rb +0 -2
  7. data/spec/dummy/app/jobs/application_job.rb +0 -7
  8. data/spec/dummy/app/mailers/application_mailer.rb +0 -4
  9. data/spec/dummy/app/models/application_record.rb +0 -3
  10. data/spec/dummy/app/views/layouts/mailer.html.erb +0 -13
  11. data/spec/dummy/app/views/layouts/mailer.text.erb +0 -1
  12. data/spec/dummy/bin/dev +0 -2
  13. data/spec/dummy/bin/rails +0 -4
  14. data/spec/dummy/bin/rake +0 -4
  15. data/spec/dummy/bin/setup +0 -34
  16. data/spec/dummy/config/application.rb +0 -43
  17. data/spec/dummy/config/boot.rb +0 -5
  18. data/spec/dummy/config/cable.yml +0 -10
  19. data/spec/dummy/config/database.yml +0 -17
  20. data/spec/dummy/config/environment.rb +0 -5
  21. data/spec/dummy/config/environments/development.rb +0 -67
  22. data/spec/dummy/config/environments/production.rb +0 -86
  23. data/spec/dummy/config/environments/test.rb +0 -53
  24. data/spec/dummy/config/initializers/cors.rb +0 -16
  25. data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -8
  26. data/spec/dummy/config/initializers/inflections.rb +0 -16
  27. data/spec/dummy/config/locales/en.yml +0 -31
  28. data/spec/dummy/config/puma.rb +0 -38
  29. data/spec/dummy/config/routes.rb +0 -3
  30. data/spec/dummy/config/storage.yml +0 -34
  31. data/spec/dummy/config.ru +0 -6
  32. data/spec/dummy/db/schema.rb +0 -246
  33. data/spec/dummy/log/development.log +0 -2077
  34. data/spec/dummy/log/test.log +0 -69259
  35. data/spec/dummy/tmp/local_secret.txt +0 -1
  36. data/spec/examples.txt +0 -167
  37. data/spec/models/bscf/core/address_spec.rb +0 -12
  38. data/spec/models/bscf/core/business_spec.rb +0 -64
  39. data/spec/models/bscf/core/category_spec.rb +0 -43
  40. data/spec/models/bscf/core/order_item_spec.rb +0 -26
  41. data/spec/models/bscf/core/order_spec.rb +0 -16
  42. data/spec/models/bscf/core/product_spec.rb +0 -47
  43. data/spec/models/bscf/core/quotation_item_spec.rb +0 -44
  44. data/spec/models/bscf/core/quotation_spec.rb +0 -41
  45. data/spec/models/bscf/core/request_for_quotation_spec.rb +0 -13
  46. data/spec/models/bscf/core/rfq_item_spec.rb +0 -14
  47. data/spec/models/bscf/core/role_spec.rb +0 -14
  48. data/spec/models/bscf/core/user_profile_spec.rb +0 -20
  49. data/spec/models/bscf/core/user_role_spec.rb +0 -13
  50. data/spec/models/bscf/core/user_spec.rb +0 -22
  51. data/spec/models/bscf/core/virtual_account_spec.rb +0 -111
  52. data/spec/models/bscf/core/virtual_account_transaction_spec.rb +0 -133
  53. data/spec/rails_helper.rb +0 -46
  54. data/spec/spec_helper.rb +0 -37
  55. data/spec/support/models/shared_examples.rb +0 -49
  56. data/spec/support/requests/shared_requests.rb +0 -126
@@ -1,111 +0,0 @@
1
- require 'rails_helper'
2
-
3
- module Bscf
4
- module Core
5
- RSpec.describe VirtualAccount, type: :model do
6
- attributes = [
7
- { account_number: %i[presence uniqueness] },
8
- { cbs_account_number: %i[presence uniqueness] },
9
- { balance: [ :presence, :numericality ] },
10
- { interest_rate: [ :presence, :numericality ] },
11
- { interest_type: :presence },
12
- { branch_code: :presence },
13
- { product_scheme: [ :presence ] },
14
- { voucher_type: [ :presence ] },
15
- { status: :presence },
16
- { user: :belong_to }
17
- ]
18
-
19
- include_examples("model_shared_spec", :virtual_account, attributes)
20
-
21
- it { should validate_numericality_of(:balance).is_greater_than_or_equal_to(0) }
22
- it { should validate_numericality_of(:interest_rate).is_greater_than_or_equal_to(0) }
23
- it { should validate_inclusion_of(:product_scheme).in_array(VirtualAccount::PRODUCT_SCHEMES) }
24
- it { should validate_inclusion_of(:voucher_type).in_array(VirtualAccount::VOUCHER_TYPES) }
25
-
26
- describe 'scopes' do
27
- let!(:active_account) { create(:virtual_account, :active_status) }
28
- let!(:pending_account) { create(:virtual_account) }
29
- let!(:savings_account) { create(:virtual_account) }
30
- let!(:current_account) { create(:virtual_account, :current_account) }
31
- let!(:loan_account) { create(:virtual_account, :loan_account) }
32
-
33
- it 'filters active accounts' do
34
- expect(described_class.active_accounts).to include(active_account)
35
- expect(described_class.active_accounts).not_to include(pending_account)
36
- end
37
-
38
- it 'filters by branch' do
39
- expect(described_class.by_branch('BR001')).to include(active_account)
40
- end
41
-
42
- it 'filters by product scheme' do
43
- expect(described_class.by_product('SAVINGS')).to include(savings_account)
44
- expect(described_class.by_product('SAVINGS')).not_to include(current_account)
45
- expect(described_class.by_product('CURRENT')).to include(current_account)
46
- expect(described_class.by_product('LOAN')).to include(loan_account)
47
- end
48
- end
49
-
50
- describe '#generate_account_number' do
51
- let(:virtual_account) { build(:virtual_account) }
52
-
53
- it 'generates account number on create' do
54
- expect(virtual_account.account_number).to be_nil
55
- virtual_account.save
56
- expect(virtual_account.account_number).to be_present
57
- expect(virtual_account.account_number).to match(/\ABR001SAVINGSREGULAR\d{6}\z/)
58
- end
59
-
60
- it 'maintains existing account number' do
61
- existing_number = 'BR001SAVINGSREGULAR000001'
62
- virtual_account.account_number = existing_number
63
- virtual_account.save
64
- expect(virtual_account.account_number).to eq(existing_number)
65
- end
66
-
67
- it 'increments sequence number' do
68
- first_account = create(:virtual_account)
69
- second_account = create(:virtual_account)
70
-
71
- first_seq = first_account.account_number[-6..-1].to_i
72
- second_seq = second_account.account_number[-6..-1].to_i
73
-
74
- expect(second_seq).to eq(first_seq + 1)
75
- end
76
- end
77
-
78
- describe 'interest types' do
79
- it 'supports simple interest' do
80
- account = build(:virtual_account)
81
- expect(account.interest_type).to eq('simple')
82
- end
83
-
84
- it 'supports compound interest' do
85
- account = build(:virtual_account, :compound_interest)
86
- expect(account.interest_type).to eq('compound')
87
- end
88
- end
89
-
90
- describe 'account types' do
91
- it 'creates savings account by default' do
92
- account = create(:virtual_account)
93
- expect(account.product_scheme).to eq('SAVINGS')
94
- expect(account.interest_rate).to eq(2.5)
95
- end
96
-
97
- it 'creates current account' do
98
- account = create(:virtual_account, :current_account)
99
- expect(account.product_scheme).to eq('CURRENT')
100
- expect(account.interest_rate).to eq(0.0)
101
- end
102
-
103
- it 'creates loan account' do
104
- account = create(:virtual_account, :loan_account)
105
- expect(account.product_scheme).to eq('LOAN')
106
- expect(account.interest_rate).to eq(12.5)
107
- end
108
- end
109
- end
110
- end
111
- end
@@ -1,133 +0,0 @@
1
- require 'rails_helper'
2
-
3
- module Bscf
4
- module Core
5
- RSpec.describe VirtualAccountTransaction, type: :model do
6
- attributes = [
7
- { amount: [ :presence, :numericality ] },
8
- { transaction_type: :presence },
9
- { status: :presence },
10
- { reference_number: [ :presence, :uniqueness ] }
11
- ]
12
-
13
- include_examples("model_shared_spec", :virtual_account_transaction, attributes)
14
-
15
- describe 'validations' do
16
- it { should validate_numericality_of(:amount).is_greater_than(0) }
17
- end
18
-
19
- describe 'enums' do
20
- it { should define_enum_for(:transaction_type).with_values(transfer: 0, deposit: 1, withdrawal: 2) }
21
- it { should define_enum_for(:status).with_values(pending: 0, completed: 1, failed: 2, cancelled: 3) }
22
- end
23
-
24
- describe '#generate_reference_number' do
25
- let(:transaction) { build(:virtual_account_transaction) }
26
-
27
- it 'generates reference number before validation on create' do
28
- transaction.save
29
- expect(transaction.reference_number).to be_present
30
- expect(transaction.reference_number).to match(/\ATXN\d{14}[0-9a-f]{6}\z/)
31
- end
32
-
33
- it 'does not override existing reference number' do
34
- existing_ref = 'TXN20230101123456abc123'
35
- transaction.reference_number = existing_ref
36
- transaction.save
37
- expect(transaction.reference_number).to eq(existing_ref)
38
- end
39
- end
40
-
41
- describe 'transaction processing' do
42
- let(:from_account) { create(:virtual_account, balance: 1000.00, status: :active) }
43
- let(:to_account) { create(:virtual_account, balance: 500.00, status: :active) }
44
- let(:transaction) do
45
- build(:virtual_account_transaction,
46
- from_account: from_account,
47
- to_account: to_account,
48
- amount: 300.00)
49
- end
50
-
51
- context 'when processing transfer' do
52
- it 'updates account balances on successful transfer' do
53
- expect(transaction.save).to be true
54
- expect(transaction.process!).to be true
55
-
56
- expect(from_account.reload.balance.round(2)).to eq(700.00)
57
- expect(to_account.reload.balance.round(2)).to eq(800.00)
58
- expect(transaction.reload.status).to eq('completed')
59
- end
60
-
61
- it 'validates sufficient balance' do
62
- transaction.amount = 2000.00
63
- expect(transaction.save).to be false
64
- expect(transaction.errors[:from_account]).to include('insufficient balance')
65
- end
66
-
67
- it 'validates account status' do
68
- from_account.update!(status: :suspended)
69
- expect(transaction.save).to be false
70
- expect(transaction.errors[:from_account]).to include('must be active')
71
- end
72
- end
73
-
74
- context 'when processing deposit' do
75
- let(:transaction) do
76
- build(:virtual_account_transaction, :deposit,
77
- to_account: to_account,
78
- amount: 300.00)
79
- end
80
-
81
- it 'updates recipient account balance' do
82
- expect(transaction.save).to be true
83
- expect(transaction.process!).to be true
84
-
85
- expect(to_account.reload.balance.round(2)).to eq(800.00)
86
- expect(transaction.reload.status).to eq('completed')
87
- end
88
-
89
- it 'validates recipient account status' do
90
- to_account.update!(status: :suspended)
91
- expect(transaction.save).to be false
92
- expect(transaction.errors[:to_account]).to include('must be active')
93
- end
94
- end
95
-
96
- context 'when processing withdrawal' do
97
- let(:transaction) do
98
- build(:virtual_account_transaction, :withdrawal,
99
- from_account: from_account,
100
- amount: 300.00)
101
- end
102
-
103
- it 'updates source account balance' do
104
- expect(transaction.save).to be true
105
- expect(transaction.process!).to be true
106
-
107
- expect(from_account.reload.balance.round(2)).to eq(700.00)
108
- expect(transaction.reload.status).to eq('completed')
109
- end
110
-
111
- it 'validates source account status' do
112
- from_account.update!(status: :suspended)
113
- expect(transaction.save).to be false
114
- expect(transaction.errors[:from_account]).to include('must be active')
115
- end
116
- end
117
- end
118
-
119
- describe '#cancel!' do
120
- it 'cancels pending transaction' do
121
- transaction = create(:virtual_account_transaction)
122
- expect(transaction.cancel!).to be true
123
- expect(transaction.status).to eq('cancelled')
124
- end
125
-
126
- it 'cannot cancel completed transaction' do
127
- transaction = create(:virtual_account_transaction, :completed)
128
- expect(transaction.cancel!).to be false
129
- end
130
- end
131
- end
132
- end
133
- end
data/spec/rails_helper.rb DELETED
@@ -1,46 +0,0 @@
1
- # This file is copied to spec/ when you run 'rails generate rspec:install'
2
- require "spec_helper"
3
- ENV["RAILS_ENV"] ||= "test"
4
- require_relative "../spec/dummy/config/environment"
5
- abort("The Rails environment is running in production mode!") if Rails.env.production?
6
-
7
- require "rspec/rails"
8
- require "database_cleaner/active_record"
9
- require "factory_bot_rails"
10
- require "faker"
11
- require "shoulda-matchers"
12
-
13
- begin
14
- ActiveRecord::Migration.maintain_test_schema!
15
- rescue ActiveRecord::PendingMigrationError => e
16
- abort e.to_s.strip
17
- end
18
-
19
- RSpec.configure do |config|
20
- config.before(:suite) do
21
- DatabaseCleaner.strategy = :transaction
22
- DatabaseCleaner.clean_with(:truncation)
23
- end
24
-
25
- config.before do
26
- DatabaseCleaner.strategy = :transaction
27
- DatabaseCleaner.start
28
- end
29
-
30
- config.append_after do
31
- DatabaseCleaner.clean
32
- end
33
-
34
- config.fixture_path = "#{::Rails.root}/spec/fixtures"
35
- config.use_transactional_fixtures = true
36
- config.infer_spec_type_from_file_location!
37
- config.filter_rails_from_backtrace!
38
- config.include FactoryBot::Syntax::Methods
39
- end
40
-
41
- Shoulda::Matchers.configure do |config|
42
- config.integrate do |with|
43
- with.test_framework(:rspec)
44
- with.library(:rails)
45
- end
46
- end
data/spec/spec_helper.rb DELETED
@@ -1,37 +0,0 @@
1
- require "simplecov"
2
- require "./spec/support/models/shared_examples"
3
- # require "./spec/support/requests/shared_requests"
4
- require "rspec/retry"
5
-
6
- RSpec.configure do |config|
7
- config.expect_with :rspec do |expectations|
8
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
9
- end
10
-
11
- config.mock_with :rspec do |mocks|
12
- mocks.verify_partial_doubles = true
13
- end
14
-
15
- config.shared_context_metadata_behavior = :apply_to_host_groups
16
- config.example_status_persistence_file_path = "spec/examples.txt"
17
- config.disable_monkey_patching!
18
-
19
- config.formatter = RSpec::Core::Formatters::DocumentationFormatter
20
-
21
- config.profile_examples = 10
22
- config.order = :random
23
- Kernel.srand config.seed
24
-
25
- config.verbose_retry = true
26
- config.display_try_failure_messages = true
27
- config.around :each, :js do |ex|
28
- ex.run_with_retry retry: 3
29
- end
30
- end
31
-
32
- SimpleCov.start("rails") do
33
- add_filter("/lib/")
34
- add_filter("/bin/")
35
- add_filter("/db/")
36
- add_filter("/spec/")
37
- end
@@ -1,49 +0,0 @@
1
- module Bscf
2
- module Core
3
- VALIDATIONS = {
4
- presence: "validate_presence_of",
5
- uniqueness: "validate_uniqueness_of",
6
- numericality: "validate_numericality_of",
7
- inclusion: "validate_inclusion_of",
8
- belong_to: "belong_to",
9
- have_many: "have_many",
10
- have_and_belong_to_many: "have_and_belong_to_many",
11
- have_one: "have_one",
12
- delegate: "delegate_method"
13
- }.freeze
14
-
15
- RSpec.shared_examples "model_shared_spec" do |factory, attribs, subj = true|
16
- subject { create(factory) } if subj
17
-
18
- it "has a valid factory" do
19
- expect(create(factory)).to be_valid
20
- end
21
-
22
- attribs.each do |attr|
23
- attr.each do |k, v|
24
- if v.instance_of?(Array)
25
- v.each do |validation|
26
- if validation.instance_of?(Hash)
27
- method = validation.keys[0]
28
- options = validation.values[0]
29
- it {
30
- expect(subject).to(
31
- options.inject(
32
- send(VALIDATIONS[method], k)
33
- ) do |o, p|
34
- p[1].nil? ? o.send(p[0]) : o.send(p[0], p[1])
35
- end
36
- )
37
- }
38
- else
39
- it { is_expected.to(send(VALIDATIONS[validation], k)) }
40
- end
41
- end
42
- else
43
- it { is_expected.to(send(VALIDATIONS[v], k)) }
44
- end
45
- end
46
- end
47
- end
48
- end
49
- end
@@ -1,126 +0,0 @@
1
- module Bscf
2
- module Core
3
- RSpec.shared_examples "request_shared_spec" do |controller, field_count, exclude = []|
4
- include Comee::Core::Engine.routes.url_helpers
5
-
6
- let(:factory) { controller.classify.underscore.to_sym }
7
- let(:clazz) { "Bscf::Core::#{controller.classify}".constantize }
8
-
9
- unless exclude.include?(:index)
10
- describe "GET /index" do
11
- it "returns success response" do
12
- count = clazz.count
13
- 3.times { create(factory) }
14
- get(send("#{controller}_url"), headers: headers)
15
- expect(response).to be_successful
16
- result = JSON(response.body)
17
-
18
- expect(result["success"]).to be_truthy
19
- expect(result["data"].count - count).to eq 3
20
- end
21
- end
22
- end
23
-
24
- unless exclude.include?(:show)
25
- describe "GET /show" do
26
- it "returns a success response" do
27
- obj = create(factory)
28
- get(send("#{controller.singularize}_url", obj), headers: headers)
29
- expect(response).to be_successful
30
- result = JSON(response.body)
31
- expect(result["success"]).to be_truthy
32
- expect(result["data"].count).to eq field_count
33
- expect(result["data"]["id"]).to eq obj.id
34
- end
35
- end
36
- end
37
-
38
- unless exclude.include?(:create)
39
- describe "POST /create" do
40
- context "with valid params" do
41
- it "creates a new object" do
42
- params = { payload: valid_attributes }
43
- expect do
44
- post(
45
- send("#{controller}_url"),
46
- headers: headers,
47
- params: params,
48
- as: :json
49
- )
50
- end.to change(clazz, :count).by(1)
51
- expect(response).to have_http_status(:created)
52
- expect(response.content_type).to eq("application/json; charset=utf-8")
53
-
54
- result = JSON(response.body)
55
- expect(result["success"]).to be_truthy
56
- end
57
- end
58
-
59
- context "with invalid params" do
60
- it "renders a JSON response with errors for the new object" do
61
- params = { payload: invalid_attributes }
62
- post(
63
- send("#{controller}_url"),
64
- params: params,
65
- headers: headers,
66
- as: :json
67
- )
68
-
69
- expect(response).to have_http_status(422)
70
- expect(response.content_type).to eq("application/json; charset=utf-8")
71
-
72
- result = JSON(response.body)
73
- expect(result["success"]).to be_falsey
74
- expect(result["error"]).not_to be_blank
75
- end
76
- end
77
- end
78
- end
79
-
80
- unless exclude.include?(:update)
81
- describe "PUT /update" do
82
- context "with valid params" do
83
- it "updates the requested object" do
84
- obj = create(factory)
85
- params = { id: obj.to_param, payload: new_attributes }
86
- put(
87
- send("#{controller.singularize}_url", obj),
88
- headers: headers,
89
- params: params, as: :json
90
- )
91
- obj.reload
92
-
93
- expect(response).to have_http_status(:ok)
94
- expect(obj.send(new_attributes.keys[0])).to eq new_attributes.values[0]
95
- expect(response.content_type).to eq("application/json; charset=utf-8")
96
-
97
- result = JSON(response.body)
98
- expect(result["success"]).to be_truthy
99
- expect(result["data"]["id"]).to eq obj.id
100
- end
101
- end
102
-
103
- context "with invalid params" do
104
- it "renders a JSON response with errors for the object" do
105
- obj = create(factory)
106
- params = { id: obj.to_param, payload: invalid_attributes }
107
- put(
108
- send("#{controller.singularize}_url", obj),
109
- headers: headers,
110
- params: params,
111
- as: :json
112
- )
113
-
114
- expect(response).to have_http_status(422)
115
- expect(response.content_type).to eq("application/json; charset=utf-8")
116
-
117
- result = JSON(response.body)
118
- expect(result["success"]).to be_falsey
119
- expect(result["error"]).not_to be_blank
120
- end
121
- end
122
- end
123
- end
124
- end
125
- end
126
- end