-
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.
Merge pull request #116 from TreinaDev/lista-faturas-dashboard
Lista faturas dashboard
- Loading branch information
Showing
10 changed files
with
247 additions
and
0 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,42 @@ | ||
class Bill | ||
attr_accessor :unit_id, :id, :condo_id, :issue_date, :due_date, :total_value_cents, :status, :values | ||
|
||
def initialize(params = {}) | ||
@unit_id = params.fetch('unit_id', nil) | ||
@id = params.fetch('id', nil) | ||
@condo_id = params.fetch('condo_id', nil) | ||
@issue_date = params.fetch('issue_date', nil) | ||
@due_date = params.fetch('due_date', nil) | ||
@total_value_cents = params.fetch('total_value_cents', nil) | ||
@status = params.fetch('status', nil) | ||
@values = params.fetch('values', []) | ||
end | ||
|
||
def self.request_open_bills(unit_id) | ||
response = Faraday.get("http://localhost:4000/api/v1/units/#{unit_id}/bills") | ||
|
||
return [] unless response.success? | ||
|
||
bills_data = JSON.parse(response.body)['bills'] | ||
bills_array = bills_data.map { |bill_data| new(bill_data) } | ||
bills_array.sort_by { |bill| bill.due_date.to_time.to_i }.reverse | ||
end | ||
|
||
def total_value_formatted | ||
"R$ #{format('%.2f', total_value_cents / 100.0).gsub('.', ',')}" | ||
end | ||
|
||
def due_date_formatted | ||
format_date(@due_date) | ||
end | ||
|
||
def issue_date_formatted | ||
format_date(@issue_date) | ||
end | ||
|
||
private | ||
|
||
def format_date(date) | ||
Date.parse(date).strftime('%d/%m/%Y') | ||
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,40 @@ | ||
<div class="accordion-item rounded-5 shadow-sm"> | ||
<h2 class="accordion-header"> | ||
<button class="accordion-button collapsed rounded-pill py-3" style="background-color: #FDE879" type="button" data-bs-toggle="collapse" data-bs-target="#bills" aria-expanded="false" aria-controls="collapseOne"> | ||
<strong class="position-absolute top-50 start-50 translate-middle text-black">Faturas em Aberto</strong> | ||
</button> | ||
</h2> | ||
|
||
<div id="bills" class="accordion-collapse collapse" data-bs-parent="#accordionExample"> | ||
<div class="accordion-body"> | ||
<% if !@refused && @bills.present? && @bills.any? %> | ||
<% @bills.take(3).each do |bill| %> | ||
<div class="d-flex align-items-center my-1"> | ||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-currency-dollar mx-2" viewBox="0 0 16 16"> | ||
<path d="M4 10.781c.148 1.667 1.513 2.85 3.591 3.003V15h1.043v-1.216c2.27-.179 3.678-1.438 3.678-3.3 0-1.59-.947-2.51-2.956-3.028l-.722-.187V3.467c1.122.11 1.879.714 2.07 1.616h1.47c-.166-1.6-1.54-2.748-3.54-2.875V1H7.591v1.233c-1.939.23-3.27 1.472-3.27 3.156 0 1.454.966 2.483 2.661 2.917l.61.162v4.031c-1.149-.17-1.94-.8-2.131-1.718zm3.391-3.836c-1.043-.263-1.6-.825-1.6-1.616 0-.944.704-1.641 1.8-1.828v3.495l-.2-.05zm1.591 1.872c1.287.323 1.852.859 1.852 1.769 0 1.097-.826 1.828-2.2 1.939V8.73z"/> | ||
</svg> | ||
<div class="d-flex flex-column mx-3"> | ||
<div class="mt-3 fs-5">Valor: <%= bill.total_value_formatted %></div> | ||
<div class="text-muted small">Vencimento: <%= bill.due_date_formatted %></div> | ||
</div> | ||
<%= link_to root_path, class: "ms-auto btn btn-dark d-inline-flex align-items-center rounded-pill" do %> | ||
<p style="margin: 0; font-size: 14px;">Visualizar</p> <i class="bi bi-search ms-1"></i> | ||
<% end %> | ||
</div> | ||
<hr class="m-0"> | ||
<% end %> | ||
<% if @bills.count > 3 %> | ||
<div class='d-flex'> | ||
<%= link_to root_path, class:"btn py-1 rounded-pill d-flex justify-content-center align-items-center mb-2 w-25 fs-6 text-muted", style: "width: 100%;" do %> | ||
<strong>ver mais</strong> | ||
<% end %> | ||
</div> | ||
<% end %> | ||
<% elsif @refused %> | ||
<div class="alert alert-warning text-center">Conexão perdida com o servidor do PagueAlugel.</div> | ||
<% else %> | ||
<div class="alert alert-warning text-center">Não existem faturas em aberto.</div> | ||
<% end %> | ||
</div> | ||
</div> | ||
</div> |
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,5 @@ | ||
{ | ||
"bills": [ | ||
|
||
] | ||
} |
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,34 @@ | ||
{ | ||
"bills": [ | ||
{ | ||
"id": 11, | ||
"issue_date": "2024-09-01", | ||
"due_date": "2024-09-10", | ||
"total_value_cents": 5000 | ||
}, | ||
{ | ||
"id": 1, | ||
"issue_date": "2024-07-01", | ||
"due_date": "2024-07-10", | ||
"total_value_cents": 1000 | ||
}, | ||
{ | ||
"id": 3, | ||
"issue_date": "2024-05-01", | ||
"due_date": "2024-05-10", | ||
"total_value_cents": 3000 | ||
}, | ||
{ | ||
"id": 6, | ||
"issue_date": "2024-03-01", | ||
"due_date": "2024-03-10", | ||
"total_value_cents": 2564 | ||
}, | ||
{ | ||
"id": 9, | ||
"issue_date": "2024-02-01", | ||
"due_date": "2024-02-10", | ||
"total_value_cents": 1234 | ||
} | ||
] | ||
} |
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,16 @@ | ||
{ | ||
"bills": [ | ||
{ | ||
"id": 1, | ||
"issue_date": "2024-07-01", | ||
"due_date": "2024-07-10", | ||
"total_value_cents": 1000 | ||
}, | ||
{ | ||
"id": 3, | ||
"issue_date": "2024-05-01", | ||
"due_date": "2024-05-10", | ||
"total_value_cents": 3000 | ||
} | ||
] | ||
} |
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,80 @@ | ||
require 'rails_helper' | ||
|
||
describe 'user access condo show' do | ||
it 'and see fees on dashboard' do | ||
condo = create :condo | ||
resident = create(:resident, :with_residence, condo:) | ||
unit11 = resident.residence | ||
json_data = Rails.root.join('spec/support/json/two_bills.json').read | ||
fake_response = double('faraday_response', body: json_data, success?: true) | ||
allow(Faraday).to receive(:get).with("http://localhost:4000/api/v1/units/#{unit11.id}/bills").and_return(fake_response) | ||
|
||
login_as resident, scope: :resident | ||
|
||
visit condo_path condo | ||
click_on 'Faturas em Aberto' | ||
|
||
expect(page).to have_content 'Faturas em Aberto' | ||
expect(page).to have_content 'Vencimento: 10/07/2024' | ||
expect(page).to have_content 'Valor: R$ 10,00' | ||
expect(page).to have_content 'Vencimento: 10/05/2024' | ||
expect(page).to have_content 'Valor: R$ 30,00' | ||
end | ||
|
||
it 'and do not see more than 3 ordered by more recent' do | ||
condo = create :condo | ||
resident = create(:resident, :with_residence, condo:) | ||
unit11 = resident.residence | ||
json_data = Rails.root.join('spec/support/json/five_bills.json').read | ||
fake_response = double('faraday_response', body: json_data, success?: true) | ||
allow(Faraday).to receive(:get).with("http://localhost:4000/api/v1/units/#{unit11.id}/bills").and_return(fake_response) | ||
|
||
login_as resident, scope: :resident | ||
|
||
visit condo_path condo | ||
click_on 'Faturas em Aberto' | ||
|
||
expect(page).to have_content 'Faturas em Aberto' | ||
expect(page).to have_content 'Vencimento: 10/09/2024' | ||
expect(page).to have_content 'Valor: R$ 50,00' | ||
expect(page).to have_content 'Vencimento: 10/07/2024' | ||
expect(page).to have_content 'Valor: R$ 10,00' | ||
expect(page).to have_content 'Vencimento: 10/05/2024' | ||
expect(page).to have_content 'Valor: R$ 30,00' | ||
within '#bills' do | ||
expect(page).to have_content 'ver mais' | ||
end | ||
expect(page).not_to have_content 'Vencimento: 10/03/2024' | ||
expect(page).not_to have_content 'Valor: R$ 25,64' | ||
expect(page).not_to have_content 'Vencimento: 10/02/2024' | ||
expect(page).not_to have_content 'Valor: R$ 12,34' | ||
end | ||
|
||
it "and there's no data returned" do | ||
condo = create :condo | ||
resident = create(:resident, :with_residence, condo:) | ||
unit11 = resident.residence | ||
json_data = Rails.root.join('spec/support/json/empty_bills.json').read | ||
fake_response = double('faraday_response', body: json_data, success?: true) | ||
allow(Faraday).to receive(:get).with("http://localhost:4000/api/v1/units/#{unit11.id}/bills").and_return(fake_response) | ||
|
||
login_as resident, scope: :resident | ||
|
||
visit condo_path condo | ||
click_on 'Faturas em Aberto' | ||
|
||
expect(page).to have_content 'Não existem faturas em aberto.' | ||
end | ||
|
||
it 'and connection is lost with the external API' do | ||
condo = create :condo | ||
resident = create(:resident, :with_residence, condo:) | ||
|
||
login_as resident, scope: :resident | ||
|
||
visit condo_path condo | ||
click_on 'Faturas em Aberto' | ||
|
||
expect(page).to have_content 'Conexão perdida com o servidor do PagueAlugel.' | ||
end | ||
end |