-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '8344-discounted-invoices' into develop
- Loading branch information
Showing
3 changed files
with
92 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe AlaveteliPro::Invoice, type: :model do | ||
let(:invoice) { AlaveteliPro::Invoice.new(stripe_invoice) } | ||
|
||
let(:stripe_invoice) do | ||
double('Stripe::Invoice', | ||
status: 'open', charge: 'ch_123', date: 1722211200, amount_paid: 0) | ||
end | ||
|
||
let(:stripe_charge) do | ||
double('Stripe::Charge', receipt_url: 'http://example.com/receipt') | ||
end | ||
|
||
before do | ||
allow(Stripe::Charge). | ||
to receive(:retrieve).with('ch_123').and_return(stripe_charge) | ||
end | ||
|
||
describe '#open?' do | ||
it 'returns true when the status is open' do | ||
expect(invoice).to be_open | ||
end | ||
|
||
it 'returns false when the status is not open' do | ||
allow(stripe_invoice).to receive(:status).and_return('paid') | ||
expect(invoice).not_to be_open | ||
end | ||
end | ||
|
||
describe '#paid?' do | ||
it 'returns true when the status is paid and an amount has been paid' do | ||
allow(stripe_invoice).to receive(:status).and_return('paid') | ||
allow(stripe_invoice).to receive(:amount_paid).and_return(1000) | ||
expect(invoice).to be_paid | ||
end | ||
|
||
it 'returns false when 100% discounted' do | ||
allow(stripe_invoice).to receive(:status).and_return('paid') | ||
expect(invoice).not_to be_paid | ||
end | ||
|
||
it 'returns false when the status is not paid' do | ||
allow(stripe_invoice).to receive(:amount_paid).and_return(1000) | ||
expect(invoice).not_to be_paid | ||
end | ||
end | ||
|
||
describe '#date' do | ||
it 'returns a date object for the invoice' do | ||
with_env_tz 'UTC' do | ||
expect(invoice.date).to eq(Date.new(2024, 7, 29)) | ||
end | ||
end | ||
end | ||
|
||
describe '#charge' do | ||
it 'returns a Stripe::Charge object' do | ||
expect(invoice.charge).to eq(stripe_charge) | ||
end | ||
|
||
it 'memoizes the Stripe::Charge object' do | ||
expect(Stripe::Charge).to receive(:retrieve).once.with('ch_123') | ||
2.times { invoice.charge } | ||
end | ||
end | ||
|
||
describe '#receipt_url' do | ||
it 'delegates receipt_url to the charge' do | ||
expect(invoice.receipt_url).to eq('http://example.com/receipt') | ||
end | ||
|
||
it 'returns nil when there is no charge' do | ||
allow(stripe_invoice).to receive(:charge).and_return(nil) | ||
expect(invoice.receipt_url).to be_nil | ||
end | ||
end | ||
|
||
describe '#method_missing' do | ||
it 'forwards missing methods to the original object' do | ||
allow(stripe_invoice). | ||
to receive(:some_missing_method).and_return('result') | ||
expect(invoice.some_missing_method).to eq('result') | ||
end | ||
end | ||
end |