fio_api 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +26 -0
  3. data/.travis.yml +7 -2
  4. data/Gemfile +9 -12
  5. data/README.rdoc +8 -3
  6. data/Rakefile +11 -13
  7. data/VERSION +1 -1
  8. data/fio_api.gemspec +57 -33
  9. data/lib/base/account.rb +2 -2
  10. data/lib/base/deserializers/import_response_deserializer.rb +51 -0
  11. data/lib/base/deserializers/list_response_deserializer.rb +47 -36
  12. data/lib/base/list.rb +9 -14
  13. data/lib/base/payment.rb +40 -0
  14. data/lib/base/payments/domestic.rb +13 -0
  15. data/lib/base/payments/status.rb +8 -0
  16. data/lib/base/payments/xml/item.rb +41 -0
  17. data/lib/base/payments/xml/root.rb +30 -0
  18. data/lib/base/request.rb +4 -54
  19. data/lib/base/transaction.rb +2 -2
  20. data/lib/base.rb +2 -6
  21. data/lib/fio_api.rb +16 -10
  22. data/lib/utils/hash.rb +2 -2
  23. data/spec/base/account_spec.rb +4 -8
  24. data/spec/base/deserializers/import_response_deserializer_spec.rb +41 -0
  25. data/spec/base/deserializers/list_response_deserializer_spec.rb +48 -59
  26. data/spec/base/list_spec.rb +36 -23
  27. data/spec/base/payment_spec.rb +38 -0
  28. data/spec/base/payments/domestic_spec.rb +14 -0
  29. data/spec/base/payments/status_spec.rb +13 -0
  30. data/spec/base/payments/xml/root_spec.rb +63 -0
  31. data/spec/base/request_spec.rb +2 -49
  32. data/spec/base/transaction_spec.rb +5 -9
  33. data/spec/fio_api_spec.rb +4 -7
  34. data/spec/fixtures/vcr_cassettes/by_date_range.yml +47 -0
  35. data/spec/fixtures/vcr_cassettes/by_listing_id_and_year.yml +49 -0
  36. data/spec/fixtures/vcr_cassettes/from_last_fetch.yml +44 -0
  37. data/spec/fixtures/vcr_cassettes/import.yml +53 -0
  38. data/spec/fixtures/vcr_cassettes/invalid_import.yml +51 -0
  39. data/spec/fixtures/vcr_cassettes/set_last_fetch_date.yml +44 -0
  40. data/spec/fixtures/vcr_cassettes/set_last_fetch_id.yml +47 -0
  41. data/spec/spec_helper.rb +7 -2
  42. data/spec/utils/hash_spec.rb +10 -15
  43. metadata +70 -24
  44. data/lib/base/deserializer.rb +0 -19
  45. data/spec/base/deserializer_spec.rb +0 -12
@@ -0,0 +1,30 @@
1
+ module FioAPI
2
+ module Payments
3
+ module Xml
4
+ class Root
5
+ XSI_OPTIONS = {
6
+ 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
7
+ 'xsi:noNamespaceSchemaLocation' => 'http://www.fio.cz/schema/importIB.xsd'
8
+ }.freeze
9
+
10
+ attr_reader :payments
11
+
12
+ def initialize(payments)
13
+ @payments = payments
14
+ end
15
+
16
+ def build
17
+ @build ||= Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
18
+ xml.Import(XSI_OPTIONS) do
19
+ xml.Orders do
20
+ payments.each do |payment|
21
+ ::FioAPI::Payments::Xml::Item.new(xml, payment).build
22
+ end
23
+ end
24
+ end
25
+ end.to_xml
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
data/lib/base/request.rb CHANGED
@@ -2,70 +2,20 @@ require 'httparty'
2
2
 
3
3
  module FioAPI
4
4
  class Request < FioAPI::Base
5
- # Consant of base part of uri for requesting
6
- BASE_URI = "https://www.fio.cz/ib_api/rest/"
5
+ include HTTParty
7
6
 
8
- class << self
7
+ base_uri 'https://www.fio.cz/ib_api/rest/'
9
8
 
9
+ class << self
10
10
  # Reader for token
11
11
  def token
12
12
  @@token
13
13
  end
14
14
 
15
15
  # Setter for token
16
- def token= token
16
+ def token=(token)
17
17
  @@token = token
18
18
  end
19
19
  end
