myfinance 0.7.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -2
- data/CHANGELOG.md +15 -0
- data/Gemfile.lock +1 -1
- data/README.md +304 -1
- data/lib/myfinance.rb +12 -0
- data/lib/myfinance/client.rb +16 -0
- data/lib/myfinance/entities/bank_statement.rb +16 -0
- data/lib/myfinance/entities/credit_card.rb +19 -0
- data/lib/myfinance/entities/credit_card_collection.rb +11 -0
- data/lib/myfinance/entities/credit_card_transaction.rb +26 -0
- data/lib/myfinance/entities/credit_card_transaction_collection.rb +11 -0
- data/lib/myfinance/entities/financial_account.rb +1 -1
- data/lib/myfinance/entities/payable_account_collection.rb +14 -0
- data/lib/myfinance/entities/receivable_account_collection.rb +14 -0
- data/lib/myfinance/entities/reconcile_collection.rb +30 -0
- data/lib/myfinance/resources/bank_statement.rb +20 -0
- data/lib/myfinance/resources/category.rb +16 -0
- data/lib/myfinance/resources/classification_center.rb +1 -1
- data/lib/myfinance/resources/credit_card.rb +47 -0
- data/lib/myfinance/resources/credit_card_transaction.rb +47 -0
- data/lib/myfinance/resources/financial_account.rb +48 -7
- data/lib/myfinance/resources/financial_transaction.rb +13 -2
- data/lib/myfinance/resources/person.rb +1 -1
- data/lib/myfinance/resources/reconcile.rb +20 -0
- data/lib/myfinance/version.rb +1 -1
- data/spec/lib/myfinance/client_spec.rb +21 -0
- data/spec/lib/myfinance/entities/credit_card_collection_spec.rb +23 -0
- data/spec/lib/myfinance/entities/credit_card_spec.rb +7 -0
- data/spec/lib/myfinance/entities/credit_card_transaction_collection_spec.rb +21 -0
- data/spec/lib/myfinance/entities/credit_card_transaction_spec.rb +8 -0
- data/spec/lib/myfinance/entities/reconcile_collection_spec.rb +20 -0
- data/spec/lib/myfinance/resources/bank_statement_spec.rb +53 -0
- data/spec/lib/myfinance/resources/category_spec.rb +24 -3
- data/spec/lib/myfinance/resources/classification_center_spec.rb +12 -5
- data/spec/lib/myfinance/resources/credit_card_spec.rb +142 -0
- data/spec/lib/myfinance/resources/credit_card_transaction_spec.rb +162 -0
- data/spec/lib/myfinance/resources/financial_transaction_spec.rb +27 -2
- data/spec/lib/myfinance/resources/payable_account_spec.rb +131 -15
- data/spec/lib/myfinance/resources/person_spec.rb +16 -4
- data/spec/lib/myfinance/resources/receivable_account_spec.rb +132 -15
- data/spec/lib/myfinance/resources/reconcile_spec.rb +33 -0
- data/spec/support/bank_statements/extrato.ofx +207 -0
- metadata +35 -2
@@ -32,7 +32,7 @@ module Myfinance
|
|
32
32
|
def find_by(params)
|
33
33
|
values = params.map { |k,v| "search[#{k}]=#{v}" }.join("&")
|
34
34
|
|
35
|
-
http.get("/people?#{values}", body: {}) do |response|
|
35
|
+
http.get(URI.encode("/people?#{values}"), body: {}) do |response|
|
36
36
|
respond_with_collection(response)
|
37
37
|
end
|
38
38
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Myfinance
|
2
|
+
module Resources
|
3
|
+
class Reconcile < Base
|
4
|
+
def reconcile(entity_id, financial_accounts_ids = [], financial_transactions_ids = [])
|
5
|
+
body = { selected_financial_account_ids: financial_accounts_ids,
|
6
|
+
selected_financial_transaction_ids: financial_transactions_ids }
|
7
|
+
|
8
|
+
http.post(path(entity_id), body: body) do |response|
|
9
|
+
respond_with_collection(response)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def path(entity_id)
|
16
|
+
"/entities/#{entity_id}/reconciles"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/myfinance/version.rb
CHANGED
@@ -124,4 +124,25 @@ describe Myfinance::Client do
|
|
124
124
|
subject.taxes
|
125
125
|
end
|
126
126
|
end
|
127
|
+
|
128
|
+
describe "#credit_cards" do
|
129
|
+
it "instantiates a new Myfinance::Resources::CreditCard" do
|
130
|
+
expect(Myfinance::Resources::CreditCard).to receive(:new).with(subject.http)
|
131
|
+
subject.credit_cards
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "#credit_card_transactions" do
|
136
|
+
it "instantiates a new Myfinance::Resources::CreditCardTransaction" do
|
137
|
+
expect(Myfinance::Resources::CreditCardTransaction).to receive(:new).with(subject.http)
|
138
|
+
subject.credit_card_transactions
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe "#reconciles" do
|
143
|
+
it "instantiates a new Myfinance::Resources::Reconcile" do
|
144
|
+
expect(Myfinance::Resources::Reconcile).to receive(:new).with(subject.http)
|
145
|
+
subject.reconciles
|
146
|
+
end
|
147
|
+
end
|
127
148
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Myfinance::Entities::CreditCardCollection do
|
4
|
+
let(:entity_klass) { described_class }
|
5
|
+
|
6
|
+
let(:params) { double(headers: {}, parsed_body: [{}]) }
|
7
|
+
|
8
|
+
subject { described_class.new(params) }
|
9
|
+
|
10
|
+
context "#build" do
|
11
|
+
it "returns order collection" do
|
12
|
+
expect(subject.build).to be_a(entity_klass)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns order" do
|
16
|
+
subject.build
|
17
|
+
expect(subject.collection.count).to eq(1)
|
18
|
+
expect(
|
19
|
+
subject.collection.first
|
20
|
+
).to be_a(Myfinance::Entities::CreditCard)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Myfinance::Entities::CreditCard do
|
4
|
+
it_behaves_like "entity_attributes", [:created_at, :id, :name, :updated_at, :entity_id, :person_id, :flag,
|
5
|
+
:flag_image_url, :observation, :classification_center_id, :category_id,
|
6
|
+
:closing_day, :expiration_day]
|
7
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Myfinance::Entities::CreditCardTransactionCollection do
|
4
|
+
let(:entity_klass) { described_class }
|
5
|
+
|
6
|
+
let(:params) { double(headers: {}, parsed_body: [{}]) }
|
7
|
+
|
8
|
+
subject { described_class.new(params) }
|
9
|
+
|
10
|
+
context "#build" do
|
11
|
+
it "returns order collection" do
|
12
|
+
expect(subject.build).to be_a(entity_klass)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns order" do
|
16
|
+
subject.build
|
17
|
+
expect(subject.collection.count).to eq(1)
|
18
|
+
expect(subject.collection.first).to be_a(Myfinance::Entities::CreditCardTransaction)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Myfinance::Entities::CreditCardTransaction do
|
4
|
+
it_behaves_like "entity_attributes", [:credit_card_invoice_id, :classification_center_id, :category_id, :amount,
|
5
|
+
:description, :occurred_at, :type, :document, :observation, :created_at,
|
6
|
+
:updated_at, :invoice_payment, :excel_import_id, :financial_account_id,
|
7
|
+
:person_id, :moved, :recurrence_id, :indexed_at, :credit_card_id, :id]
|
8
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Myfinance::Entities::ReconcileCollection do
|
4
|
+
let(:entity_klass) { described_class }
|
5
|
+
|
6
|
+
let(:params) { double(headers: {}, parsed_body: [{}]) }
|
7
|
+
|
8
|
+
subject { described_class.new(params) }
|
9
|
+
|
10
|
+
context "#build" do
|
11
|
+
it "returns order collection" do
|
12
|
+
expect(subject.build).to be_a(entity_klass)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns order" do
|
16
|
+
subject.build
|
17
|
+
expect(subject.collection.count).to eq(0)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Myfinance::Resources::BankStatement, vcr: true do
|
4
|
+
let(:entity_id) { 3_798 }
|
5
|
+
let(:deposit_account_id) { 14_268 }
|
6
|
+
let(:bank_statement_id) { 18_213 }
|
7
|
+
let(:bank_statement_klass) { Myfinance::Entities::BankStatement }
|
8
|
+
let(:file) { File.open("spec/support/bank_statements/#{file_name}", "r") }
|
9
|
+
let(:file_name) { "extrato.ofx" }
|
10
|
+
let(:request_error) { Myfinance::RequestError }
|
11
|
+
|
12
|
+
describe "#import" do
|
13
|
+
subject { client.bank_statements.import(entity_id, deposit_account_id, file) }
|
14
|
+
|
15
|
+
it "returns a BankStatement" do
|
16
|
+
expect(subject).to be_a(bank_statement_klass)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns imported BankStatement" do
|
20
|
+
expect(subject.file_file_name).to eq(file_name)
|
21
|
+
expect(subject.created_at).not_to eq(nil)
|
22
|
+
end
|
23
|
+
|
24
|
+
context "with invalid file" do
|
25
|
+
subject { client.bank_statements.import(entity_id, deposit_account_id, "diretorio/que/nao/existe/arquivo.ofx") }
|
26
|
+
|
27
|
+
it "returns 500 error code" do
|
28
|
+
expect { subject }.to raise_error(request_error) do |e|
|
29
|
+
expect(e.code).to eq(500)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#status" do
|
36
|
+
subject { client.bank_statements.status(entity_id, deposit_account_id, bank_statement_id) }
|
37
|
+
|
38
|
+
it "returns a BankStatement" do
|
39
|
+
expect(subject).to be_a(bank_statement_klass)
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when invalid ID" do
|
43
|
+
subject { client.bank_statements.status(entity_id, deposit_account_id, nil) }
|
44
|
+
|
45
|
+
it "returns 404 not found error" do
|
46
|
+
expect { subject }.to raise_error(request_error) do |e|
|
47
|
+
expect(e.code).to eq(404)
|
48
|
+
expect(e.message).to eq("Not Found")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -48,6 +48,29 @@ describe Myfinance::Resources::Category, vcr: true do
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
+
describe "#find_by" do
|
52
|
+
context "when success" do
|
53
|
+
it "find categories by attributes" do
|
54
|
+
result = client.categories.find_by({ name: "Alimentação" })
|
55
|
+
expect(result).to be_a(Myfinance::Entities::CategoryCollection)
|
56
|
+
expect(result.collection.first).to be_a(entity_klass)
|
57
|
+
expect(result.collection.first.name).to eql("Alimentação")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "when error" do
|
62
|
+
let(:client) { Myfinance.client("") }
|
63
|
+
|
64
|
+
it "raises Myfinance::RequestError with 401 status code" do
|
65
|
+
expect {
|
66
|
+
client.categories.find_by({})
|
67
|
+
}.to raise_error(Myfinance::RequestError) do |error|
|
68
|
+
expect(error.code).to eql(401)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
51
74
|
describe "#create" do
|
52
75
|
let(:params) { { name: "Category 1" } }
|
53
76
|
|
@@ -89,9 +112,7 @@ describe Myfinance::Resources::Category, vcr: true do
|
|
89
112
|
end
|
90
113
|
|
91
114
|
it "raises Myfinance::RequestError with 422 status core" do
|
92
|
-
expect {
|
93
|
-
result = client.categories.update(548083, { name: "" })
|
94
|
-
}.to raise_error(Myfinance::RequestError) do |error|
|
115
|
+
expect { client.categories.update(548083, { name: "" }) }.to raise_error(Myfinance::RequestError) do |error|
|
95
116
|
expect(error.code).to eql(422)
|
96
117
|
end
|
97
118
|
end
|
@@ -54,17 +54,24 @@ describe Myfinance::Resources::ClassificationCenter, vcr: true do
|
|
54
54
|
|
55
55
|
describe "#find_by" do
|
56
56
|
context "when success" do
|
57
|
-
let(:params) do
|
58
|
-
{ entity_id_equals: 3798, name_equals: "Centro de Custo Tal" }
|
59
|
-
end
|
60
|
-
|
61
57
|
it "find a classification centers by name successfully" do
|
62
|
-
result = client.classification_centers.find_by(
|
58
|
+
result = client.classification_centers.find_by(
|
59
|
+
{ entity_id_equals: 3798, name_equals: "Centro de Custo Tal" }
|
60
|
+
)
|
63
61
|
expect(result).to be_a(entity_collection)
|
64
62
|
expect(result.collection.first).to be_a(entity_klass)
|
65
63
|
expect(result.collection.first.name).to eq("Centro de Custo Tal")
|
66
64
|
end
|
67
65
|
|
66
|
+
it "find a classification centers with special characters" do
|
67
|
+
result = client.classification_centers.find_by(
|
68
|
+
{ entity_id_equals: 3798, name_equals: "Socialização 2" }
|
69
|
+
)
|
70
|
+
expect(result).to be_a(entity_collection)
|
71
|
+
expect(result.collection.first).to be_a(entity_klass)
|
72
|
+
expect(result.collection.first.name).to eq("Socialização 2")
|
73
|
+
end
|
74
|
+
|
68
75
|
it "returns a empty classification center successfully" do
|
69
76
|
result = client.classification_centers.find_by(
|
70
77
|
{ entity_id_equals: 3798, name_equals: "Any" }
|
@@ -0,0 +1,142 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Myfinance::Resources::CreditCard, vcr: true do
|
4
|
+
let(:cc_klass) { Myfinance::Entities::CreditCard }
|
5
|
+
let(:entity_id) { 3798 }
|
6
|
+
let(:cc_id) { 44 }
|
7
|
+
let(:credit_cards) { client.credit_cards }
|
8
|
+
let(:request_error) { Myfinance::RequestError }
|
9
|
+
|
10
|
+
describe "#find_all" do
|
11
|
+
context "when successful" do
|
12
|
+
subject { credit_cards.find_all(entity_id) }
|
13
|
+
before :each do
|
14
|
+
subject.build
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns a 200 OK response code" do
|
18
|
+
expect(subject.response.code).to eq(200)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns a collection of CreditCards" do
|
22
|
+
expect(subject).to be_a(Myfinance::Entities::CreditCardCollection)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns credit cards inside collection" do
|
26
|
+
expect(subject.collection.first).to be_a(cc_klass)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when supplying invalid IDs" do
|
31
|
+
subject { credit_cards.find_all(nil) }
|
32
|
+
it "raises not found error with 404" do
|
33
|
+
expect { subject }.to raise_error(request_error) do |e|
|
34
|
+
expect(e.code).to eq(404)
|
35
|
+
expect(e.message).to eq("Not Found")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#find" do
|
42
|
+
context "when successful" do
|
43
|
+
subject { credit_cards.find(entity_id, cc_id) }
|
44
|
+
|
45
|
+
it "returns a CreditCard" do
|
46
|
+
expect(subject).to be_a(cc_klass)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when supplying invalid IDs" do
|
51
|
+
subject { credit_cards.find(nil, nil) }
|
52
|
+
|
53
|
+
it "raises not found error with 404" do
|
54
|
+
expect { subject }.to raise_error(request_error) do |e|
|
55
|
+
expect(e.code).to eq(404)
|
56
|
+
expect(e.message).to eq("Not Found")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "#create" do
|
63
|
+
context "when successful" do
|
64
|
+
let(:params) { { name: "Nubank", flag: "MasterCard", closing_day: 20, expiration_day: 02 } }
|
65
|
+
subject { credit_cards.create(entity_id, params) }
|
66
|
+
|
67
|
+
it "creates a CreditCard" do
|
68
|
+
expect(subject).to be_a(cc_klass)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "contains given params" do
|
72
|
+
expect(subject).to have_attributes(params)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "when given invalid params" do
|
77
|
+
let(:params) { { name: "Nubank", flag: "BandeiraDeWesteros", closing_day: 20, expiration_day: 02 } }
|
78
|
+
subject { credit_cards.create(entity_id, params) }
|
79
|
+
|
80
|
+
it "returns 422 Unprocessable Entity" do
|
81
|
+
expect { subject }.to raise_error(request_error) do |e|
|
82
|
+
expect(e.code).to eq(422)
|
83
|
+
expect(e.message).to eq("Unprocessable Entity")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "#update" do
|
90
|
+
context "when successful" do
|
91
|
+
let(:params) { { name: "Neon", flag: "Visa", closing_day: 20, expiration_day: 02 } }
|
92
|
+
subject { credit_cards.update(entity_id, cc_id, params) }
|
93
|
+
|
94
|
+
it "updates a CreditCard" do
|
95
|
+
expect(subject).to be_a(cc_klass)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "contains given params" do
|
99
|
+
expect(subject).to have_attributes(params)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context "when given invalid params" do
|
104
|
+
let(:params) { { name: "Nubank", flag: "BandeiraDeWesteros", closing_day: 20, expiration_day: 02 } }
|
105
|
+
subject { credit_cards.update(entity_id, cc_id, params) }
|
106
|
+
|
107
|
+
it "returns 422 Unprocessable Entity" do
|
108
|
+
expect { subject }.to raise_error(request_error) do |e|
|
109
|
+
expect(e.code).to eq(422)
|
110
|
+
expect(e.message).to eq("Unprocessable Entity")
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "#destroy" do
|
117
|
+
let(:params) { { name: "Nubank", flag: "MasterCard", closing_day: 20, expiration_day: 02 } }
|
118
|
+
let(:new_cc) { credit_cards.create(entity_id, params) }
|
119
|
+
|
120
|
+
context "when successful" do
|
121
|
+
before :each do
|
122
|
+
credit_cards.destroy(entity_id, new_cc.id)
|
123
|
+
end
|
124
|
+
|
125
|
+
it "does not find deleted CreditCard" do
|
126
|
+
expect { credit_cards.find(entity_id, new_cc.id) }.to raise_error(request_error) do |e|
|
127
|
+
expect(e.code).to eq(404)
|
128
|
+
expect(e.message).to eq("Not Found")
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context "when given invalid ID" do
|
134
|
+
it "returns 404 Not Found" do
|
135
|
+
expect { credit_cards.destroy(entity_id, 424242) }.to raise_error(request_error) do |e|
|
136
|
+
expect(e.code).to eq(404)
|
137
|
+
expect(e.message).to eq("Not Found")
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,162 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Myfinance::Resources::CreditCardTransaction, vcr: true do
|
4
|
+
let(:cct_klass) { Myfinance::Entities::CreditCardTransaction }
|
5
|
+
let(:entity_id) { 3906 }
|
6
|
+
let(:cc_id) { 73 }
|
7
|
+
let(:cct_id) { 319529 }
|
8
|
+
let(:year) { "2017" }
|
9
|
+
let(:month) { "04" }
|
10
|
+
let(:credit_card_transactions) { client.credit_card_transactions }
|
11
|
+
let(:request_error) { Myfinance::RequestError }
|
12
|
+
let(:client) { Myfinance.client("0657bac70fdf5c06ce822719568f3636a9a07b87ba617ec7", 3682) }
|
13
|
+
|
14
|
+
describe "#find_all" do
|
15
|
+
context "when successful" do
|
16
|
+
subject { credit_card_transactions.find_all(entity_id, cc_id, year, month) }
|
17
|
+
before :each do
|
18
|
+
subject.build
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns a 200 OK response code" do
|
22
|
+
expect(subject.response.code).to eq(200)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns a collection of CreditCardTransactions" do
|
26
|
+
expect(subject).to be_a(Myfinance::Entities::CreditCardTransactionCollection)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns credit cards inside collection" do
|
30
|
+
expect(subject.collection.first).to be_a(cct_klass)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "when supplying invalid IDs" do
|
35
|
+
subject { credit_card_transactions.find_all(nil, nil, 2017, "99") }
|
36
|
+
it "raises not found error with 404" do
|
37
|
+
expect { subject }.to raise_error(request_error) do |e|
|
38
|
+
expect(e.code).to eq(404)
|
39
|
+
expect(e.message).to eq("Not Found")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#find" do
|
46
|
+
context "when successful" do
|
47
|
+
subject { credit_card_transactions.find(entity_id, cc_id, cct_id) }
|
48
|
+
|
49
|
+
it "returns a CreditCardTransaction" do
|
50
|
+
expect(subject).to be_a(cct_klass)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "when supplying invalid IDs" do
|
55
|
+
subject { credit_card_transactions.find(nil, 666, 99999) }
|
56
|
+
|
57
|
+
it "raises not found error with 404" do
|
58
|
+
expect { subject }.to raise_error(request_error) do |e|
|
59
|
+
expect(e.code).to eq(404)
|
60
|
+
expect(e.message).to eq("Not Found")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "#create" do
|
67
|
+
context "when successful" do
|
68
|
+
let(:params) do
|
69
|
+
{ amount: BigDecimal.new(199), occurred_at: Date.new(2017, 1, 1), description: "O Guia", credit_card_id: cc_id }
|
70
|
+
end
|
71
|
+
subject { credit_card_transactions.create(entity_id, cc_id, params) }
|
72
|
+
|
73
|
+
it "creates a CreditCardTransaction" do
|
74
|
+
expect(subject).to be_a(cct_klass)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "contains given params" do
|
78
|
+
expect(subject).to have_attributes(params)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "when given invalid params" do
|
83
|
+
let(:params) { { amount: BigDecimal.new(199), description: "O Guia" } }
|
84
|
+
subject { credit_card_transactions.create(entity_id, cc_id, params) }
|
85
|
+
|
86
|
+
it "returns 422 Unprocessable Entity" do
|
87
|
+
expect { subject }.to raise_error(request_error) do |e|
|
88
|
+
expect(e.code).to eq(422)
|
89
|
+
expect(e.message).to eq("Unprocessable Entity")
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "#update" do
|
96
|
+
let(:params) { { amount: BigDecimal.new(999), description: "O Guia Vol. II" } }
|
97
|
+
subject { credit_card_transactions.update(entity_id, cc_id, cct_id, params) }
|
98
|
+
|
99
|
+
it "updates a CreditCardTransaction" do
|
100
|
+
expect(subject).to be_a(cct_klass)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "contains given params" do
|
104
|
+
expect(subject).to have_attributes(params)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "#destroy" do
|
109
|
+
let(:params) do
|
110
|
+
{ amount: BigDecimal.new(199), occurred_at: Date.new(2017, 1, 1), description: "O Guia Obsoleto", credit_card_id: cc_id }
|
111
|
+
end
|
112
|
+
let(:new_cct) { credit_card_transactions.create(entity_id, cc_id, params) }
|
113
|
+
|
114
|
+
context "when successful" do
|
115
|
+
before :each do
|
116
|
+
credit_card_transactions.destroy(entity_id, cc_id, new_cct.id)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "does not find deleted CreditCardTransaction" do
|
120
|
+
expect { credit_card_transactions.find(entity_id, cc_id, new_cct.id) }.to raise_error(request_error) do |e|
|
121
|
+
expect(e.code).to eq(404)
|
122
|
+
expect(e.message).to eq("Not Found")
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context "when given invalid ID" do
|
128
|
+
it "returns 404 Not Found" do
|
129
|
+
expect { credit_card_transactions.destroy(entity_id, 6666, 424242) }.to raise_error(request_error) do |e|
|
130
|
+
expect(e.code).to eq(404)
|
131
|
+
expect(e.message).to eq("Not Found")
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe "#destroy_parcelled" do
|
138
|
+
let(:params) do
|
139
|
+
{ amount: BigDecimal.new(199), occurred_at: Date.new(2017, 1, 1), number_of_parcels: 2, credit_card_id: cc_id }
|
140
|
+
end
|
141
|
+
let(:new_cct) { credit_card_transactions.create(entity_id, cc_id, params) }
|
142
|
+
|
143
|
+
before :each do
|
144
|
+
credit_card_transactions.destroy_parcelled(entity_id, cc_id, new_cct.id)
|
145
|
+
end
|
146
|
+
|
147
|
+
it "does not find first CreditCardTransaction" do
|
148
|
+
expect { credit_card_transactions.find(entity_id, cc_id, new_cct.id) }.to raise_error(request_error) do |e|
|
149
|
+
expect(e.code).to eq(404)
|
150
|
+
expect(e.message).to eq("Not Found")
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
it "does not find second CreditCardTransaction" do
|
155
|
+
expect { credit_card_transactions.find(entity_id, cc_id, new_cct.id + 1) }.to raise_error(request_error) do |e|
|
156
|
+
expect(e.code).to eq(404)
|
157
|
+
expect(e.message).to eq("Not Found")
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
end
|