callcredit 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/spec/request_spec.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Callcredit::Request do
4
+ before { configure_callcredit }
4
5
  let(:request) { Callcredit::Request.new(connection, config) }
5
- let(:config) { Callcredit::Config.new }
6
+ let(:config) { Callcredit.config }
6
7
  let(:connection) { Callcredit::Client.new(config).send(:connection) }
7
8
 
8
9
  let(:response_hash) { { status: status, body: body } }
@@ -10,20 +11,35 @@ describe Callcredit::Request do
10
11
  let(:body) { "<Results><Errors/></Results>" }
11
12
  before { stub_request(:get, config[:api_endpoint]).to_return(response_hash) }
12
13
 
13
- let(:check_data) { { personal_data: { date_of_birth: date_of_birth } } }
14
+ let(:check_data) do
15
+ { personal_data: {
16
+ first_name: "Grey",
17
+ last_name: "Baker",
18
+ date_of_birth: date_of_birth,
19
+ postcode: "EC2A 1DX",
20
+ building_number: "22-25"
21
+ }
22
+ }
23
+ end
24
+
14
25
  let(:date_of_birth) { "01/01/2000" }
15
26
 
16
27
  describe '#build_request_xml' do
17
- subject(:build_request_xml) do
18
- request.build_request_xml(:id_enhanced, check_data).to_s
28
+ subject(:request_xml) do
29
+ request.build_request_xml(:id_enhanced, check_data)
19
30
  end
20
- let(:request_xml) { load_fixture('request.xml') }
31
+ let(:xml_schema) { load_fixture('request.xsd') }
32
+ let(:xsd) { Nokogiri::XML::Schema(xml_schema) }
21
33
 
22
- it { should == request_xml }
34
+ it "generates a valid XML request" do
35
+ xsd.validate(request_xml).should == []
36
+ end
23
37
 
24
38
  context "with a date object for date_of_birth" do
25
39
  let(:date_of_birth) { Date.parse("01/01/2000") }
26
- it { should == request_xml }
40
+ it "generates a valid XML request" do
41
+ xsd.validate(request_xml).should == []
42
+ end
27
43
  end
28
44
  end
29
45
 
data/spec/spec_helper.rb CHANGED
@@ -3,7 +3,12 @@ require 'webmock/rspec'
3
3
  RSpec.configure { |config| config.include WebMock::API }
4
4
 
5
5
  def configure_callcredit
6
- Callcredit.configure { |config| config[:first_name] = "Grey" }
6
+ Callcredit.configure do |config|
7
+ config[:company] = "GoCardless"
8
+ config[:username] = "Username"
9
+ config[:password] = "Password"
10
+ config[:application_name] = "Application"
11
+ end
7
12
  end
8
13
 
9
14
  def load_fixture(*filename)
@@ -0,0 +1,108 @@
1
+ require 'spec_helper'
2
+
3
+ describe Callcredit::Validations do
4
+ let(:check_data) do
5
+ { personal_data: {
6
+ first_name: "Grey",
7
+ last_name: "Baker",
8
+ date_of_birth: date_of_birth,
9
+ postcode: "EC2A 1DX",
10
+ building_number: "22-25"
11
+ }
12
+ }
13
+ end
14
+ let(:date_of_birth) { "01/01/2000" }
15
+
16
+ describe '#clean_date_of_birth' do
17
+ subject { Callcredit::Validations.clean_date_of_birth(date_of_birth) }
18
+
19
+ context "with a date object" do
20
+ let(:date_of_birth) { Date.parse("01/01/2000") }
21
+ it { should == date_of_birth.strftime("%d/%m/%Y") }
22
+ end
23
+
24
+ context "with a parseable string" do
25
+ let(:date_of_birth) { "01-01-2000" }
26
+ it { should == "01/01/2000" }
27
+ end
28
+
29
+ context "with a load of rubbish" do
30
+ let(:date_of_birth) { "A couple of weeks ago" }
31
+ it "raises an error" do
32
+ expect { subject }.to raise_error Callcredit::InvalidRequestError
33
+ end
34
+ end
35
+ end
36
+
37
+ describe '#clean_first_name' do
38
+ subject { Callcredit::Validations.clean_first_name(first_name) }
39
+
40
+ context "without a first name" do
41
+ let(:first_name) { nil }
42
+ it "raises an error" do
43
+ expect { subject }.to raise_error Callcredit::InvalidRequestError
44
+ end
45
+ end
46
+
47
+ context "with a simple first name" do
48
+ let(:first_name) { "Grey" }
49
+ it { should == first_name }
50
+ end
51
+
52
+ context "with a first name with non-ASCII characters" do
53
+ let(:first_name) { "Gréy" }
54
+ it { should == "Grey" }
55
+ end
56
+
57
+ context "without a very long first name" do
58
+ let(:first_name) { "A" * 31 }
59
+ it "raises an error" do
60
+ expect { subject }.to raise_error Callcredit::InvalidRequestError
61
+ end
62
+ end
63
+
64
+ context "without a first name with numbers in it" do
65
+ let(:first_name) { "David the 3rd" }
66
+ it "raises an error" do
67
+ expect { subject }.to raise_error Callcredit::InvalidRequestError
68
+ end
69
+ end
70
+ end
71
+
72
+ describe '#clean_middle_names' do
73
+ subject { Callcredit::Validations.clean_middle_names(name) }
74
+
75
+ context "without a middle name" do
76
+ let(:name) { nil }
77
+ it { should == nil }
78
+ end
79
+ end
80
+
81
+ describe '#clean_postcode' do
82
+ subject { Callcredit::Validations.clean_postcode(postcode) }
83
+
84
+ context "without a post code" do
85
+ let(:postcode) { nil }
86
+ it "raises an error" do
87
+ expect { subject }.to raise_error Callcredit::InvalidRequestError
88
+ end
89
+ end
90
+
91
+ context "with a correct post code" do
92
+ let(:postcode) { "EC2A 1DX" }
93
+ it { should == postcode }
94
+ end
95
+
96
+ context "with a padded post code" do
97
+ let(:postcode) { "EC2A 1DX " }
98
+ it { should == "EC2A 1DX" }
99
+ end
100
+
101
+ context "with a postcode that is too short" do
102
+ let(:postcode) { "N1" }
103
+ it "raises an error" do
104
+ expect { subject }.to raise_error Callcredit::InvalidRequestError
105
+ end
106
+ end
107
+ end
108
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: callcredit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grey Baker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-19 00:00:00.000000000 Z
11
+ date: 2014-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: unidecoder
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 1.1.2
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 1.1.2
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rspec
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -120,18 +134,20 @@ files:
120
134
  - lib/callcredit/request.rb