20
-
21
- attr_accessor :uri, :response_json, :deserializer
22
-
23
- # Make request to uri
24
- #
25
- # == Returns:
26
- # Request instance
27
- #
28
- def fetch
29
- self.response_json = HTTParty.get(uri, format: :json)
30
- self
31
- end
32
-
33
- # Set uri for request
34
- #
35
- # == Parameters:
36
- # args::
37
- # Parts of uri
38
- #
39
- # == Returns:
40
- # Uri string
41
- #
42
- def set_uri(*args)
43
- self.uri = construct_uri(*args)
44
- end
45
-
46
- # Reader for request response
47
- #
48
- # == Returns:
49
- # Response as a JSON or a deserialilzed response. Depends if the deserializer is set
50
- #
51
- def response
52
- @response ||= deserializer ? deserializer.deserialize(response_json) : response_json
53
- end
54
-
55
- private
56
-
57
- # Uri constructor
58
- #
59
- # == Parameters:
60
- # args::
61
- # Parts of uri
62
- #
63
- # == Returns:
64
- # Uri string
65
- #
66
- def construct_uri(*args)
67
- url_parts = args.map(&:to_s).join("/")
68
- URI::join(BASE_URI, url_parts).to_s
69
- end
70
20
  end
71
21
  end
@@ -2,7 +2,7 @@ module FioAPI
2
2
  # == Transaction class representing the Transaction entity
3
3
  class Transaction < FioAPI::Base
4
4
  attr_accessor :transaction_id, :date, :amount, :currency, :account, :account_name, :bank_code,
5
- :bank_name, :ks, :vs, :ss, :user_identification, :message_for_recipient, :transaction_type,
6
- :sender, :detail_info, :comment, :bic, :action_id
5
+ :bank_name, :ks, :vs, :ss, :user_identification, :message_for_recipient, :transaction_type,
6
+ :sender, :detail_info, :comment, :bic, :action_id
7
7
  end
8
8
  end
data/lib/base.rb CHANGED
@@ -9,12 +9,8 @@ module FioAPI
9
9
  # == Returns:
10
10
  # New object with prefilled attributes
11
11
  #
12
- def initialize(*h)
13
- if h.length == 1 && h.first.kind_of?(Hash)
14
- h.first.each { |k,v| send("#{k}=",v) }
15
- end
12
+ def initialize(*hash)
13
+ hash.first.each { |k, v| send("#{k}=", v) } if hash.length == 1 && hash.first.is_a?(Hash)
16
14
  end
17
-
18
15
  end
19
16
  end
20
-
data/lib/fio_api.rb CHANGED
@@ -1,16 +1,23 @@
1
- require "utils/hash"
2
- require "base"
3
- require "base/deserializer"
4
- require "base/account"
5
- require "base/transaction"
6
- require "base/list"
7
- require "base/request"
1
+ require 'utils/hash'
2
+ require 'tempfile'
3
+ require 'base'
4
+ require 'base/account'
5
+ require 'base/transaction'
6
+ require 'base/list'
7
+ require 'base/request'
8
+ require 'base/payment'
9
+ require 'base/payments/status'
10
+ require 'base/payments/domestic'
11
+ require 'base/payments/xml/root'
12
+ require 'base/payments/xml/item'
13
+ require 'base/deserializers/list_response_deserializer'
14
+ require 'base/deserializers/import_response_deserializer'
8
15
 
9
16
  module FioAPI
10
17
  # == Returns:
11
18
  # A string with current version of gem
12
19
  #
13
- VERSION = "0.0.1"
20
+ VERSION = '0.0.6'.freeze
14
21
 
15
22
  # Set API token for requests
16
23
  #
@@ -21,7 +28,7 @@ module FioAPI
21
28
  # == Returns:
22
29
  # Token
23
30
  #
24
- def self.token= token
31
+ def self.token=(token)
25
32
  FioAPI::Request.token = token
26
33
  end
27
34
 
@@ -34,4 +41,3 @@ module FioAPI
34
41
  FioAPI::Request.token
35
42
  end
36
43
  end
37
-
data/lib/utils/hash.rb CHANGED
@@ -10,13 +10,13 @@ class Hash
10
10
  #
11
11
  def try_path(*args)
12
12
  value = self
13
- args.each{ |arg_name| value = value.nil? ? nil : value[arg_name] }
13
+ args.each { |arg_name| value = value.nil? ? nil : value[arg_name] }
14
14
  value
