crowd_pay 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +38 -0
- data/.rspec +1 -0
- data/.travis.yml +24 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +69 -0
- data/LICENSE +21 -0
- data/README.md +12 -0
- data/Rakefile +7 -0
- data/crowd_pay.gemspec +17 -0
- data/lib/crowd_pay.rb +163 -0
- data/lib/crowd_pay/account.rb +83 -0
- data/lib/crowd_pay/asset.rb +26 -0
- data/lib/crowd_pay/escrow.rb +22 -0
- data/lib/crowd_pay/investor.rb +51 -0
- data/lib/crowd_pay/transaction.rb +52 -0
- data/lib/crowd_pay/verification.rb +42 -0
- data/lib/crowd_pay/version.rb +3 -0
- data/spec/account_spec.rb +287 -0
- data/spec/asset_spec.rb +34 -0
- data/spec/crowd_pay_spec.rb +187 -0
- data/spec/escrow_spec.rb +42 -0
- data/spec/factories/accounts.rb +42 -0
- data/spec/factories/assets.rb +10 -0
- data/spec/factories/escrows.rb +12 -0
- data/spec/factories/investors.rb +31 -0
- data/spec/factories/transactions.rb +14 -0
- data/spec/factories/verifications.rb +105 -0
- data/spec/investor_spec.rb +198 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/transaction_spec.rb +176 -0
- data/spec/verification_spec.rb +91 -0
- metadata +107 -0
@@ -0,0 +1,198 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "CrowdPay::Investor" do
|
4
|
+
let(:investor) { FactoryGirl.build(:investor) }
|
5
|
+
|
6
|
+
context "validate factories" do
|
7
|
+
it "should validate the investor factories" do
|
8
|
+
expect(investor.valid?).to be(true)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "Validations" do
|
13
|
+
it "tax_id_number presence" do
|
14
|
+
investor.tax_id_number = nil
|
15
|
+
expect(investor).to be_invalid
|
16
|
+
end
|
17
|
+
|
18
|
+
it "is_mailing_address_foreign presence" do
|
19
|
+
investor.is_mailing_address_foreign = nil
|
20
|
+
expect(investor).to be_invalid
|
21
|
+
end
|
22
|
+
|
23
|
+
it "is_person presence" do
|
24
|
+
investor.is_person = nil
|
25
|
+
expect(investor).to be_invalid
|
26
|
+
end
|
27
|
+
|
28
|
+
it "is_cip_satisfied presence" do
|
29
|
+
investor.is_cip_satisfied = nil
|
30
|
+
expect(investor).to be_invalid
|
31
|
+
end
|
32
|
+
|
33
|
+
it "created_by_ip_address presence" do
|
34
|
+
investor.created_by_ip_address = nil
|
35
|
+
expect(investor).to be_invalid
|
36
|
+
end
|
37
|
+
|
38
|
+
it "minmum lenth of tax_id_number" do
|
39
|
+
investor.tax_id_number = "1234567"
|
40
|
+
expect(investor).to be_invalid
|
41
|
+
end
|
42
|
+
|
43
|
+
it "maximum lenth of tax_id_number" do
|
44
|
+
investor.tax_id_number = "1234567890"
|
45
|
+
expect(investor).to be_invalid
|
46
|
+
end
|
47
|
+
|
48
|
+
it "maximum lenth of created_by_ip_address" do
|
49
|
+
investor.created_by_ip_address = "32424324354544523674523645345345345345"
|
50
|
+
expect(investor).to be_invalid
|
51
|
+
end
|
52
|
+
|
53
|
+
it "maximum lenth of first_name" do
|
54
|
+
investor.first_name = "adsdsdsds dfdsfdsfds fdsfdfsdf fdsfdsfdsf fdsfsdfdfs fdsfdsf"
|
55
|
+
expect(investor).to be_invalid
|
56
|
+
end
|
57
|
+
|
58
|
+
it "maximum lenth of middle_name" do
|
59
|
+
investor.middle_name = "adsdsdsds dfdsfdsfds fdsfdfsdf fdsfdsfdsf fdsfsdfdfs fdsfdsf"
|
60
|
+
expect(investor).to be_invalid
|
61
|
+
end
|
62
|
+
|
63
|
+
it "maximum lenth of last_name" do
|
64
|
+
investor.last_name = "adsdsdsds dfdsfdsfds fdsfdfsdf fdsfdsfdsf fdsfsdfdfs fdsfdsf"
|
65
|
+
expect(investor).to be_invalid
|
66
|
+
end
|
67
|
+
|
68
|
+
it "maximum lenth of name" do
|
69
|
+
investor.name = "adsdsdsds dfdsfdsfds fdsfdfsdf fdsfdsfdsf fdsfsdfdfs fdsfdsf adsdsdsds dfdsfdsfds fdsfdfsdf fdsfdsfdsf fdsfsdfdfs fdsfdsf adsdsdsds dfdsfdsfds fdsfdfsdf fdsfdsfdsf fdsfsdfdfs fdsfdsf"
|
70
|
+
expect(investor).to be_invalid
|
71
|
+
end
|
72
|
+
|
73
|
+
it "maximum lenth of mailing_address_1" do
|
74
|
+
investor.mailing_address_1 = "adsdsdsds dfdsfdsfds fdsfdfsdf fdsfdsfdsf fdsfsdfdfs fdsfdsf"
|
75
|
+
expect(investor).to be_invalid
|
76
|
+
end
|
77
|
+
|
78
|
+
it "maximum lenth of mailing_address_2" do
|
79
|
+
investor.mailing_address_2 = "adsdsdsds dfdsfdsfds fdsfdfsdf fdsfdsfdsf fdsfsdfdfs fdsfdsf"
|
80
|
+
expect(investor).to be_invalid
|
81
|
+
end
|
82
|
+
|
83
|
+
it "maximum lenth of mailing_city" do
|
84
|
+
investor.mailing_city = "adsdsdsds dfdsfdsfds fdsfdfsdf fdsfdsfdsf fdsfsdfdfs fdsfdsf"
|
85
|
+
expect(investor).to be_invalid
|
86
|
+
end
|
87
|
+
|
88
|
+
it "maximum lenth of mailing_state" do
|
89
|
+
investor.mailing_state = "adsdsdsds dfdsfdsfds fdsfdfsdf fdsfdsfdsf fdsfsdfdfs fdsfdsf"
|
90
|
+
expect(investor).to be_invalid
|
91
|
+
end
|
92
|
+
|
93
|
+
it "maximum lenth of mailing_zip" do
|
94
|
+
investor.mailing_zip = "3242432435454"
|
95
|
+
expect(investor).to be_invalid
|
96
|
+
end
|
97
|
+
|
98
|
+
it "maximum lenth of mailing_country" do
|
99
|
+
investor.mailing_country = "ghgjhghbvzxbczx czxczxcbxzcxzcxzcxzczxsascsdsa dsfsfsdfdsfdsf"
|
100
|
+
expect(investor).to be_invalid
|
101
|
+
end
|
102
|
+
|
103
|
+
it "maximum lenth of legal_address_1" do
|
104
|
+
investor.legal_address_1 = "ghgjhghbvzxbczx czxczxcbxzcxzcxzcxzczxsascsdsa dsfsfsdfdsfdsf"
|
105
|
+
expect(investor).to be_invalid
|
106
|
+
end
|
107
|
+
|
108
|
+
it "maximum lenth of legal_address_2" do
|
109
|
+
investor.legal_address_2 = "ghgjhghbvzxbczx czxczxcbxzcxzcxzcxzczxsascsdsa dsfsfsdfdsfdsf"
|
110
|
+
expect(investor).to be_invalid
|
111
|
+
end
|
112
|
+
|
113
|
+
it "maximum lenth of legal_city" do
|
114
|
+
investor.legal_city = "ghgjhghbvzxbczx czxczxcbxzcxzcxzcxzczxsascsdsa dsfsfsdfdsfdsf"
|
115
|
+
expect(investor).to be_invalid
|
116
|
+
end
|
117
|
+
|
118
|
+
it "maximum lenth of legal_state" do
|
119
|
+
investor.legal_state = "ghgjhghbvzxbczx czxczxcbxzcxzcxzcxzczxsascsdsa"
|
120
|
+
expect(investor).to be_invalid
|
121
|
+
end
|
122
|
+
|
123
|
+
it "maximum lenth of legal_zip" do
|
124
|
+
investor.legal_zip = "3242432435454"
|
125
|
+
expect(investor).to be_invalid
|
126
|
+
end
|
127
|
+
|
128
|
+
it "maximum lenth of legal_country" do
|
129
|
+
investor.legal_country = "ghgjhghbvzxbczx czxczxcbxzcxzcxzcxzczxsascsdsa dsfsfsdfdsfdsf"
|
130
|
+
expect(investor).to be_invalid
|
131
|
+
end
|
132
|
+
|
133
|
+
it "maximum lenth of primary_phone" do
|
134
|
+
investor.primary_phone = "3242432435454"
|
135
|
+
expect(investor).to be_invalid
|
136
|
+
end
|
137
|
+
|
138
|
+
it "maximum lenth of secondary_phone" do
|
139
|
+
investor.secondary_phone = "3242432435454"
|
140
|
+
expect(investor).to be_invalid
|
141
|
+
end
|
142
|
+
|
143
|
+
it "maximum lenth of email" do
|
144
|
+
investor.email = "sadasdasdsavxcvcx@fdsfdsfdsfgdfgtreter.dsfdsfdsfdsfdsfdsvc"
|
145
|
+
expect(investor).to be_invalid
|
146
|
+
end
|
147
|
+
|
148
|
+
it "maximum lenth of portal_investor_number" do
|
149
|
+
investor.portal_investor_number = "32424324354544543534534534543534534535345435453"
|
150
|
+
expect(investor).to be_invalid
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context "create" do
|
155
|
+
context "positive case" do
|
156
|
+
it "should create a new investor" do
|
157
|
+
url = "https://test.crowdpay.com/Crowdfunding/api/Investor"
|
158
|
+
investor_attributes = FactoryGirl.attributes_for(:investor)
|
159
|
+
stub_request(:post, url).to_return(:status => 201, :body => "{\"id\":78630,\"investor_key\":\"9f3c734c-3a99-4a04-9d00-007f7497b6df\",\"tax_id_number\":\"*****2650\",\"first_name\":\"Investor First\",\"middle_name\":\"Investor Middle\",\"last_name\":\"Investor Last\",\"name\":null,\"birth_date\":\"1985-04-07T00:00:00\",\"mailing_address_1\":\"123 Ave A\",\"mailing_address_2\":null,\"mailing_city\":\"Somewhere\",\"mailing_state\":\"TX\",\"mailing_zip\":\"79109\",\"mailing_country\":null,\"is_mailing_address_foreign\":false,\"legal_address_1\":\"123 Ave A\",\"legal_address_2\":null,\"legal_city\":\"Somewhere\",\"legal_state\":\"TX\",\"legal_zip\":\"79109\",\"legal_country\":null,\"is_legal_address_foreign\":false,\"primary_phone\":\"1112223333\",\"secondary_phone\":\"2223334444\",\"is_person\":true,\"email\":\"cgrimes@qwinixtech.com\",\"is_cip_satisfied\":false,\"portal_investor_number\":\"yourinvestornumber\",\"created_by_ip_address\":\"192.168.2.61\",\"Accounts\":[]}")
|
160
|
+
investor = CrowdPay::Investor.create(investor_attributes)
|
161
|
+
expect(investor).to be_an(CrowdPay::Investor)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context "negative case" do
|
166
|
+
it "should not create a new investor" do
|
167
|
+
url = "https://test.crowdpay.com/Crowdfunding/api/Investor"
|
168
|
+
stub_request(:post, url).to_return(:status => 400, :body => "{\"Message\":\"The request is invalid.\",\"ModelState\":{\"investor\":[\"An error has occurred.\",\"An error has occurred.\",\"An error has occurred.\"],\"investor.tax_id_number\":[\"The tax_id_number field is required.\"],\"investor.created_by_ip_address\":[\"The created_by_ip_address field is required.\"]}}")
|
169
|
+
investor = CrowdPay::Investor.create({})
|
170
|
+
expect(investor).to be_an(CrowdPay::Investor)
|
171
|
+
expect(investor.errors["tax_id_number"]).to eq(["The tax_id_number field is required."])
|
172
|
+
expect(investor.errors["created_by_ip_address"]).to eq(["The created_by_ip_address field is required."])
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
context "find" do
|
178
|
+
context "positive case" do
|
179
|
+
it "should get an investor with id" do
|
180
|
+
investor_key = "a3cda761-78ff-4789-84fb-80a35628f95e"
|
181
|
+
stub_request(:get, "https://test.crowdpay.com/Crowdfunding/api/Investor/#{investor_key}").to_return(:status => 200, :body => "{\"id\":78627,\"investor_key\":\"a3cda761-78ff-4789-84fb-80a35628f95e\",\"tax_id_number\":\"*****8718\",\"first_name\":\"Investor First\",\"middle_name\":\"Investor Middle\",\"last_name\":\"Investor Last\",\"name\":\"Investor First Investor Middle Investor Last\",\"birth_date\":\"1985-04-07T00:00:00\",\"mailing_address_1\":\"123 Ave A\",\"mailing_address_2\":null,\"mailing_city\":\"Somewhere\",\"mailing_state\":\"TX\",\"mailing_zip\":\"79109\",\"mailing_country\":null,\"is_mailing_address_foreign\":false,\"legal_address_1\":\"123 Ave A\",\"legal_address_2\":null,\"legal_city\":\"Somewhere\",\"legal_state\":\"TX\",\"legal_zip\":\"79109\",\"legal_country\":null,\"is_legal_address_foreign\":false,\"primary_phone\":\"1112223333\",\"secondary_phone\":\"2223334444\",\"is_person\":true,\"email\":\"cgrimes@qwinixtech.com\",\"is_cip_satisfied\":false,\"portal_investor_number\":\"yourinvestornumber\",\"created_by_ip_address\":\"192.168.2.61\",\"Accounts\":[]}")
|
182
|
+
investor2 = CrowdPay::Investor.find(investor_key)
|
183
|
+
expect(investor2).to be_an(CrowdPay::Investor)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
context "negative case" do
|
188
|
+
it "should return an investor object with errors in it if investor_key is invalid" do
|
189
|
+
investor_key = "invalid_investor_key"
|
190
|
+
stub_request(:get, "https://test.crowdpay.com/Crowdfunding/api/Investor/#{investor_key}").to_return(:status => 405, :body => "{\"Message\":\"The requested resource does not support http method 'GET'.\"}")
|
191
|
+
investor = CrowdPay::Investor.find(investor_key)
|
192
|
+
expect(investor).to be_an(CrowdPay::Investor)
|
193
|
+
expect(investor.errors[:api]).to eq(["The requested resource does not support http method 'GET'."])
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'codeclimate-test-reporter'
|
2
|
+
CodeClimate::TestReporter.start
|
3
|
+
|
4
|
+
require 'factory_girl'
|
5
|
+
require 'webmock/rspec'
|
6
|
+
require 'active_support/time'
|
7
|
+
|
8
|
+
require 'crowd_pay'
|
9
|
+
|
10
|
+
ENV['CROWD_PAY_DOMAIN'] = 'https://test.crowdpay.com'
|
11
|
+
ENV['CROWD_PAY_API_KEY'] = 'test'
|
12
|
+
ENV['CROWD_PAY_PORTAL_KEY'] = 'test'
|
13
|
+
ENV['CROWD_PAY_BY_PASS_VALIDATION'] = 'test'
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.include FactoryGirl::Syntax::Methods
|
17
|
+
|
18
|
+
config.before(:suite) do
|
19
|
+
FactoryGirl.find_definitions
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,176 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "CrowdPay::Investor" do
|
4
|
+
let(:transaction) { FactoryGirl.build(:transaction) }
|
5
|
+
|
6
|
+
context "validate factories" do
|
7
|
+
it "should validate the transaction factories" do
|
8
|
+
expect(transaction.valid?).to be(true)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "Validations" do
|
13
|
+
|
14
|
+
it "account_id presence" do
|
15
|
+
transaction.account_id = nil
|
16
|
+
expect(transaction).to be_invalid
|
17
|
+
end
|
18
|
+
|
19
|
+
it "amount presence" do
|
20
|
+
transaction.amount = nil
|
21
|
+
expect(transaction).to be_invalid
|
22
|
+
end
|
23
|
+
|
24
|
+
it "created_by_ip_address presence" do
|
25
|
+
transaction.created_by_ip_address = nil
|
26
|
+
expect(transaction).to be_invalid
|
27
|
+
end
|
28
|
+
|
29
|
+
it "maximum length of reference" do
|
30
|
+
transaction.reference = "anthskut thanks thsmk"
|
31
|
+
expect(transaction).to be_invalid
|
32
|
+
end
|
33
|
+
|
34
|
+
it "maximum length of description" do
|
35
|
+
transaction.description = "qwuhtndkl ethrindks thinekmdh thnmildhf thimfnghbcaml"
|
36
|
+
expect(transaction).to be_invalid
|
37
|
+
end
|
38
|
+
|
39
|
+
it "maximum length of created_by_ip_address" do
|
40
|
+
transaction.created_by_ip_address = "123.456789.12345678.123456"
|
41
|
+
expect(transaction).to be_invalid
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
context "find" do
|
47
|
+
it "should get an transaction with id" do
|
48
|
+
account_id = "82980"
|
49
|
+
id = "6829651"
|
50
|
+
stub_request(:get, "https://test.crowdpay.com/Crowdfunding/api/Account/#{account_id}/Transaction/#{id}").to_return(:status => 200, :body => "{\"id\":6829651,\"account_id\":\"#{account_id}\",\"date\":\"#{Date.today}\",\"reference\":\"Reffernce\",\"amount\":100.0,\"status\":\"pending\",\"created_by_ip_address\":\"192.168.2.61\"}")
|
51
|
+
transaction = CrowdPay::Transaction.find(account_id, id)
|
52
|
+
expect(transaction).to be_an(CrowdPay::Transaction)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should get an transaction without id" do
|
56
|
+
account_id = "82980"
|
57
|
+
id = ""
|
58
|
+
stub_request(:get, "https://test.crowdpay.com/Crowdfunding/api/Account/#{account_id}/Transaction/#{id}").to_return(:status => 200, :body => "{\"Message\":\"The requested resource does not support http method 'GET'.\"}")
|
59
|
+
transaction = CrowdPay::Transaction.find(account_id, id)
|
60
|
+
expect(transaction).to be_an(CrowdPay::Transaction)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "withdraw_fund" do
|
65
|
+
it "should create withdraw transaction" do
|
66
|
+
account_id = "82980"
|
67
|
+
id = "6829651"
|
68
|
+
trasaction_data = FactoryGirl.attributes_for(:transaction, account_id: account_id, id: id)
|
69
|
+
stub_request(:post, "https://test.crowdpay.com/Crowdfunding/api/Account/#{account_id}/Transaction/WithdrawFunds").to_return(:status => 200, :body => "{\"id\":78627,\"account_id\":\"#{account_id}\",\"date\":\"#{Date.today}\",\"reference\":\"Reffernce\",\"amount\":100.0,\"status\":\"pending\",\"created_by_ip_address\":\"192.168.2.61\"}")
|
70
|
+
transaction = CrowdPay::Transaction.withdraw_funds(trasaction_data)
|
71
|
+
expect(transaction).to be_an(CrowdPay::Transaction)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "create fund escrow" do
|
76
|
+
context "positive case" do
|
77
|
+
it "should create a new found escrow" do
|
78
|
+
account_id = "82980"
|
79
|
+
url = "https://test.crowdpay.com/Crowdfunding/api/Account/#{account_id}/Transaction/FundDebtEscrow"
|
80
|
+
account_attributes = FactoryGirl.attributes_for(:account, account_id: account_id)
|
81
|
+
stub_request(:post, url).to_return(:status => 201, :body => "{\"id\":82980,\"account_id\":\"#{account_id}\",\"asset_id\":\"456789\",\"date\":\"2015-01-01T00:00:00\",\"reference\":\"yourreferencenumber\",\"description\":\"description you would like placed on transaction\",\"amount\":\"100.00\",\"quantity\":\"10\",\"created_by_ip_address\":\"123.456.789.012\"}")
|
82
|
+
transaction_obj = CrowdPay::Transaction.fund_debt_escrow(account_attributes)
|
83
|
+
expect(transaction_obj).to be_an(CrowdPay::Transaction)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "negative case" do
|
88
|
+
it "should not create a new found escrow" do
|
89
|
+
account_id = "82980"
|
90
|
+
url = "https://test.crowdpay.com/Crowdfunding/api/Account/#{account_id}/Transaction/FundDebtEscrow"
|
91
|
+
stub_request(:post, url).to_return(:status => 400, :body => "{\"Message\":\"The request is invalid.\",\"ModelState\":{\"account\":[\"An error has occurred.\",\"An error has occurred.\",\"An error has occurred.\"],\"account.draft_account_type_id \":[\"The draft_account_type_id field is required.\"],\"account.draft_routing_number \":[\"The draft_routing_number field is required.\"],\" account.draft_account_number \":[\"The draft_account_number field is required.\"], \"account. draft_account_name \":[\"The draft_account_name field is required.\"], \"account. status_id \":[\"The field status_id must match the regular expression '[1-3]'.\"], \"account. account_type_id \":[\"The field account_type_id must match the regular expression '[2]|1[1-2]'.\"], \"account. created_by_ip_address \":[\"The created_by_ip_address field is required.\"]}}")
|
92
|
+
transaction_obj = CrowdPay::Transaction.fund_debt_escrow(account_id: account_id)
|
93
|
+
expect(transaction_obj).to be_an(CrowdPay::Transaction)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context "create fund account" do
|
99
|
+
context "positive case" do
|
100
|
+
it "should create a new fund account" do
|
101
|
+
account_id = "82980"
|
102
|
+
url = "https://test.crowdpay.com/Crowdfunding/api/Account/#{account_id}/Transaction/FundAccount"
|
103
|
+
account_attributes = FactoryGirl.attributes_for(:account, account_id: account_id)
|
104
|
+
stub_request(:post, url).to_return(:status => 201, :body => "{\"id\":9876544,\"account_id\":\"#{account_id}\",\"date\":\"2015-01-01T00:00:00\",\"reference\":\"yourreferencenumber\",\"description\":\"description you would like placed on transaction\",\"amount\":\"100.00\",\"created_by_ip_address\":\"123.456.789.012\"}")
|
105
|
+
transaction_obj = CrowdPay::Transaction.fund_account(account_attributes)
|
106
|
+
expect(transaction_obj).to be_an(CrowdPay::Transaction)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context "negative case" do
|
111
|
+
it "should not create a new fund account" do
|
112
|
+
account_id = "82980"
|
113
|
+
url = "https://test.crowdpay.com/Crowdfunding/api/Account/#{account_id}/Transaction/FundAccount"
|
114
|
+
stub_request(:post, url).to_return(:status => 400, :body => "{\"Message\":\"The request is invalid.\",\"ModelState\":{\"account\":[\"An error has occurred.\",\"An error has occurred.\",\"An error has occurred.\"],\"account.draft_account_type_id \":[\"The draft_account_type_id field is required.\"],\"account.draft_routing_number \":[\"The draft_routing_number field is required.\"],\" account.draft_account_number \":[\"The draft_account_number field is required.\"], \"account. draft_account_name \":[\"The draft_account_name field is required.\"], \"account. status_id \":[\"The field status_id must match the regular expression '[1-3]'.\"], \"account. account_type_id \":[\"The field account_type_id must match the regular expression '[2]|1[1-2]'.\"], \"account. created_by_ip_address \":[\"The created_by_ip_address field is required.\"]}}")
|
115
|
+
transaction_obj = CrowdPay::Transaction.fund_account(account_id: account_id)
|
116
|
+
expect(transaction_obj).to be_an(CrowdPay::Transaction)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context "create debt pay" do
|
122
|
+
context "positive case" do
|
123
|
+
it "should create a new debt pay" do
|
124
|
+
debt_data = { account_id: "82980", asset_id: "471922", activity_code: "305", sold_date: nil,
|
125
|
+
reference: 'IntPaid', description: 'CrowdPay: Debt Pay Post Interest', amount: "100.00", created_by_ip_address: '182.156.77.154'
|
126
|
+
}
|
127
|
+
url = "https://test.crowdpay.com/Crowdfunding/api/Account/#{debt_data[:account_id]}/Transaction/DebtPay"
|
128
|
+
stub_request(:post, url)
|
129
|
+
.to_return(status: 201, body: "{\"id\":6580369,\"account_id\":\"#{debt_data[:account_id]}\",\"sold_date\":\"2015-01-01T00:00:00\",\"asset_id\":\"#{debt_data[:asset_id]}\",\"activity_code\":\"305\",\"status\":\"pending\",\"reference\":\"yourreferencenumber\",\"description\":\"description you would like placed on transaction\",\"amount\":\"100.00\",\"created_by_ip_address\":\"123.456.789.012\"}")
|
130
|
+
transaction_obj = CrowdPay::Transaction.debt_pay(debt_data)
|
131
|
+
expect(transaction_obj).to be_an(CrowdPay::Transaction)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
context "negative case" do
|
136
|
+
it "should not create a new debt pay" do
|
137
|
+
debt_data = { account_id: "82980", asset_id: "471922" }
|
138
|
+
url = "https://test.crowdpay.com/Crowdfunding/api/Account/#{debt_data[:account_id]}/Transaction/DebtPay"
|
139
|
+
stub_request(:post, url)
|
140
|
+
.to_return(:status => 400, :body => "{\"Message\":\"The request is invalid.\",\"ModelState\":{\"account\":[\"An error has occurred.\",\"An error has occurred.\",\"An error has occurred.\"],\"account.activity_code \":[\"The activity_code field is required.\"],\"account. created_by_ip_address \":[\"The created_by_ip_address field is required.\"]}}")
|
141
|
+
transaction_obj = CrowdPay::Transaction.debt_pay(debt_data)
|
142
|
+
expect(transaction_obj).to be_an(CrowdPay::Transaction)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context "create Reinvest Debt" do
|
148
|
+
context "positive case" do
|
149
|
+
it "should create a new reinvest debt" do
|
150
|
+
reinvest_data = { account_id: "82980", asset_id: "471922", activity_code: "707", sold_date: nil,
|
151
|
+
reference: "yourreferencenumber", description: "description you would like placed on transaction",
|
152
|
+
amount: "100.00", quantity: 1, created_by_ip_address: "182.156.77.154", term: 3.0,
|
153
|
+
effective_date: "2015-01-15T00:00:00", interest_type: 1, interest_frequency: 4, interest_rate: 1.0,
|
154
|
+
maturity_date: "2018-07-15T00:00:00", third_party_asset_number:34, asset_description:"Community Investment Note", cusip_number:"3213243244"
|
155
|
+
}
|
156
|
+
url = "https://test.crowdpay.com/Crowdfunding/api/Account/#{reinvest_data[:account_id]}/Transaction/ReinvestDebt"
|
157
|
+
|
158
|
+
stub_request(:post, url).to_return(status: 201, body: "{\"id\":1223344,\"account_id\":\"82980\",\"sold_date\":null,\"asset_id\":\"471922\",\"activity_code\":\"707\",\"status\":\"pending\",\"reference\":\"yourreferencenumber\",\"description\":\"description you would like placed on transaction\",\"amount\":\"100.00\",\"quantity\":1,\"term\":3.0,\"effective_date\":\"2015-01-15T00:00:00\",\"interest_type\":1,\"interest_frequency\":4,\"interest_rate\":1.50,\"maturity_date\":\"2018-07-15T00:00:00\",\"third_party_asset_number\":\"yourassetnumber\",\"asset_description\":\"custom asset description\",\"cusip_number\":\"1315020180115\",\"status\":\"pending\",\"created_by_ip_address\":\"123.456.789.012\"}")
|
159
|
+
|
160
|
+
transaction_obj = CrowdPay::Transaction.reinvest_debt(reinvest_data)
|
161
|
+
expect(transaction_obj).to be_an(CrowdPay::Transaction)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context "negative case" do
|
166
|
+
it "should not create a new reinvest debt" do
|
167
|
+
account_id = "82980"
|
168
|
+
reinvest_data = {account_id: "82980", asset_id: "471922"}
|
169
|
+
url = "https://test.crowdpay.com/Crowdfunding/api/Account/#{reinvest_data[:account_id]}/Transaction/ReinvestDebt"
|
170
|
+
stub_request(:post, url).to_return(:status => 400, :body => "{\"Message\":\"The request is invalid.\",\"ModelState\":{\"account\":[\"An error has occurred.\",\"An error has occurred.\",\"An error has occurred.\"],\"account.activity_code \":[\"The activity_code field is required.\"],\"account. created_by_ip_address \":[\"The created_by_ip_address field is required.\"]}}")
|
171
|
+
transaction_obj = CrowdPay::Transaction.reinvest_debt(reinvest_data)
|
172
|
+
expect(transaction_obj).to be_an(CrowdPay::Transaction)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'CrowdPay::Verification' do
|
4
|
+
context 'validate factories' do
|
5
|
+
let(:verification) { FactoryGirl.build :verification }
|
6
|
+
|
7
|
+
it 'should validate the investor factories' do
|
8
|
+
expect(verification.valid?).to be(true)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '.verify' do
|
13
|
+
let(:url) { 'https://test.crowdpay.com/identification/api/v1/ops/verify-identity' }
|
14
|
+
|
15
|
+
let(:verification_attributes) { FactoryGirl.attributes_for :verification }
|
16
|
+
|
17
|
+
context 'pass' do
|
18
|
+
it 'shows that a pass has occured' do
|
19
|
+
stub_request(:post, url).to_return status: 200,
|
20
|
+
body: '{"id":"1254778630","Key":"id.success","Message":"Pass"}'
|
21
|
+
|
22
|
+
verify = CrowdPay::Verification.verify verification_attributes, false
|
23
|
+
|
24
|
+
expect(verify.pass?).to eq(true)
|
25
|
+
expect(verify.fail?).to eq(false)
|
26
|
+
expect(verify.soft_fail?).to eq(false)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'hard fail' do
|
31
|
+
it 'shows that a fail has occured' do
|
32
|
+
stub_request(:post, url).to_return status: 200,
|
33
|
+
body: '{"id":"1254778630","Key":"id.failure","Message":"Fail"}'
|
34
|
+
|
35
|
+
verify = CrowdPay::Verification.verify verification_attributes, false
|
36
|
+
|
37
|
+
expect(verify.fail?).to eq(true)
|
38
|
+
expect(verify.pass?).to eq(false)
|
39
|
+
expect(verify.soft_fail?).to eq(false)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'handles other failure messages' do
|
43
|
+
stub_request(:post, url).to_return status: 200,
|
44
|
+
body: '{"Key":"id.error","Message":"No first name submitted"}'
|
45
|
+
|
46
|
+
verify = CrowdPay::Verification.verify verification_attributes, false
|
47
|
+
|
48
|
+
expect(verify.pass?).to eq(false)
|
49
|
+
expect(verify.fail?).to eq(true)
|
50
|
+
expect(verify.soft_fail?).to eq(false)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'soft fail' do
|
55
|
+
it 'shows that a soft fail has occured' do
|
56
|
+
stub_request(:post, url).to_return status: 200,
|
57
|
+
body: FactoryGirl.attributes_for(:verification, :soft_fail).to_json
|
58
|
+
|
59
|
+
verify = CrowdPay::Verification.verify verification_attributes, false
|
60
|
+
|
61
|
+
expect(verify.soft_fail?).to eq(true)
|
62
|
+
expect(verify.fail?).to eq(true)
|
63
|
+
expect(verify.pass?).to eq(false)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '.verify_answers' do
|
69
|
+
let(:url) { 'https://test.crowdpay.com/identification/api/v1/ops/verify-answers' }
|
70
|
+
|
71
|
+
it 'shows that a pass has occured when pass' do
|
72
|
+
stub_request(:post, url).to_return status: 200,
|
73
|
+
body: '{"Id":"1265185524","Key":"result.questions.0.incorrect","Message":"All answers correct","Summary":"pass"}'
|
74
|
+
|
75
|
+
verify = CrowdPay::Verification.verify_answers answers: []
|
76
|
+
|
77
|
+
expect(verify.pass?).to eq(true)
|
78
|
+
expect(verify.fail?).to eq(false)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'shows that a fail has occured when fail' do
|
82
|
+
stub_request(:post, url).to_return status: 200,
|
83
|
+
body: '{"Id":"1265411516","Key":"result.questions.3.incorrect","Message":"Three Incorrect Answers","Summary":"fail"}'
|
84
|
+
|
85
|
+
verify = CrowdPay::Verification.verify_answers answers: []
|
86
|
+
|
87
|
+
expect(verify.fail?).to eq(true)
|
88
|
+
expect(verify.pass?).to eq(false)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|