-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementa alguns testes para os services
- Loading branch information
1 parent
c65d009
commit 4a1c4b0
Showing
6 changed files
with
63 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
describe CNBARowToTransactionService do | ||
setup { create(:transaction_kind, code: random_line[0]) } | ||
|
||
subject(:service) { described_class.call(random_line, user_id) } | ||
|
||
let(:financial_entry) do | ||
create(:financial_entry, content_file: File.open('./CNAB.txt').read) | ||
end | ||
let(:content_file) { financial_entry.content_file } | ||
let(:random_line) { content_file.lines.sample.to_s.strip } | ||
let(:user_id) { financial_entry.user_id } | ||
|
||
describe 'when row invalid' do | ||
let(:financial_entry) { build(:invalid_financial_entry) } | ||
|
||
it { is_expected.not_to be_success } | ||
|
||
it { expect(Transaction.count).to eq(0) } | ||
end | ||
|
||
describe 'when row valid' do | ||
it { is_expected.to be_success } | ||
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,31 @@ | ||
# frozen_string_literal: true | ||
|
||
describe ImportCNBAFileService do | ||
setup do | ||
content_file.each_line do |line| | ||
next if TransactionKind.exists?(code: line[0]) | ||
|
||
create(:transaction_kind, code: line[0]) | ||
end | ||
end | ||
|
||
subject(:service) { described_class.call(financial_entry_params) } | ||
|
||
let(:user) { create(:user) } | ||
let(:content_file) { File.open('./CNAB.txt').read } | ||
let(:financial_entry_params) do | ||
{ user_id: user.id, content_file: content_file } | ||
end | ||
|
||
describe 'when params invalid' do | ||
let(:financial_entry_params) { { user_id: nil, content_file: '' } } | ||
|
||
it { is_expected.not_to be_success } | ||
|
||
it { expect(Transaction.count).to eq(0) } | ||
end | ||
|
||
describe 'when params valid' do | ||
it { is_expected.to be_success } | ||
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.configure do |config| | ||
config.include Devise::Test::ControllerHelpers | ||
config.include Devise::Test::ControllerHelpers, type: :controller | ||
config.include Devise::Test::IntegrationHelpers, type: :service | ||
end |