15
15
  end
16
16
  end
17
17
 
18
18
  class NilClass
19
- def try_path(*args)
19
+ def try_path(*_args)
20
20
  nil
21
21
  end
22
22
  end
@@ -1,17 +1,13 @@
1
- require_relative "../spec_helper"
1
+ require_relative '../spec_helper'
2
2
 
3
3
  describe FioAPI::Account do
4
-
5
- describe "instance attributes" do
6
-
7
- [:account_id, :bank_id, :currency, :iban,:bic,:opening_balance,:closing_balance,
8
- :date_start, :date_end, :year_list, :id_list, :id_from, :id_to, :id_last_download].each do |attr|
4
+ describe 'instance attributes' do
5
+ %i[account_id bank_id currency iban bic opening_balance closing_balance
6
+ date_start date_end year_list id_list id_from id_to id_last_download].each do |attr|
9
7
 
10
8
  it "should respond to #{attr}" do
11
9
  expect(FioAPI::Account.new).to respond_to(attr)
12
10
  end
13
-
14
11
  end
15
12
  end
16
-
17
13
  end
@@ -0,0 +1,41 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe FioAPI::ImportResponseDeserializer do
4
+ describe 'instance attributes' do
5
+ it 'should respond to status' do
6
+ expect(FioAPI::ImportResponseDeserializer.new('{}', '')).to respond_to(:status)
7
+ end
8
+ end
9
+
10
+ describe 'deserialization' do
11
+ before(:each) do
12
+ @deserializer = FioAPI::ImportResponseDeserializer.new('{}', '')
13
+ end
14
+
15
+ it 'deserialize valid payment status' do
16
+ status_json = {
17
+ 'errorCode' => '0', 'idInstruction' => '153935923', 'status' => 'ok', 'sums' => {
18
+ 'sum' => { 'sumCredit' => '0', 'sumDebet' => '100.0', 'id' => 'CZK' }
19
+ }
20
+ }
21
+
22
+ result = { error_code: 0, id_instruction: 153_935_923, sum_credit: 0.0, sum_debet: 100.0, error_message: '' }
23
+ deserialized = @deserializer.send(:deserialize_import, status_json)
24
+ result.each do |attr_name, value|
25
+ expect(deserialized.send(attr_name)).to eq(value)
26
+ end
27
+ end
28
+
29
+ it 'deserialize invalid payment status' do
30
+ status_json = {
31
+ 'errorCode' => '11', 'status' => 'error', 'message' => 'Error message'
32
+ }
33
+
34
+ result = { error_code: 11, id_instruction: 0, sum_credit: 0.0, sum_debet: 0.0, error_message: 'Error message' }
35
+ deserialized = @deserializer.send(:deserialize_import, status_json)
36
+ result.each do |attr_name, value|
37
+ expect(deserialized.send(attr_name)).to eq(value)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,92 +1,81 @@
1
- require_relative "../../spec_helper"
1
+ require_relative '../../spec_helper'
2
2
 
3
3
  describe FioAPI::ListResponseDeserializer do
4
-
5
- describe "instance attributes" do
6
-
7
- it "should respond to account" do
8
- expect(FioAPI::ListResponseDeserializer.new).to respond_to(:account)
4
+ describe 'instance attributes' do
5
+ it 'should respond to account' do
6
+ expect(FioAPI::ListResponseDeserializer.new('{}', '')).to respond_to(:account)
9
7
  end
10
8
 
11
- it "should respond to transactions" do
12
- expect(FioAPI::ListResponseDeserializer.new).to respond_to(:transactions)
9
+ it 'should respond to transactions' do
10
+ expect(FioAPI::ListResponseDeserializer.new('{}', '')).to respond_to(:transactions)
13
11
  end
14
-
15
12
  end
16
13
 
17
- describe "deserialization" do
14
+ describe 'deserialization' do
18
15
  before(:each) do
19
- @deserializer = FioAPI::ListResponseDeserializer.new
16
+ @deserializer = FioAPI::ListResponseDeserializer.new('{}', '')
20
17
  end
21
18
 
