bankster-transaction 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13233f67cf124e55da18ba4f729de47db24fe375
4
- data.tar.gz: 3969267143d63497d34c88077db153c5c101339b
3
+ metadata.gz: 860a2733dc4a0ee55294c9654cc38deacc22fb53
4
+ data.tar.gz: 7ea23ca5d57b7ad1856c88725cbbca5df3a2cf69
5
5
  SHA512:
6
- metadata.gz: 8cf75dcceee8ca6b8fee59b9d685ee0c333733bc63ca94d68b3f4775a9186edc4c51a198ffb2cba326079a535a22012ee5920e18d18c28625b5d251d47909348
7
- data.tar.gz: c7ff5f40bf5368064778f07ac7eb9c77eaec58b776d7fecffff0468994b64f52e8800b11229fc3e9c54df1ad2d7e98e09ac3ef67bd9016ab1f0c6d4e52e79340
6
+ metadata.gz: d41c7634a3a7167d90697e15518d4aa9b3e19a309ae40a21340094c1a25d4887d9579f8963a207e980c4edf2f9ec69056b5f5639ecf6fe87e070577c22e0c198
7
+ data.tar.gz: d0a79ee09f26cfdc3587dbb10abc2bb3517c21ada73efd0d6c3cf44ddbdcaac7ebe4b0c2f7293d174209717bd3a4df957ae2a7ab3e60b631918cae4dae314b6b
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'bankster-transaction'
7
- spec.version = '0.1.1'
7
+ spec.version = '0.1.2'
8
8
  spec.authors = ['Roman Lehnert']
9
9
  spec.email = ['roman.lehnert@googlemail.com']
10
10
 
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
22
22
  end
23
23
 
24
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ spec.files = `git ls-files -z`.split("\x0")
25
25
  spec.bindir = 'exe'
26
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
27
  spec.require_paths = ['lib']