121
135
  - lib/callcredit/response.rb
122
136
  - lib/callcredit/util.rb
137
+ - lib/callcredit/validations.rb
123
138
  - lib/callcredit/version.rb
124
139
  - spec/callcredit_spec.rb
125
140
  - spec/checks/id_enhanced_spec.rb
126
141
  - spec/client_spec.rb
127
142
  - spec/fixtures/access_denied.xml
128
143
  - spec/fixtures/bad_request.xml
129
- - spec/fixtures/request.xml
144
+ - spec/fixtures/request.xsd
130
145
  - spec/fixtures/response.xml
131
146
  - spec/fixtures/system_call_failure.xml
132
147
  - spec/request_spec.rb
133
148
  - spec/response_spec.rb
134
149
  - spec/spec_helper.rb
150
+ - spec/validations_spec.rb
135
151
  homepage: https://github.com/gocardless/callcredit-ruby
136
152
  licenses: []
137
153
  metadata: {}
@@ -161,9 +177,10 @@ test_files:
161
177
  - spec/client_spec.rb
162
178
  - spec/fixtures/access_denied.xml
163
179
  - spec/fixtures/bad_request.xml
164
- - spec/fixtures/request.xml
180
+ - spec/fixtures/request.xsd
165
181
  - spec/fixtures/response.xml
166
182
  - spec/fixtures/system_call_failure.xml
167
183
  - spec/request_spec.rb
168
184
  - spec/response_spec.rb
169
185
  - spec/spec_helper.rb
186
+ - spec/validations_spec.rb
@@ -1,50 +0,0 @@
1
- <?xml version="1.0"?>
2
- <callvalidate>
3
- <authentication>
4
- <company/>
5
- <username/>
6
- <password/>
7
- </authentication>
8
- <sessions>
9
- <session>
10
- <data>
11
- <ChecksRequired>
12
- <BankStandard>no</BankStandard>
13
- <BankEnhanced>no</BankEnhanced>
14
- <CardLive>no</CardLive>
15
- <CardEnhanced>no</CardEnhanced>
16
- <IDEnhanced>yes</IDEnhanced>
17
- <NCOAAlert>no</NCOAAlert>
18
- <CallValidate3D>no</CallValidate3D>
19
- <TheAffordabilityReport>no</TheAffordabilityReport>
20
- <DeliveryFraud>no</DeliveryFraud>
21
- <EmailValidate>no</EmailValidate>
22
- <CreditScore>no</CreditScore>
23
- <Zodiac>no</Zodiac>
24
- <IPAddress>no</IPAddress>
25
- <BankAccountPlus>no</BankAccountPlus>
26
- <BankOFA>no</BankOFA>
27
- <CardOFA>no</CardOFA>
28
- </ChecksRequired>
29
- <Personal>
30
- <Individual>
31
- <Dateofbirth>01/01/2000</Dateofbirth>
32
- <Title>Unknown</Title>
33
- <Firstname/>
34
- <Othernames/>
35
- <Surname/>
36
- <Phonenumber/>
37
- <Drivinglicensenumber/>
38
- </Individual>
39
- <Address>
40
- <Buildingnumber/>
41
- <Buildingname/>
42
- <Address1/>
43
- <Postcode/>
44
- </Address>
45
- </Personal>
46
- </data>
47
- </session>
48
- </sessions>
49
- <application/>
50
- </callvalidate>