22
- it "deserialize account info" do
23
- account_json = { "accountId" => "26457567988", "bankId" => "2010", "currency" => "CZK",
24
- "iban" => "CZ03345356456702600147988", "bic" => "FIOBCZPPXXX", "openingBalance" => 0.0, "closingBalance" => 11669.96,
25
- "dateStart" => "2011-01-01+0100", "dateEnd" => "2012-12-26+0100", "yearList" => 2012, "idList" => 353434,
26
- "idFrom" => 1145645683284, "idTo" => 1167566706, "idLastDownload" => 234234234234
27
- }
19
+ it 'deserialize account info' do
20
+ account_json = { 'accountId' => '26457567988', 'bankId' => '2010', 'currency' => 'CZK',
21
+ 'iban' => 'CZ03345356456702600147988', 'bic' => 'FIOBCZPPXXX', 'openingBalance' => 0.0, 'closingBalance' => 11_669.96,
22
+ 'dateStart' => '2011-01-01+0100', 'dateEnd' => '2012-12-26+0100', 'yearList' => 2012, 'idList' => 353_434,
23
+ 'idFrom' => 1_145_645_683_284, 'idTo' => 1_167_566_706, 'idLastDownload' => 234_234_234_234 }
28
24
 
29
- result = { :account_id => "26457567988", :bank_id => "2010", :currency => "CZK", :iban => "CZ03345356456702600147988",
30
- :bic => "FIOBCZPPXXX", :opening_balance => 0.0, :closing_balance => 11669.96, :date_start => "2011-01-01+0100",
31
- :date_end => "2012-12-26+0100", :year_list => 2012, :id_list => 353434, :id_from => 1145645683284,
32
- :id_to => 1167566706, :id_last_download => 234234234234 }
25
+ result = { account_id: '26457567988', bank_id: '2010', currency: 'CZK', iban: 'CZ03345356456702600147988',
26
+ bic: 'FIOBCZPPXXX', opening_balance: 0.0, closing_balance: 11_669.96, date_start: '2011-01-01+0100',
27
+ date_end: '2012-12-26+0100', year_list: 2012, id_list: 353_434, id_from: 1_145_645_683_284,
28
+ id_to: 1_167_566_706, id_last_download: 234_234_234_234 }
33
29
 
34
- deserialized = @deserializer.send(:deserialize_account, account_json)
30
+ deserialized = @deserializer.send(:deserialize_account, account_json)
35
31
 
36
- result.each do |attr_name,value|
32
+ result.each do |attr_name, value|
37
33
  expect(deserialized.send(attr_name)).to eq(value)
38
34
  end
39
35
  end
40
36
 
