-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkontoapi-ruby_spec.rb
More file actions
61 lines (47 loc) · 2.42 KB
/
kontoapi-ruby_spec.rb
File metadata and controls
61 lines (47 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'spec_helper'
describe "KontoAPI" do
it "should raise if no api key was provided" do
lambda { KontoAPI::valid?( :ktn => '1234567', :blz => '12312312' ) }.should raise_error(RuntimeError)
end
it "should raise if api key is invalid" do
FakeWeb.register_uri(:get, %r|https://ask\.kontoapi\.de/for/validity.json?.*|, :body => '{"error":"unauthenticated"}', :status => ["401", "Unauthorized"])
KontoAPI::api_key = 'abc123'
lambda { KontoAPI::valid?( :ktn => '1234567', :blz => '12312312' ) }.should raise_error(Net::HTTPServerException)
end
context "checking validity" do
it "should return false if account number or bank code are empty" do
KontoAPI::valid?( :ktn => nil, :blz => nil ).should be_false
KontoAPI::valid?( :ktn => '123', :blz => nil ).should be_false
KontoAPI::valid?( :ktn => nil, :blz => '123' ).should be_false
KontoAPI::valid?( :ktn => '', :blz => '' ).should be_false
KontoAPI::valid?( :ktn => '123', :blz => '' ).should be_false
KontoAPI::valid?( :ktn => '', :blz => '123' ).should be_false
end
it "should return true for successfull validity checks" do
FakeWeb.register_uri(:get, %r|https://ask\.kontoapi\.de/for/validity.json?.*|, :body => '{"answer":"yes"}')
KontoAPI::api_key = 'abc123'
KontoAPI::valid?( :ktn => 'correct_account_number', :blz => '12312312' ).should be_true
end
it "should return false for unsuccessfull validity checks" do
FakeWeb.register_uri(:get, %r|https://ask\.kontoapi\.de/for/validity.json?.*|, :body => '{"answer":"no"}')
KontoAPI::api_key = 'abc123'
KontoAPI::valid?( :ktn => 'incorrect_account_number', :blz => '12312312' ).should be_false
end
end
context "getting bank names" do
it "should return nil if no bank code was provided" do
KontoAPI::bank_name(nil).should be_nil
KontoAPI::bank_name('').should be_nil
end
it "should return nil if no bank was found" do
FakeWeb.register_uri(:get, %r|https://ask\.kontoapi\.de/for/bankname.json?.*|, :body => '{"answer":""}')
KontoAPI::api_key = 'abc123'
KontoAPI::bank_name('12312312').should be_nil
end
it "should return Postbank for bank code 10010010" do
FakeWeb.register_uri(:get, %r|https://ask\.kontoapi\.de/for/bankname.json?.*|, :body => '{"answer":"Postbank"}')
KontoAPI::api_key = 'abc123'
KontoAPI::bank_name('10010010').should == "Postbank"
end
end
end