@@ -0,0 +1,29 @@
1
+ FactoryGirl.define do
2
+ factory :transaction, class: Bankster::Transaction do
3
+ skip_create
4
+
5
+ name 'Max Mustermann'
6
+ iban 'DE123'
7
+ bic 'ASD'
8
+ type :credit_tansfer
9
+ purpose 'my purpose'
10
+ amount Money.new(123, "EUR")
11
+ booking_date Date.today
12
+ valutation_date Date.today
13
+ end
14
+
15
+ factory :transaction_api_response, class: Hash do
16
+ skip_create
17
+
18
+ name 'Max Mustermann'
19
+ type 'credit_transfer'
20
+ purpose 'my purpose'
21
+ iban 'DE123'
22
+ bic 'ASD'
23
+ amount {{ 'cents' => "123", 'currency' => "EUR" }}
24
+ booking_date Date.today.iso8601
25
+ valutation_date Date.today.iso8601
26
+
27
+ initialize_with { attributes.stringify_keys }
28
+ end
29
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'transaction_api_response factory' do
4
+ subject { FactoryGirl.create(:transaction_api_response) }
5
+
6
+ it 'validates against the json schema' do
7
+ expect(subject.to_json).to match_json_schema(:transaction_schema, strict: true)
8
+ end
9
+ end
@@ -0,0 +1,124 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bankster::Representers::TransactionRepresenter do
4
+ describe 'creation of json from multiple transactions' do
5
+ let(:transaction_1) { FactoryGirl.build(:transaction, amount: Money.eur(123)) }
6
+ let(:transaction_2) { FactoryGirl.build(:transaction, amount: Money.eur(123)) }
7
+ let(:transactions) { [transaction_1, transaction_2] }
8
+ subject { described_class.for_collection.prepare(transactions) }
9
+
10
+ it 'creates json that matches the schema' do
11
+ expect(subject.to_json).to match_json_schema(:transactions_schema, strict: true)
12
+ end
13
+ end
14
+
15
+ describe 'creation of multiple bankster transactions from a collection api response' do
16
+ let(:transaction_1) { FactoryGirl.build(:transaction, amount: Money.eur(123)) }
17
+ let(:transaction_2) { FactoryGirl.build(:transaction, amount: Money.eur(345)) }
18
+ let(:transactions) { [transaction_1, transaction_2] }
19
+ let(:api_response) { described_class.for_collection.prepare(transactions).to_json }
20
+
21
+ it 'parses collections and returns transaction objects' do
22
+ parsed_transactions = [].extend(Bankster::Representers::TransactionRepresenter.for_collection).from_json(api_response)
23
+ expect(parsed_transactions.first).to be_a(Bankster::Transaction)
24
+ expect(parsed_transactions.last).to be_a(Bankster::Transaction)
25
+ expect(parsed_transactions.count).to eql(2)
26
+ expect(parsed_transactions.first.amount).to eql(transaction_1.amount)
27
+ expect(parsed_transactions.last.amount).to eql(transaction_2.amount)
28
+ end
29
+ end
30
+
31
+ describe 'creation of json from a Bankster::Transaction' do
32
+ let(:transaction) { FactoryGirl.build(:transaction, amount: Money.eur(123)) }
33
+ subject { transaction.extend(described_class) }
34
+
35
+ it 'creates json that matches the schema' do
36
+ expect(subject.to_json).to match_json_schema(:transaction_schema, strict: true)
37
+ end
38
+
39
+ describe 'attributes' do
40
+ let(:json) { JSON.parse(subject.to_json) }
41
+
42
+ it 'represents the amount as a hash with cents and currency' do
43
+ expect(json['amount']['cents']).to eql("123")
44
+ expect(json['amount']['currency']).to eql("EUR")
45
+ end
46
+
47
+ it 'represents the purpose' do
48
+ expect(json['purpose']).to eql(transaction.purpose)
49
+ end
50
+
51
+ it 'represents the iban' do
52
+ expect(json['iban']).to eql(transaction.iban)
53
+ end
54
+
55
+ it 'represents the bic' do
56
+ expect(json['bic']).to eql(transaction.bic)
57
+ end
58
+
59
+ it 'represents the name' do
60
+ expect(json['name']).to eql(transaction.name)
61
+ end
62
+
63
+ it 'represents the type' do
64
+ expect(json['type']).to eql(transaction.type.to_s)
65
+ end
66
+
67
+ it 'represents the booking date as a iso 8609 string' do
68
+ expect(json['booking_date']).to eql(Date.today.iso8601)
69
+ end
70
+
71
+ it 'represents the valutation date as a iso 8609 string' do
72
+ expect(json['valutation_date']).to eql(Date.today.iso8601)
73
+ end
74
+ end
75
+ end
76
+
77
+ describe 'creation of a Bankster::Transaction from json' do
78
+ let(:api_response) { FactoryGirl.build(:transaction_api_response) }
79
+ let(:subject) { Bankster::Transaction.new.extend(described_class) }
80
+
81
+ before do
82
+ subject.from_json(api_response.to_json)
83
+ end
84
+
85
+ describe 'attributes' do
86
+ it 'converts the money hash with cents and currency to a Money object' do
87
+ expect(subject.amount).to eql(
88
+ Money.new(
89
+ api_response['amount']['cents'],
90
+ api_response['amount']['currency']
91
+ )
92
+ )
93
+ end
94
+
95
+ it 'represents the purpose' do
96
+ expect(subject.purpose).to eql(api_response['purpose'])
97
+ end
98
+
99
+ it 'represents the name' do
100
+ expect(subject.name).to eql(api_response['name'])
101
+ end
102
+
103
+ it 'represents the iban' do
104
+ expect(subject.iban).to eql(api_response['iban'])
105
+ end
106
+
107
+ it 'represents the bic' do
108
+ expect(subject.bic).to eql(api_response['bic'])
109
+ end
110
+
111
+ it 'converts the type from a string to a symbol' do
112
+ expect(subject.type).to eql(api_response['type'].to_sym)
113
+ end
114
+
115
+ it 'converts the booking date from a iso 8609 string to a date object' do
116
+ expect(subject.booking_date).to eql(Date.parse(api_response['booking_date']))
117
+ end
118
+
119
+ it 'converts the valutation date from a iso 8609 string to a date object' do
120
+ expect(subject.valutation_date).to eql(Date.parse(api_response['valutation_date']))
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'bankster_shared'
3
+ require 'byebug'
4
+ require 'factory_girl'
5
+ require 'json-schema-rspec'
6
+
7
+ RSpec.configure do |config|
8
+
9
+ Dir[File.dirname(__FILE__) + '/../lib/schemas/*.json'].each do |file|
10
+ config.json_schemas[File.basename(file, ".json").to_sym] = file
11
+ end
12
+ config.include JSON::SchemaMatchers
13
+
14
+ config.include FactoryGirl::Syntax::Methods
15
+ FactoryGirl.find_definitions
16
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bankster-transaction
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Lehnert
@@ -174,6 +174,10 @@ files:
174
174
  - lib/representers/transactions_representer.rb
175
175
  - lib/schemas/transaction_schema.json
176
176
  - lib/schemas/transactions_schema.json
177
+ - spec/factories/transactions_factory.rb
178
+ - spec/factories/transactions_factory_spec.rb
179
+ - spec/representers/transaction_representer_spec.rb
180
+ - spec/spec_helper.rb
177
181
  homepage: http://bankster.io/
178
182
  licenses:
179
183
  - MIT