41
-
42
-
43
- it "deserialize transaction info" do
37
+ it 'deserialize transaction info' do
44
38
  transaction_json = {
45
- "column22" => { "value" => 1148734530, "name" => "ID pohybu", "id" => 22},
46
- "column0" => { "value" => 1340661600000, "name" => "Datum", "id" => 0},
47
- "column1" => { "value" => 1, "name" => "Objem", "id" => 1 },
48
- "column14" => { "value" => "CZK", "name" => "Mena", "id" => 14 },
49
- "column2" => { "value" => "2900233333", "name" => "Protiucet", "id" => 2 },
50
- "column10" => { "value" => "Pavel, Novak", "name" => "Nazev protiuctu", "id" => 10},
51
- "column3" => { "value" => "2010", "name" => "Kod banky", "id" => 3},
52
- "column12" => { "value" => "Fio banka, a.s.", "name" => "Nazev banky", "id" => 12 },
53
- "column4" => { "value" => "0558", "name" => "KS", "id" => 4 },
54
- "column5" => { "value" => "0558345345345", "name" => "VS", "id" => 5 },
55
- "column6" => { "value" => "055234", "name" => "SS", "id" => 6 },
56
- "column7" => { "value" => "Prikaz", "name" => "Identifikace uzivatelem", "id" => 7 },
57
- "column16" => { "value" => "Prikaz pro tomase", "name" => "Zprava pro prijemce", "id" => 16 },
58
- "column8" => { "value" => "Prijem prevodem uvnitr banky", "name" => "Typ", "id" => 8 },
59
- "column9" => { "value" => "Robin Bortlik", "name" => "Odesilatel", "id" => 9 },
60
- "column18" => { "value" => "Detail info", "name" => "Detailni informace", "id" => 18 },
61
- "column25" => { "value" => "Text", "name" => "Komentar", "id" => 25 },
62
- "column26" => { "value" => "345790", "name" => "BIC", "id" => 26 },
63
- "column17" => { "value" => 2105685816, "name" => "ID pokynu", "id" => 17}
39
+ 'column22' => { 'value' => 1_148_734_530, 'name' => 'ID pohybu', 'id' => 22 },
40
+ 'column0' => { 'value' => 1_340_661_600_000, 'name' => 'Datum', 'id' => 0 },
41
+ 'column1' => { 'value' => 1, 'name' => 'Objem', 'id' => 1 },
42
+ 'column14' => { 'value' => 'CZK', 'name' => 'Mena', 'id' => 14 },
43
+ 'column2' => { 'value' => '2900233333', 'name' => 'Protiucet', 'id' => 2 },
44
+ 'column10' => { 'value' => 'Pavel, Novak', 'name' => 'Nazev protiuctu', 'id' => 10 },
45
+ 'column3' => { 'value' => '2010', 'name' => 'Kod banky', 'id' => 3 },
46
+ 'column12' => { 'value' => 'Fio banka, a.s.', 'name' => 'Nazev banky', 'id' => 12 },
47
+ 'column4' => { 'value' => '0558', 'name' => 'KS', 'id' => 4 },
48
+ 'column5' => { 'value' => '0558345345345', 'name' => 'VS', 'id' => 5 },
49
+ 'column6' => { 'value' => '055234', 'name' => 'SS', 'id' => 6 },
50
+ 'column7' => { 'value' => 'Prikaz', 'name' => 'Identifikace uzivatelem', 'id' => 7 },
51
+ 'column16' => { 'value' => 'Prikaz pro tomase', 'name' => 'Zprava pro prijemce', 'id' => 16 },
52
+ 'column8' => { 'value' => 'Prijem prevodem uvnitr banky', 'name' => 'Typ', 'id' => 8 },
53
+ 'column9' => { 'value' => 'Robin Bortlik', 'name' => 'Odesilatel', 'id' => 9 },
54
+ 'column18' => { 'value' => 'Detail info', 'name' => 'Detailni informace', 'id' => 18 },
55
+ 'column25' => { 'value' => 'Text', 'name' => 'Komentar', 'id' => 25 },
56
+ 'column26' => { 'value' => '345790', 'name' => 'BIC', 'id' => 26 },
57
+ 'column17' => { 'value' => 2_105_685_816, 'name' => 'ID pokynu', 'id' => 17 }
64
58
  }
65
59
 
66
- result = {:date => 1340661600000, :amount => 1, :currency => "CZK", :account => "2900233333",
67
- :account_name => "Pavel, Novak", :bank_code => "2010", :bank_name => "Fio banka, a.s.",
68
- :ks => "0558", :vs => "0558345345345", :ss => "055234", :user_identification => "Prikaz",
69
- :message_for_recipient => "Prikaz pro tomase", :transaction_type => "Prijem prevodem uvnitr banky",
70
- :sender => "Robin Bortlik", :detail_info => "Detail info", :comment => "Text", :bic => "345790",
71
- :action_id => 2105685816}
60
+ result = { date: 1_340_661_600_000, amount: 1, currency: 'CZK', account: '2900233333',
61
+ account_name: 'Pavel, Novak', bank_code: '2010', bank_name: 'Fio banka, a.s.',
62
+ ks: '0558', vs: '0558345345345', ss: '055234', user_identification: 'Prikaz',
63
+ message_for_recipient: 'Prikaz pro tomase', transaction_type: 'Prijem prevodem uvnitr banky',
64
+ sender: 'Robin Bortlik', detail_info: 'Detail info', comment: 'Text', bic: '345790',
65
+ action_id: 2_105_685_816 }
72
66
 
73
67
  deserialized = @deserializer.send(:deserialize_transactions, [transaction_json])[0]
74
68
 
75
- result.each do |attr_name,value|
69
+ result.each do |attr_name, value|
76
70
  expect(deserialized.send(attr_name)).to eq(value)
77
71
  end
78
72
  end
79
73
 
80
- it "should return deserializer object with account and transactions" do
81
- @deserializer.deserialize({"accountStatement" => {"transactionList" => {"transaction" => [{}] }}} )
74
+ it 'should return deserializer object with account and transactions' do
75
+ @deserializer.deserialize('accountStatement' => { 'transactionList' => { 'transaction' => [{}] } })
82
76
  expect(@deserializer.account.class).to eq FioAPI::Account
83
77
  expect(@deserializer.transactions.class).to eq Array
84
78
  expect(@deserializer.transactions.first.class).to eq FioAPI::Transaction
