-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
606b15b
commit f03aa50
Showing
14 changed files
with
237 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module Incomes | ||
class ChangeIncome # < Infra::EventHandler | ||
def call(event) | ||
@income = Income.find_by(id: event.data.fetch(:id)) | ||
@income.update( | ||
value: event.data.fetch(:value), | ||
description: event.data.fetch(:description), | ||
received_at: event.data.fetch(:received_at), | ||
user_id: event.data.fetch(:user_id) | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module Incoming | ||
module Commands | ||
class UpdateIncome < Infra::Command | ||
attribute :id, Infra::Types::UUID | ||
attribute :value, Infra::Types::Coercible::Float | ||
attribute :description, Infra::Types::String | ||
attribute :received_at, Infra::Types::Date | ||
attribute :user_id, Infra::Types::ID | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module Incoming | ||
module Events | ||
class IncomeUpdated < Infra::Event | ||
attribute :id, Infra::Types::UUID | ||
attribute :value, Infra::Types::Coercible::Float | ||
attribute :description, Infra::Types::String | ||
attribute :received_at, Infra::Types::JSON::Date | ||
attribute :user_id, Infra::Types::ID | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module Incoming | ||
module Services | ||
class OnUpdateMoneyIncome | ||
def initialize(event_store = Rails.configuration.event_store) | ||
@repository = AggregateRoot::Repository.new(event_store) | ||
end | ||
|
||
def call(command) | ||
@repository.with_aggregate(Income.new, "Income$#{SecureRandom.uuid}") do |income| | ||
income.update( | ||
id: command.id, | ||
value: command.value, | ||
description: command.description, | ||
received_at: command.received_at, | ||
user_id: command.user_id | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FactoryBot.define do | ||
factory :incomes_income, class: Incomes::Income do | ||
id { SecureRandom.uuid } | ||
description { Faker::Name.name } | ||
value { Faker::Number.decimal(l_digits: 2) } | ||
user_id { Faker::Number.number(digits: 1) } | ||
received_at { Faker::Date.backward(days: 1) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
describe 'Update incoming money' do | ||
before do | ||
sign_in user | ||
visit root_path | ||
end | ||
|
||
let(:user) { create(:user) } | ||
let!(:income) { create(:incomes_income, user_id: user.id) } | ||
|
||
it 'by navigating to incomes and filling the form' do | ||
within '#desktop-nav' do | ||
click_link 'Incomes' | ||
end | ||
|
||
within "#incomes_income_#{income.id}" do | ||
click_link 'Edit' | ||
end | ||
|
||
fill_income('Salary', '20/01/2022', 10_000) | ||
expect_income_content('Salary', '20/01/2022', '10000.0') | ||
|
||
fill_income('Freelance', '21/01/2022', 1_000) | ||
expect_income_content('Freelance', '20/01/2022', '1000.0') | ||
|
||
expect(page).to have_content 'Total' | ||
expect(page).to have_content '$11000.0' | ||
end | ||
|
||
private | ||
|
||
def fill_income(description, received_at, value) | ||
fill_in 'Description', with: description | ||
fill_in 'Value', with: value | ||
fill_in 'Received at', with: received_at | ||
|
||
click_button 'Save' | ||
|
||
expect(page).to have_content 'Success' | ||
end | ||
|
||
def expect_income_content(description, received_at, value) | ||
expect(page).to have_content description | ||
expect(page).to have_content received_at | ||
expect(page).to have_content value | ||
end | ||
end |