85
79
  end
86
80
  end
87
81
  end
88
-
89
-
90
-
91
-
92
-
@@ -1,45 +1,58 @@
1
- require_relative "../spec_helper"
1
+ require_relative '../spec_helper'
2
2
 
3
3
  describe FioAPI::List do
4
4
  before(:each) do
5
5
  @list = FioAPI::List.new
6
- allow(HTTParty).to receive(:get) { {response: "response"} }
7
6
  end
8
7
 
9
- it "should set request with uri for date range" do
10
- date_from = Date.new(2011,1,1)
11
- date_to = Date.new(2012,11,25)
8
+ it 'should set request with uri for date range' do
9
+ date_from = Date.new(2011, 1, 1)
10
+ date_to = Date.new(2012, 11, 25)
12
11
  url = "https://www.fio.cz/ib_api/rest/periods/#{FioAPI.token}/#{date_from}/#{date_to}/transactions.json"
13
- expect(@list.by_date_range(date_from, date_to).request.uri).to eq url
12
+ VCR.use_cassette 'by_date_range', erb: true do
13
+ list = @list.by_date_range(date_from, date_to)
14
+ expect(list.request.uri.to_s).to eq url
15
+ expect(list.transactions.length).to eq 1
16
+ end
14
17
  end
15
18
 
16
- it "should set request with uri for listing_id and year" do
19
+ it 'should set request with uri for listing_id and year' do
17
20
  year = 2012
18
- id = "12345"
21
+ id = '12345'
19
22
  url = "https://www.fio.cz/ib_api/rest/by-id/#{FioAPI.token}/#{year}/#{id}/transactions.json"
20
- expect(@list.by_listing_id_and_year(id, year).request.uri).to eq url
23
+ VCR.use_cassette 'by_listing_id_and_year', erb: true do
24
+ list = @list.by_listing_id_and_year(id, year)
25
+ expect(list.request.uri.to_s).to eq url
26
+ expect(list.transactions.length).to eq 0
27
+ end
21
28
  end
22
29
 
23
- it "should set request with uri from last fetch" do
30
+ it 'should set request with uri from last fetch' do
24
31
  url = "https://www.fio.cz/ib_api/rest/last/#{FioAPI.token}/transactions.json"
25
- expect(@list.from_last_fetch.request.uri).to eq url
32
+ VCR.use_cassette 'from_last_fetch', erb: true do
33
+ list = @list.from_last_fetch
34
+ expect(list.request.uri.to_s).to eq url
35
+ expect(list.transactions.length).to eq 0
36
+ end
26
37
  end
27
38
 
28
- it "should set request with uri to set last fetch id" do
29
- id = "12345"
39
+ it 'should set request with uri to set last fetch id' do
40
+ id = '12345'
30
41
  url = "https://www.fio.cz/ib_api/rest/set-last-id/#{FioAPI.token}/#{id}/"
31
- expect(@list.set_last_fetch_id(id).request.uri).to eq url
42
+ VCR.use_cassette 'set_last_fetch_id', erb: true do
43
+ list = @list.set_last_fetch_id(id)
44
+ expect(list.request.uri.to_s).to eq url
45
+ expect(list.transactions.length).to eq 0
46
+ end
32
47
  end
33
48
 
34
- it "should set request with uri to set last date" do
35
- date = Date.new(2012,11,25)
49
+ it 'should set request with uri to set last date' do
50
+ date = Date.new(2012, 11, 25)
36
51
  url = "https://www.fio.cz/ib_api/rest/set-last-date/#{FioAPI.token}/#{date}/"
37
- expect(@list.set_last_fetch_date(date).request.uri).to eq url
38
- end
39
-
40
- it "should fetch and deserialize response" do
41
- @list.send(:fetch_and_deserialize_response)
42
- expect(@list.request).not_to be_nil
43
- expect(@list.response).not_to be_nil
52
+ VCR.use_cassette 'set_last_fetch_date', erb: true do
53
+ list = @list.set_last_fetch_date(date)
54
+ expect(list.request.uri.to_s).to eq url
55
+ expect(list.transactions.length).to eq 0
56
+ end
44
57
  end
45
58
  end
@@ -0,0 +1,38 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe FioAPI::Payment do
4
+ before(:each) do
5
+ @payment = FioAPI::Payments::Domestic.new(account_from: '11111111', currency: 'CZK', amount: amount, account_to: '22222222', bank_code: '3030', date: '2018-06-15')
6
+ @service = FioAPI::Payment.new [@payment]
7
+ end
8
+
9
+ context 'payment with valid data' do
10
+ let(:amount) { 100.0 }
11
+ it 'should make request' do
12
+ VCR.use_cassette 'import', erb: true do
13
+ expect(@service.import).to be_a HTTParty::Response
14
+ expect(@service.request).to be_a HTTParty::Response
15
+ expect(@service.response).to be_a FioAPI::ImportResponseDeserializer
16
+ end
17
+ end
18
+
19
+ it 'should build path' do
20
+ expect(@service.path).to eq "/import/?token=#{FioAPI.token}&type=xml"
21
+ end
22
+ end
23
+
24
+ context 'payment with invalid data' do
25
+ let(:amount) { '' }
26
+ it 'should make request' do
27
+ VCR.use_cassette 'invalid_import', erb: true do
28
+ expect(@service.import).to be_a HTTParty::Response
29
+ expect(@service.request).to be_a HTTParty::Response
30
+ expect(@service.response).to be_a FioAPI::ImportResponseDeserializer
31
+ end
32
+ end
33
+
34
+ it 'should build path' do
35
+ expect(@service.path).to eq "/import/?token=#{FioAPI.token}&type=xml"
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,14 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe FioAPI::Payments::Domestic do
4
+ describe 'instance attributes' do
5
+ %i[
6
+ account_from currency amount account_to bank_code ks vs ss
7
+ date message_for_recipient comment
8
+ ].each do |attr|
9
+ it "should respond to #{attr}" do
10
+ expect(FioAPI::Payments::Domestic.new).to respond_to(attr)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe FioAPI::Payments::Status do
4
+ describe 'instance attributes' do
5
+ %i[
6
+ error_code id_instruction error_message sum_credit sum_debet
7
+ ].each do |attr|
8
+ it "should respond to #{attr}" do
9
+ expect(FioAPI::Payments::Status.new).to respond_to(attr)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,63 @@
1
+ require_relative '../../../spec_helper'
2
+
3
+ describe FioAPI::Payments::Xml::Root do
4
+ let(:payments) { [] }
5
+ let(:service) { FioAPI::Payments::Xml::Root.new(payments) }
6
+
7
+ context 'build xml without payments' do
8
+ it 'returns empty xml' do
9
+ expect(service.build).to eq <<-XML
10
+ <?xml version="1.0" encoding="UTF-8"?>
11
+ <Import xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.fio.cz/schema/importIB.xsd">
12
+ <Orders/>
13
+ </Import>
14
+ XML
15
+ end
16
+ end
17
+
18
+ context 'build xml with payments' do
19
+ let(:payments) do
20
+ [
21
+ FioAPI::Payments::Domestic.new(account_from: '11111111', currency: 'CZK', amount: 123.1, account_to: '22222222', bank_code: '3030', date: '2018-06-15'),
22
+ FioAPI::Payments::Domestic.new
23
+ ]
24
+ end
25
+ it 'returns empty xml' do
26
+ expect(service.build).to eq <<-XML
27
+ <?xml version="1.0" encoding="UTF-8"?>
28
+ <Import xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.fio.cz/schema/importIB.xsd">
29
+ <Orders>
30
+ <DomesticTransaction>
31
+ <accountFrom>11111111</accountFrom>
32
+ <currency>CZK</currency>
33
+ <amount>123.1</amount>
34
+ <accountTo>22222222</accountTo>
35
+ <bankCode>3030</bankCode>
36
+ <ks/>
37
+ <vs/>
38
+ <ss/>
39
+ <date>2018-06-15</date>
40
+ <messageForRecipient/>
41
+ <comment/>
42
+ <paymentType>431001</paymentType>
43
+ </DomesticTransaction>
44
+ <DomesticTransaction>
45
+ <accountFrom/>
46
+ <currency/>
47
+ <amount/>
48
+ <accountTo/>
49
+ <bankCode/>
50
+ <ks/>
51
+ <vs/>
52
+ <ss/>
53
+ <date/>
54
+ <messageForRecipient/>
55
+ <comment/>
56
+ <paymentType>431001</paymentType>
57
+ </DomesticTransaction>
58
+ </Orders>
59
+ </Import>
60
+ XML
61
+ end
62
+ end
63
+ end