hypercharge-schema 1.24.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (230) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/.travis.yml +6 -0
  4. data/CHANGELOG.md +3 -0
  5. data/Gemfile +7 -0
  6. data/Gemfile.lock +33 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +73 -0
  9. data/Rakefile +14 -0
  10. data/composer.json +17 -0
  11. data/hypercharge-schema.gemspec +27 -0
  12. data/json/MobilePayment.json +73 -0
  13. data/json/WpfPayment.json +99 -0
  14. data/json/authorize.json +77 -0
  15. data/json/authorize3d.json +173 -0
  16. data/json/capture.json +42 -0
  17. data/json/debit_sale.json +73 -0
  18. data/json/direct_pay24_sale.json +85 -0
  19. data/json/giro_pay_sale.json +85 -0
  20. data/json/ideal_sale.json +87 -0
  21. data/json/init_recurring_authorize.json +81 -0
  22. data/json/init_recurring_debit_authorize.json +77 -0
  23. data/json/init_recurring_debit_sale.json +77 -0
  24. data/json/init_recurring_sale.json +81 -0
  25. data/json/pay_in_advance.json +61 -0
  26. data/json/pay_pal.json +65 -0
  27. data/json/pay_safe_card_sale.json +69 -0
  28. data/json/payment_on_delivery.json +57 -0
  29. data/json/purchase_on_account.json +61 -0
  30. data/json/reconcile.json +20 -0
  31. data/json/recurring_debit_sale.json +45 -0
  32. data/json/recurring_sale.json +45 -0
  33. data/json/referenced_fund_transfer.json +46 -0
  34. data/json/refund.json +42 -0
  35. data/json/sale.json +77 -0
  36. data/json/sale3d.json +173 -0
  37. data/json/scheduler_create.json +46 -0
  38. data/json/scheduler_index.json +34 -0
  39. data/json/scheduler_update.json +35 -0
  40. data/json/types.json +385 -0
  41. data/json/void.json +33 -0
  42. data/lib/php/JsonSchemaFixture.php +12 -0
  43. data/lib/php/JsonSchemaValidator.php +47 -0
  44. data/lib/ruby/hypercharge/schema.rb +31 -0
  45. data/lib/ruby/hypercharge/schema/fixture.rb +30 -0
  46. data/lib/ruby/hypercharge/schema/version.rb +7 -0
  47. data/package.json +27 -0
  48. data/test/fixtures/notifications/PaymentNotification_echo.xml +4 -0
  49. data/test/fixtures/notifications/TransactionNotification_echo.xml +4 -0
  50. data/test/fixtures/notifications/recurring_event.json +13 -0
  51. data/test/fixtures/notifications/scheduler.json +7 -0
  52. data/test/fixtures/requests/MobilePayment.json +35 -0
  53. data/test/fixtures/requests/MobilePayment.xml +34 -0
  54. data/test/fixtures/requests/WpfPayment.json +40 -0
  55. data/test/fixtures/requests/WpfPayment.xml +39 -0
  56. data/test/fixtures/requests/WpfPayment_cancel.xml +4 -0
  57. data/test/fixtures/requests/WpfPayment_capture.xml +4 -0
  58. data/test/fixtures/requests/WpfPayment_refund.xml +4 -0
  59. data/test/fixtures/requests/WpfPayment_void.xml +4 -0
  60. data/test/fixtures/requests/authorize.json +29 -0
  61. data/test/fixtures/requests/authorize.xml +28 -0
  62. data/test/fixtures/requests/authorize3d_async.json +32 -0
  63. data/test/fixtures/requests/authorize3d_async.xml +31 -0
  64. data/test/fixtures/requests/authorize3d_sync.json +34 -0
  65. data/test/fixtures/requests/authorize3d_sync.xml +33 -0
  66. data/test/fixtures/requests/capture.json +10 -0
  67. data/test/fixtures/requests/capture.xml +9 -0
  68. data/test/fixtures/requests/debit_sale.json +28 -0
  69. data/test/fixtures/requests/debit_sale.xml +27 -0
  70. data/test/fixtures/requests/direct_pay24_sale.json +31 -0
  71. data/test/fixtures/requests/direct_pay24_sale.xml +30 -0
  72. data/test/fixtures/requests/giro_pay_sale.json +31 -0
  73. data/test/fixtures/requests/giro_pay_sale.xml +30 -0
  74. data/test/fixtures/requests/ideal_sale.json +31 -0
  75. data/test/fixtures/requests/ideal_sale.xml +30 -0
  76. data/test/fixtures/requests/init_recurring_authorize.json +34 -0
  77. data/test/fixtures/requests/init_recurring_authorize.xml +33 -0
  78. data/test/fixtures/requests/init_recurring_debit_authorize.json +33 -0
  79. data/test/fixtures/requests/init_recurring_debit_authorize.xml +32 -0
  80. data/test/fixtures/requests/init_recurring_debit_sale.json +34 -0
  81. data/test/fixtures/requests/init_recurring_debit_sale.xml +32 -0
  82. data/test/fixtures/requests/init_recurring_sale.json +34 -0
  83. data/test/fixtures/requests/init_recurring_sale.xml +33 -0
  84. data/test/fixtures/requests/init_recurring_sale_with_recurring_schedule.json +34 -0
  85. data/test/fixtures/requests/pay_in_advance.json +24 -0
  86. data/test/fixtures/requests/pay_in_advance.xml +23 -0
  87. data/test/fixtures/requests/pay_pal.json +23 -0
  88. data/test/fixtures/requests/pay_pal.xml +22 -0
  89. data/test/fixtures/requests/pay_safe_card_sale.json +23 -0
  90. data/test/fixtures/requests/pay_safe_card_sale.xml +23 -0
  91. data/test/fixtures/requests/payment_on_delivery.json +24 -0
  92. data/test/fixtures/requests/payment_on_delivery.xml +23 -0
  93. data/test/fixtures/requests/purchase_on_account.json +26 -0
  94. data/test/fixtures/requests/purchase_on_account.xml +23 -0
  95. data/test/fixtures/requests/reconcile.json +5 -0
  96. data/test/fixtures/requests/reconcile.xml +4 -0
  97. data/test/fixtures/requests/reconcile_by_date.json +7 -0
  98. data/test/fixtures/requests/reconcile_by_date.xml +6 -0
  99. data/test/fixtures/requests/recurring_debit_sale.json +11 -0
  100. data/test/fixtures/requests/recurring_debit_sale.xml +10 -0
  101. data/test/fixtures/requests/recurring_event.xml +4 -0
  102. data/test/fixtures/requests/recurring_sale.json +11 -0
  103. data/test/fixtures/requests/recurring_sale.xml +10 -0
  104. data/test/fixtures/requests/referenced_fund_transfer.json +11 -0
  105. data/test/fixtures/requests/referenced_fund_transfer.xml +10 -0
  106. data/test/fixtures/requests/refund.json +10 -0
  107. data/test/fixtures/requests/refund.xml +9 -0
  108. data/test/fixtures/requests/risk_params.json +10 -0
  109. data/test/fixtures/requests/risk_params.xml +9 -0
  110. data/test/fixtures/requests/sale.json +29 -0
  111. data/test/fixtures/requests/sale.xml +28 -0
  112. data/test/fixtures/requests/sale3d_async.json +32 -0
  113. data/test/fixtures/requests/sale3d_async.xml +31 -0
  114. data/test/fixtures/requests/sale3d_sync.json +34 -0
  115. data/test/fixtures/requests/sale3d_sync.xml +33 -0
  116. data/test/fixtures/requests/scheduler_create.json +9 -0
  117. data/test/fixtures/requests/scheduler_index_get_params.json +9 -0
  118. data/test/fixtures/requests/scheduler_update.json +8 -0
  119. data/test/fixtures/requests/void.json +8 -0
  120. data/test/fixtures/requests/void.xml +7 -0
  121. data/test/fixtures/responses/MobilePayment_new.json +20 -0
  122. data/test/fixtures/responses/MobilePayment_new.xml +19 -0
  123. data/test/fixtures/responses/PaymentNotification_echo.xml +4 -0
  124. data/test/fixtures/responses/PaymentTransactionNotification_echo.xml +4 -0
  125. data/test/fixtures/responses/WpfPayment_cancel.xml +13 -0
  126. data/test/fixtures/responses/WpfPayment_captured.xml +39 -0
  127. data/test/fixtures/responses/WpfPayment_error.json +8 -0
  128. data/test/fixtures/responses/WpfPayment_error.xml +7 -0
  129. data/test/fixtures/responses/WpfPayment_find.xml +39 -0
  130. data/test/fixtures/responses/WpfPayment_new.json +16 -0
  131. data/test/fixtures/responses/WpfPayment_new.xml +17 -0
  132. data/test/fixtures/responses/WpfPayment_refunded.xml +39 -0
  133. data/test/fixtures/responses/WpfPayment_voided.xml +39 -0
  134. data/test/fixtures/responses/authorize3d_pending_async.xml +15 -0
  135. data/test/fixtures/responses/authorize3d_sync.xml +14 -0
  136. data/test/fixtures/responses/authorize_approved.xml +14 -0
  137. data/test/fixtures/responses/authorize_error.json +16 -0
  138. data/test/fixtures/responses/authorize_error.xml +15 -0
  139. data/test/fixtures/responses/capture.xml +14 -0
  140. data/test/fixtures/responses/create_chargeback.xml +12 -0
  141. data/test/fixtures/responses/create_chargeback_reversal.xml +12 -0
  142. data/test/fixtures/responses/create_charged_debit_sale.xml +12 -0
  143. data/test/fixtures/responses/create_debit_chargeback.xml +12 -0
  144. data/test/fixtures/responses/create_deposit.xml +12 -0
  145. data/test/fixtures/responses/create_pre_arbitration.xml +12 -0
  146. data/test/fixtures/responses/create_rejected_debit_sale.xml +12 -0
  147. data/test/fixtures/responses/create_retrieval_request.xml +12 -0
  148. data/test/fixtures/responses/debit_sale.xml +12 -0
  149. data/test/fixtures/responses/direct_pay24_sale.xml +15 -0
  150. data/test/fixtures/responses/giro_pay_sale.xml +15 -0
  151. data/test/fixtures/responses/ideal_sale.xml +17 -0
  152. data/test/fixtures/responses/init_recurring_authorize.xml +14 -0
  153. data/test/fixtures/responses/init_recurring_debit_authorize.xml +17 -0
  154. data/test/fixtures/responses/init_recurring_debit_sale.xml +17 -0
  155. data/test/fixtures/responses/init_recurring_sale.xml +14 -0
  156. data/test/fixtures/responses/pay_in_advance.xml +17 -0
  157. data/test/fixtures/responses/pay_pal.xml +15 -0
  158. data/test/fixtures/responses/pay_safe_card_sale.xml +15 -0
  159. data/test/fixtures/responses/payment_on_delivery.xml +14 -0
  160. data/test/fixtures/responses/purchase_on_account.xml +18 -0
  161. data/test/fixtures/responses/reconcile_by_date_empty_result.xml +3 -0
  162. data/test/fixtures/responses/reconcile_by_date_page_1.xml +1293 -0
  163. data/test/fixtures/responses/reconcile_by_date_page_2.xml +1346 -0
  164. data/test/fixtures/responses/reconcile_by_date_page_3.xml +1394 -0
  165. data/test/fixtures/responses/reconcile_by_date_single_result.xml +16 -0
  166. data/test/fixtures/responses/recurring_debit_sale.xml +16 -0
  167. data/test/fixtures/responses/recurring_event.json +22 -0
  168. data/test/fixtures/responses/recurring_event.xml +21 -0
  169. data/test/fixtures/responses/recurring_sale.xml +14 -0
  170. data/test/fixtures/responses/referenced_fund_transfer.xml +14 -0
  171. data/test/fixtures/responses/refund.xml +14 -0
  172. data/test/fixtures/responses/sale.xml +12 -0
  173. data/test/fixtures/responses/sale3d_async.xml +15 -0
  174. data/test/fixtures/responses/sale3d_sync.xml +14 -0
  175. data/test/fixtures/responses/scheduled_transactions_empty.json +8 -0
  176. data/test/fixtures/responses/scheduled_transactions_one.json +22 -0
  177. data/test/fixtures/responses/scheduler.json +12 -0
  178. data/test/fixtures/responses/scheduler_empty_result.json +8 -0
  179. data/test/fixtures/responses/scheduler_error.json +7 -0
  180. data/test/fixtures/responses/scheduler_next.json +4 -0
  181. data/test/fixtures/responses/scheduler_page_1.json +93 -0
  182. data/test/fixtures/responses/scheduler_page_2.json +45 -0
  183. data/test/fixtures/responses/scheduler_single_result.json +21 -0
  184. data/test/fixtures/responses/void.xml +12 -0
  185. data/test/js/mobile_payment_test.js +287 -0
  186. data/test/php/all.php +9 -0
  187. data/test/php/authorize3d_test.php +546 -0
  188. data/test/php/authorize_test.php +546 -0
  189. data/test/php/capture_test.php +241 -0
  190. data/test/php/json_schema_validator_test.php +24 -0
  191. data/test/php/mobile_payment_test.php +238 -0
  192. data/test/php/reconcile_test.php +21 -0
  193. data/test/php/referenced_fund_transfer_test.php +183 -0
  194. data/test/php/refund_test.php +237 -0
  195. data/test/php/sale_test.php +546 -0
  196. data/test/php/test_helper.php +29 -0
  197. data/test/php/void_test.php +163 -0
  198. data/test/php/wpf_payment_test.php +19 -0
  199. data/test/ruby/authorize3d_async_spec.rb +29 -0
  200. data/test/ruby/authorize3d_sync_spec.rb +27 -0
  201. data/test/ruby/authorize_spec.rb +25 -0
  202. data/test/ruby/capture_spec.rb +16 -0
  203. data/test/ruby/debit_sale_spec.rb +26 -0
  204. data/test/ruby/direct_pay24_sale_spec.rb +30 -0
  205. data/test/ruby/giro_pay_sale_spec.rb +30 -0
  206. data/test/ruby/ideal_sale_spec.rb +29 -0
  207. data/test/ruby/init_recurring_authorize_spec.rb +26 -0
  208. data/test/ruby/init_recurring_debit_authorize_spec.rb +27 -0
  209. data/test/ruby/init_recurring_debit_sale_spec.rb +27 -0
  210. data/test/ruby/init_recurring_sale_spec.rb +26 -0
  211. data/test/ruby/mobile_payment_spec.rb +22 -0
  212. data/test/ruby/pay_in_advance_spec.rb +23 -0
  213. data/test/ruby/pay_pal_spec.rb +25 -0
  214. data/test/ruby/pay_safe_card_sale_spec.rb +24 -0
  215. data/test/ruby/payment_on_delivery_spec.rb +21 -0
  216. data/test/ruby/purchase_on_account_spec.rb +23 -0
  217. data/test/ruby/reconcile_spec.rb +11 -0
  218. data/test/ruby/recurring_debit_sale_spec.rb +17 -0
  219. data/test/ruby/recurring_sale_spec.rb +17 -0
  220. data/test/ruby/referenced_fund_transfer_spec.rb +17 -0
  221. data/test/ruby/refund_spec.rb +16 -0
  222. data/test/ruby/sale3d_async_spec.rb +29 -0
  223. data/test/ruby/sale3d_sync_spec.rb +27 -0
  224. data/test/ruby/sale_spec.rb +25 -0
  225. data/test/ruby/scheduler_spec.rb +43 -0
  226. data/test/ruby/test_helper.rb +74 -0
  227. data/test/ruby/types_specs.rb +1494 -0
  228. data/test/ruby/void_spec.rb +14 -0
  229. data/test/ruby/wpf_payment_spec.rb +27 -0
  230. metadata +527 -0
@@ -0,0 +1,74 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+ require 'minitest/autorun'
6
+ require 'json'
7
+ require 'json-schema'
8
+ require 'types_specs'
9
+
10
+
11
+ class FixtureInvalidError < StandardError
12
+ end
13
+
14
+ # works with minitest 4.x and 5.x
15
+ class MiniTest::Spec
16
+
17
+ before do
18
+ errors = JSON::Validator.fully_validate(schema_path, subject, :version => :draft3)
19
+ unless errors.size.zero?
20
+ raise FixtureInvalidError, errors.inspect
21
+ end
22
+ end
23
+
24
+ def validate(schema_path, data)
25
+ JSON::Validator.validate(schema_path, data, :version => :draft3)
26
+ end
27
+
28
+ def schema_path_for(name)
29
+ File.expand_path("../../../json/#{name}.json", __FILE__)
30
+ end
31
+
32
+ def fixture(name)
33
+ JSON.parse(IO.read(File.expand_path("../../fixtures/requests/#{name}.json", __FILE__)))
34
+ end
35
+
36
+
37
+ class << self
38
+ def wont_allow_additional_properties
39
+ describe 'root' do
40
+ it 'wont allow additionalProperties' do
41
+ subject['notInSchema'] = 1
42
+ validate(schema_path, subject).must_equal false
43
+ end
44
+ end
45
+ end
46
+
47
+ def root_wont_allow_additional_properties
48
+ describe 'root' do
49
+ it 'wont allow additionalProperties' do
50
+ subject[root_key]['notInSchema'] = 1
51
+ validate(schema_path, subject).must_equal false
52
+ end
53
+ end
54
+ end
55
+
56
+ def spec_attribute attr_name, options = {}
57
+ spec_name = options[:spec] || attr_name
58
+ spec_proc = TypesSpecs.proc_for(spec_name)
59
+
60
+ options[:required] ||= false
61
+
62
+ raise "Spec for #{spec_name} missing" unless spec_proc
63
+
64
+ cls = describe attr_name, &spec_proc
65
+ # add some attr_name and options as locals
66
+ cls.class_eval do
67
+ let(:attr_name) { attr_name }
68
+ options.each do |k, v|
69
+ let(k){ v }
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,1494 @@
1
+ class TypesSpecs
2
+ @@registry = {}
3
+ def self.describe desc, &block
4
+ @@registry[desc] = block
5
+ end
6
+
7
+ def self.proc_for(key)
8
+ registry[key]
9
+ end
10
+
11
+ def self.registry
12
+ @@registry
13
+ end
14
+
15
+
16
+ describe 'transaction_type' do
17
+ it 'is a static string' do
18
+ subject[root_key]['transaction_type'] = value
19
+ validate(schema_path, subject).must_equal true
20
+ end
21
+
22
+ it 'is a present' do
23
+ subject[root_key].delete('transaction_type')
24
+ validate(schema_path, subject).must_equal false
25
+ end
26
+
27
+ it 'wont allow nil' do
28
+ subject[root_key]['transaction_type'] = nil
29
+ validate(schema_path, subject).must_equal false
30
+ end
31
+
32
+ it 'wont allow other string' do
33
+ subject[root_key]['transaction_type'] = "#{value}nope"
34
+ validate(schema_path, subject).must_equal false
35
+ end
36
+
37
+ it 'wont allow integer' do
38
+ subject[root_key]['transaction_type'] = 1
39
+ validate(schema_path, subject).must_equal false
40
+ end
41
+ end
42
+
43
+ describe 'type' do
44
+ it 'is a static string' do
45
+ subject[root_key]['type'] = value
46
+ validate(schema_path, subject).must_equal true
47
+ end
48
+
49
+ it 'must be present' do
50
+ subject[root_key].delete('type')
51
+ validate(schema_path, subject).must_equal false
52
+ end
53
+
54
+ it 'wont allow nil' do
55
+ subject[root_key]['type'] = nil
56
+ validate(schema_path, subject).must_equal false
57
+ end
58
+
59
+ it 'wont allow other string' do
60
+ subject[root_key]['type'] = "#{value}nope"
61
+ validate(schema_path, subject).must_equal false
62
+ end
63
+
64
+ it 'wont allow integer' do
65
+ subject[root_key]['type'] = 1
66
+ validate(schema_path, subject).must_equal false
67
+ end
68
+ end
69
+
70
+ describe 'amount' do
71
+
72
+ it 'must be present' do
73
+ subject[root_key].delete('amount')
74
+ validate(schema_path, subject).must_equal false
75
+ end
76
+
77
+ it 'must be an integer' do
78
+ subject[root_key]['amount'] = 'one'
79
+ validate(schema_path, subject).must_equal false
80
+ end
81
+
82
+ it 'wont allow 0' do
83
+ subject[root_key]['amount'] = 0
84
+ validate(schema_path, subject).must_equal false
85
+ end
86
+
87
+ it 'wont allow negaitive values' do
88
+ subject[root_key]['amount'] = -1
89
+ validate(schema_path, subject).must_equal false
90
+ end
91
+ end
92
+
93
+ describe 'v2_amount' do
94
+
95
+ it 'must be present' do
96
+ subject.delete('amount')
97
+ validate(schema_path, subject).must_equal !required
98
+ end
99
+
100
+ it 'must be an integer' do
101
+ subject['amount'] = 'one'
102
+ validate(schema_path, subject).must_equal false
103
+ end
104
+
105
+ it 'wont allow 0' do
106
+ subject['amount'] = 0
107
+ validate(schema_path, subject).must_equal false
108
+ end
109
+
110
+ it 'wont allow negaitive values' do
111
+ subject['amount'] = -1
112
+ validate(schema_path, subject).must_equal false
113
+ end
114
+ end
115
+
116
+ describe 'currency' do
117
+ it 'must be present' do
118
+ subject[root_key].delete('currency')
119
+ validate(schema_path, subject).must_equal false
120
+ end
121
+
122
+ it 'must be ISO 4217' do
123
+ subject[root_key]['currency'] = 'Euros'
124
+ validate(schema_path, subject).must_equal false
125
+ end
126
+ end
127
+
128
+ describe 'transaction_id' do
129
+ it 'must be present' do
130
+ subject[root_key].delete('transaction_id')
131
+ validate(schema_path, subject).must_equal false
132
+ end
133
+
134
+ it 'wont be empty' do
135
+ subject[root_key]['transaction_id'] = ''
136
+ validate(schema_path, subject).must_equal false
137
+ end
138
+
139
+ it 'must allow size = 1' do
140
+ subject[root_key]['transaction_id'] = 'a'
141
+ validate(schema_path, subject).must_equal true
142
+ end
143
+
144
+ it 'must allow size = 255' do
145
+ subject[root_key]['transaction_id'] = 'a'* 255
146
+ validate(schema_path, subject).must_equal true
147
+ end
148
+
149
+ it 'wont allow size > 255' do
150
+ subject[root_key]['transaction_id'] = 'a'* 256
151
+ validate(schema_path, subject).must_equal false
152
+ end
153
+
154
+ it 'must match pattern' do
155
+ subject[root_key]['transaction_id'] = '%'
156
+ validate(schema_path, subject).must_equal false
157
+ end
158
+ end
159
+
160
+ describe 'usage' do
161
+ it 'presence' do
162
+ subject[root_key].delete('usage')
163
+ validate(schema_path, subject).must_equal !required
164
+ end
165
+
166
+ it 'wont be empty' do
167
+ subject[root_key]['usage'] = ''
168
+ validate(schema_path, subject).must_equal false
169
+ end
170
+
171
+ it 'must allow size = 255' do
172
+ subject[root_key]['usage'] = 'a' * 255
173
+ validate(schema_path, subject).must_equal true
174
+ end
175
+
176
+ it 'wont allow size > 255' do
177
+ subject[root_key]['usage'] = 'a' * 256
178
+ validate(schema_path, subject).must_equal false
179
+ end
180
+ end
181
+
182
+ describe 'description' do
183
+ it 'is required' do
184
+ subject[root_key].delete('description')
185
+ validate(schema_path, subject).must_equal false
186
+ end
187
+
188
+ it 'wont be empty' do
189
+ subject[root_key]['description'] = ''
190
+ validate(schema_path, subject).must_equal false
191
+ end
192
+
193
+ it 'must allow size = 1' do
194
+ subject[root_key]['description'] = 'a'
195
+ validate(schema_path, subject).must_equal true
196
+ end
197
+
198
+ it 'must allow size = 12400' do
199
+ subject[root_key]['description'] = 'a' * 12400
200
+ validate(schema_path, subject).must_equal true
201
+ end
202
+ end
203
+
204
+ describe 'editable_by_user' do
205
+ it 'is optional' do
206
+ subject[root_key].delete('editable_by_user')
207
+ validate(schema_path, subject).must_equal true
208
+ end
209
+
210
+ it 'wont be empty string' do
211
+ subject[root_key]['editable_by_user'] = ''
212
+ validate(schema_path, subject).must_equal false
213
+ end
214
+
215
+ it 'wont be integer' do
216
+ subject[root_key]['editable_by_user'] = 0
217
+ validate(schema_path, subject).must_equal false
218
+ end
219
+
220
+ it 'must allow true' do
221
+ subject[root_key]['editable_by_user'] = true
222
+ validate(schema_path, subject).must_equal true
223
+ end
224
+
225
+ it 'must allow false' do
226
+ subject[root_key]['editable_by_user'] = false
227
+ validate(schema_path, subject).must_equal true
228
+ end
229
+ end
230
+
231
+ describe 'customer_email' do
232
+ # if required
233
+ it 'presence' do
234
+ subject[root_key].delete('customer_email')
235
+ validate(schema_path, subject).must_equal !required
236
+ end
237
+ # else
238
+ # it 'must be present optional' do
239
+ # subject[root_key].delete('customer_email')
240
+ # validate(schema_path, subject).must_equal false
241
+ # end
242
+ # end
243
+
244
+ it 'must be an email address' do
245
+ subject[root_key]['customer_email'] = 'this-is-no-email-address.com'
246
+ validate(schema_path, subject).must_equal false
247
+ end
248
+ end
249
+
250
+ describe 'customer_phone' do
251
+ it 'is optional' do
252
+ subject[root_key].delete('customer_phone')
253
+ validate(schema_path, subject).must_equal true
254
+ end
255
+
256
+ it 'wont be empty' do
257
+ subject[root_key]['customer_phone'] = ''
258
+ validate(schema_path, subject).must_equal false
259
+ end
260
+
261
+ it 'must allow size = 255' do
262
+ subject[root_key]['customer_phone'] = '0' * 255
263
+ validate(schema_path, subject).must_equal true
264
+ end
265
+
266
+ it 'wont allow size > 255' do
267
+ subject[root_key]['customer_phone'] = '0' * 256
268
+ validate(schema_path, subject).must_equal false
269
+ end
270
+ end
271
+
272
+ describe 'url' do
273
+ it 'must be present' do
274
+ subject[root_key].delete(attr_name)
275
+ validate(schema_path, subject).must_equal false
276
+ end
277
+
278
+ it 'wont be empty' do
279
+ subject[root_key][attr_name] = ''
280
+ validate(schema_path, subject).must_equal false
281
+ end
282
+
283
+ it 'must allow http' do
284
+ subject[root_key][attr_name] = 'http://exmaple.com/notify'
285
+ validate(schema_path, subject).must_equal true
286
+ end
287
+
288
+ it 'must allow https' do
289
+ subject[root_key][attr_name] = 'https://exmaple.com/notify'
290
+ validate(schema_path, subject).must_equal true
291
+ end
292
+
293
+ it 'must be a URL' do
294
+ subject[root_key][attr_name] = 'This is no URL'
295
+ validate(schema_path, subject).must_equal false
296
+ end
297
+ end
298
+
299
+ describe 'billing_address' do
300
+ describe 'the object' do
301
+ it 'wont allow additionalProperties' do
302
+ subject[root_key]['billing_address']['notInSchema'] = 1
303
+ validate(schema_path, subject).must_equal false
304
+ end
305
+ end
306
+
307
+ it 'presence' do
308
+ subject[root_key].delete('billing_address')
309
+ validate(schema_path, subject).must_equal !required
310
+ end
311
+
312
+ it 'must be an object' do
313
+ subject[root_key]['billing_address'] = 'no object'
314
+ validate(schema_path, subject).must_equal false
315
+ end
316
+
317
+ describe 'first_name' do
318
+ it 'must be present' do
319
+ subject[root_key]['billing_address'].delete('first_name')
320
+ validate(schema_path, subject).must_equal false
321
+ end
322
+
323
+ it 'wont be empty' do
324
+ subject[root_key]['billing_address']['first_name'] = ''
325
+ validate(schema_path, subject).must_equal false
326
+ end
327
+
328
+ it 'must allow size = 255' do
329
+ subject[root_key]['billing_address']['first_name'] = 'a' * 255
330
+ validate(schema_path, subject).must_equal true
331
+ end
332
+
333
+ it 'wont allow size > 255' do
334
+ subject[root_key]['billing_address']['first_name'] = 'a' * 256
335
+ validate(schema_path, subject).must_equal false
336
+ end
337
+ end
338
+
339
+ describe 'last_name' do
340
+ it 'must be present' do
341
+ subject[root_key]['billing_address'].delete('last_name')
342
+ validate(schema_path, subject).must_equal false
343
+ end
344
+
345
+ it 'wont be empty' do
346
+ subject[root_key]['billing_address']['last_name'] = ''
347
+ validate(schema_path, subject).must_equal false
348
+ end
349
+
350
+ it 'must allow size = 255' do
351
+ subject[root_key]['billing_address']['last_name'] = 'a' * 255
352
+ validate(schema_path, subject).must_equal true
353
+ end
354
+
355
+ it 'wont allow size > 255' do
356
+ subject[root_key]['billing_address']['last_name'] = 'a' * 256
357
+ validate(schema_path, subject).must_equal false
358
+ end
359
+ end
360
+
361
+
362
+ describe 'address1' do
363
+ it 'must be present' do
364
+ subject[root_key]['billing_address'].delete('address1')
365
+ validate(schema_path, subject).must_equal false
366
+ end
367
+
368
+ it 'wont be empty' do
369
+ subject[root_key]['billing_address']['address1'] = ''
370
+ validate(schema_path, subject).must_equal false
371
+ end
372
+
373
+ it 'must allow size = 255' do
374
+ subject[root_key]['billing_address']['address1'] = 'a' * 255
375
+ validate(schema_path, subject).must_equal true
376
+ end
377
+
378
+ it 'wont allow size > 255' do
379
+ subject[root_key]['billing_address']['address1'] = 'a' * 256
380
+ validate(schema_path, subject).must_equal false
381
+ end
382
+ end
383
+
384
+ describe 'address2' do
385
+ it 'is optional' do
386
+ subject[root_key]['billing_address'].delete('address2')
387
+ validate(schema_path, subject).must_equal true
388
+ end
389
+
390
+ it 'wont be empty' do
391
+ subject[root_key]['billing_address']['address2'] = ''
392
+ validate(schema_path, subject).must_equal false
393
+ end
394
+
395
+ it 'must allow size = 255' do
396
+ subject[root_key]['billing_address']['address2'] = 'a' * 255
397
+ validate(schema_path, subject).must_equal true
398
+ end
399
+
400
+ it 'wont allow size > 255' do
401
+ subject[root_key]['billing_address']['address2'] = 'a' * 256
402
+ validate(schema_path, subject).must_equal false
403
+ end
404
+ end
405
+
406
+ describe 'city' do
407
+ it 'must be present' do
408
+ subject[root_key]['billing_address'].delete('city')
409
+ validate(schema_path, subject).must_equal false
410
+ end
411
+
412
+ it 'wont be empty' do
413
+ subject[root_key]['billing_address']['city'] = ''
414
+ validate(schema_path, subject).must_equal false
415
+ end
416
+
417
+ it 'must allow size = 255' do
418
+ subject[root_key]['billing_address']['city'] = 'a' * 255
419
+ validate(schema_path, subject).must_equal true
420
+ end
421
+
422
+ it 'wont allow size > 255' do
423
+ subject[root_key]['billing_address']['city'] = 'a' * 256
424
+ validate(schema_path, subject).must_equal false
425
+ end
426
+ end
427
+
428
+ describe 'zip_code' do
429
+ it 'must be present' do
430
+ subject[root_key]['billing_address'].delete('zip_code')
431
+ validate(schema_path, subject).must_equal false
432
+ end
433
+
434
+ it 'wont be empty' do
435
+ subject[root_key]['billing_address']['zip_code'] = ''
436
+ validate(schema_path, subject).must_equal false
437
+ end
438
+
439
+ it 'must allow size = 32' do
440
+ subject[root_key]['billing_address']['zip_code'] = 'a' * 32
441
+ validate(schema_path, subject).must_equal true
442
+ end
443
+
444
+ it 'wont allow size > 32' do
445
+ subject[root_key]['billing_address']['zip_code'] = 'a' * 33
446
+ validate(schema_path, subject).must_equal false
447
+ end
448
+ end
449
+
450
+ describe 'state' do
451
+ it 'is optional' do
452
+ validate(schema_path, subject).must_equal true
453
+ end
454
+
455
+ it 'must allow ISO 3166_2 in USA' do
456
+ subject[root_key]['billing_address']['state'] = 'CA'
457
+ validate(schema_path, subject).must_equal true
458
+ end
459
+
460
+ it 'must allow ISO 3166_2 in Canada' do
461
+ subject[root_key]['billing_address']['state'] = 'AB'
462
+ validate(schema_path, subject).must_equal true
463
+ end
464
+
465
+ it 'wont allow other' do
466
+ subject[root_key]['billing_address']['state'] = 'XX'
467
+ validate(schema_path, subject).must_equal false
468
+ end
469
+ end
470
+
471
+ describe 'country' do
472
+ it 'must be present' do
473
+ subject[root_key]['billing_address'].delete('country')
474
+ validate(schema_path, subject).must_equal false
475
+ end
476
+
477
+ it 'must allow US' do
478
+ subject[root_key]['billing_address']['country'] = 'US'
479
+ validate(schema_path, subject).must_equal true
480
+ end
481
+
482
+ it 'wont allow USA' do
483
+ subject[root_key]['billing_address']['country'] = 'USA'
484
+ validate(schema_path, subject).must_equal false
485
+ end
486
+
487
+ it 'wont allow XX' do
488
+ subject[root_key]['billing_address']['country'] = 'XX'
489
+ validate(schema_path, subject).must_equal false
490
+ end
491
+ end
492
+
493
+ end
494
+
495
+ describe 'transaction_types' do
496
+ it 'is optional' do
497
+ subject[root_key].delete('transaction_types')
498
+ validate(schema_path, subject).must_equal true
499
+ end
500
+
501
+ it 'must allow customer initiated payments_transaction types' do
502
+ ['authorize', 'authorize3d', 'sale', 'sale3d', 'init_recurring_sale',
503
+ 'ideal_sale', 'debit_sale', 'sepa_debit', 'direct_pay24_sale',
504
+ 'giro_pay_sale', 'pay_safe_card_sale', 'init_recurring_authorize',
505
+ 'purchase_on_account', 'pay_in_advance', 'deposit', 'payment_on_delivery',
506
+ 'pay_pal', 'init_recurring_debit_sale', 'init_recurring_debit_authorize',
507
+ 'recurring_debit_sale', 'barzahlen_sale'].each do |tt|
508
+ subject[root_key]['transaction_types'] = [tt]
509
+ validate(schema_path, subject).must_equal true
510
+ end
511
+ end
512
+
513
+ it 'wont allow arbitrary values' do
514
+ subject[root_key]['transaction_types'] = ['NOPE']
515
+ validate(schema_path, subject).must_equal false
516
+ end
517
+
518
+ it 'wont allow empty array' do
519
+ subject[root_key]['transaction_types'] = []
520
+ validate(schema_path, subject).must_equal false
521
+ end
522
+
523
+ it 'wont allow non array type' do
524
+ subject[root_key]['transaction_types'] = 'not an array!'
525
+ validate(schema_path, subject).must_equal false
526
+ end
527
+ end
528
+
529
+
530
+ describe 'retries' do
531
+ it 'is optional' do
532
+ subject[root_key].delete('retries')
533
+ validate(schema_path, subject).must_equal true
534
+ end
535
+
536
+ it 'wont be nil' do
537
+ subject[root_key]['retries'] = nil
538
+ validate(schema_path, subject).must_equal false
539
+ end
540
+
541
+ it 'must be an integer' do
542
+ subject[root_key]['retries'] = 'not an integer!'
543
+ validate(schema_path, subject).must_equal false
544
+ end
545
+
546
+ it 'wont be 0' do
547
+ subject[root_key]['retries'] = 0
548
+ validate(schema_path, subject).must_equal false
549
+ end
550
+
551
+ it 'must be postive' do
552
+ subject[root_key]['retries'] = -1
553
+ validate(schema_path, subject).must_equal false
554
+ end
555
+ end
556
+
557
+ describe 'risk_params' do
558
+ describe 'the object' do
559
+ it 'wont allow additionalProperties' do
560
+ subject[root_key]['risk_params']['notInSchema'] = 1
561
+ validate(schema_path, subject).must_equal false
562
+ end
563
+ end
564
+
565
+ it 'is optional' do
566
+ subject[root_key].delete('risk_params')
567
+ validate(schema_path, subject).must_equal true
568
+ end
569
+
570
+ it 'must allow the following known keys' do
571
+ ['ssn', 'mac_address', 'session_id', 'user_id', 'user_level',
572
+ 'email', 'phone', 'remote_ip', 'serial_number', 'infocapture_token'].each do |tt|
573
+ subject[root_key]['risk_params'] = {tt => 'a string'}
574
+ validate(schema_path, subject).must_equal true
575
+ end
576
+ end
577
+
578
+ it 'wont allow two keys in items' do
579
+ subject[root_key]['risk_params'] = [{'ssn' => 'a string', 'user_level' => '1'}]
580
+ validate(schema_path, subject).must_equal false
581
+ end
582
+
583
+
584
+ it 'wont allow arbitrary keys in items' do
585
+ subject[root_key]['risk_params'] = {'NOPE' => 'a string'}
586
+ validate(schema_path, subject).must_equal false
587
+ end
588
+
589
+ # TODO:
590
+ # it 'wont allow empty object' do
591
+ # subject[root_key]['risk_params'] = {}
592
+ # validate(schema_path, subject).must_equal false
593
+ # end
594
+
595
+ it 'wont allow non object type' do
596
+ subject[root_key]['risk_params'] = 'not an object!'
597
+ validate(schema_path, subject).must_equal false
598
+ end
599
+
600
+ it 'wont allow array' do
601
+ subject[root_key]['risk_params'] = ['not an object!']
602
+ validate(schema_path, subject).must_equal false
603
+ end
604
+
605
+ end
606
+
607
+ describe 'recurring_schedule' do
608
+ it 'is optional' do
609
+ subject[root_key].delete('recurring_schedule')
610
+ validate(schema_path, subject).must_equal true
611
+ end
612
+
613
+ it 'must be an object' do
614
+ subject[root_key]['recurring_schedule'] = "not an object!"
615
+ validate(schema_path, subject).must_equal false
616
+ end
617
+
618
+ describe 'start_date' do
619
+ it 'must be present' do
620
+ subject[root_key]['recurring_schedule'].delete('start_date')
621
+ validate(schema_path, subject).must_equal false
622
+ end
623
+
624
+ it 'must be a string' do
625
+ subject[root_key]['recurring_schedule']['start_date'] = 1
626
+ validate(schema_path, subject).must_equal false
627
+ end
628
+
629
+ it 'must allow date format YYYY-MM-DD' do
630
+ subject[root_key]['recurring_schedule']['start_date'] = "2013-12-01"
631
+ validate(schema_path, subject).must_equal true
632
+ end
633
+
634
+ it 'wont allow other formats' do
635
+ subject[root_key]['recurring_schedule']['start_date'] = "2013/12/01"
636
+ validate(schema_path, subject).must_equal false
637
+ end
638
+
639
+ it 'wont allow impossible date' do
640
+ subject[root_key]['recurring_schedule']['start_date'] = "2013-22-01"
641
+ validate(schema_path, subject).must_equal false
642
+
643
+ subject[root_key]['recurring_schedule']['start_date'] = "2013-01-41"
644
+ validate(schema_path, subject).must_equal false
645
+ end
646
+
647
+ it 'wont allow arbitrary string' do
648
+ subject[root_key]['recurring_schedule']['start_date'] = "not a date format"
649
+ validate(schema_path, subject).must_equal false
650
+ end
651
+
652
+ end
653
+
654
+ describe 'end_date' do
655
+ it 'is optional' do
656
+ subject[root_key]['recurring_schedule'].delete('end_date')
657
+ validate(schema_path, subject).must_equal true
658
+ end
659
+
660
+ it 'must be a string' do
661
+ subject[root_key]['recurring_schedule']['end_date'] = 1
662
+ validate(schema_path, subject).must_equal false
663
+ end
664
+
665
+ it 'must allow date format YYYY-MM-DD' do
666
+ subject[root_key]['recurring_schedule']['end_date'] = "2013-12-01"
667
+ validate(schema_path, subject).must_equal true
668
+ end
669
+
670
+ it 'wont allow other formats' do
671
+ subject[root_key]['recurring_schedule']['end_date'] = "2013/12/01"
672
+ validate(schema_path, subject).must_equal false
673
+ end
674
+
675
+ it 'wont allow impossible date' do
676
+ subject[root_key]['recurring_schedule']['end_date'] = "2013-22-01"
677
+ validate(schema_path, subject).must_equal false
678
+
679
+ subject[root_key]['recurring_schedule']['end_date'] = "2013-01-41"
680
+ validate(schema_path, subject).must_equal false
681
+ end
682
+
683
+ it 'wont allow arbitrary string' do
684
+ subject[root_key]['recurring_schedule']['end_date'] = "not a date format"
685
+ validate(schema_path, subject).must_equal false
686
+ end
687
+
688
+ end
689
+
690
+ describe 'amount' do
691
+ it 'must be present' do
692
+ subject[root_key]['recurring_schedule'].delete('amount')
693
+ validate(schema_path, subject).must_equal false
694
+ end
695
+
696
+ it 'must validate amount is integer' do
697
+ subject[root_key]['recurring_schedule']['amount'] = 'not an integer'
698
+ validate(schema_path, subject).must_equal false
699
+ end
700
+
701
+ it 'wont allow 0' do
702
+ subject[root_key]['recurring_schedule']['amount'] = 0
703
+ validate(schema_path, subject).must_equal false
704
+ end
705
+
706
+ it 'wont allow negaitive' do
707
+ subject[root_key]['recurring_schedule']['amount'] = -1
708
+ validate(schema_path, subject).must_equal false
709
+ end
710
+ end
711
+
712
+ describe 'interval' do
713
+ it 'must be present' do
714
+ subject[root_key]['recurring_schedule'].delete('interval')
715
+ validate(schema_path, subject).must_equal false
716
+ end
717
+
718
+ it 'must allow "weekly", "monthly", "anually"' do
719
+ ["weekly", "monthly", "anually"].each do |interval|
720
+ subject[root_key]['recurring_schedule']['interval'] = interval
721
+ validate(schema_path, subject).must_equal true
722
+ end
723
+ end
724
+
725
+ it 'wont allow other values' do
726
+ subject[root_key]['recurring_schedule']['interval'] = 'once'
727
+ validate(schema_path, subject).must_equal false
728
+
729
+ subject[root_key]['recurring_schedule']['interval'] = 1
730
+ validate(schema_path, subject).must_equal false
731
+ end
732
+ end
733
+
734
+ describe 'max_retries' do
735
+ it 'is optional' do
736
+ subject[root_key]['recurring_schedule'].delete('max_retries')
737
+ validate(schema_path, subject).must_equal true
738
+ end
739
+
740
+ it 'wont be nil' do
741
+ subject[root_key]['recurring_schedule']['max_retries'] = nil
742
+ validate(schema_path, subject).must_equal false
743
+ end
744
+
745
+ it 'must allow 0' do
746
+ subject[root_key]['recurring_schedule']['max_retries'] = 0
747
+ validate(schema_path, subject).must_equal true
748
+ end
749
+
750
+ it 'must allow 10' do
751
+ subject[root_key]['recurring_schedule']['max_retries'] = 10
752
+ validate(schema_path, subject).must_equal true
753
+ end
754
+
755
+ it 'wont allow 11' do
756
+ subject[root_key]['recurring_schedule']['max_retries'] = 11
757
+ validate(schema_path, subject).must_equal false
758
+ end
759
+
760
+ it 'must be postive' do
761
+ subject[root_key]['recurring_schedule']['max_retries'] = -1
762
+ validate(schema_path, subject).must_equal false
763
+ end
764
+ end
765
+ end
766
+
767
+ describe 'remote_ip' do
768
+ it 'presence' do
769
+ subject[root_key].delete('remote_ip')
770
+ validate(schema_path, subject).must_equal !required
771
+ end
772
+
773
+ it 'must allow 0.0.0.0' do
774
+ subject[root_key]['remote_ip'] = '0.0.0.0'
775
+ validate(schema_path, subject).must_equal true
776
+ end
777
+
778
+ it 'must allow 255.255.255.255' do
779
+ subject[root_key]['remote_ip'] = '255.255.255.255'
780
+ validate(schema_path, subject).must_equal true
781
+ end
782
+
783
+ it 'wont allow partial' do
784
+ subject[root_key]['remote_ip'] = '255.255.255'
785
+ validate(schema_path, subject).must_equal false
786
+ end
787
+
788
+ it 'wont arbitrary string' do
789
+ subject[root_key]['remote_ip'] = 'nope an ip'
790
+ validate(schema_path, subject).must_equal false
791
+ end
792
+
793
+ it 'wont integer' do
794
+ subject[root_key]['remote_ip'] = 1
795
+ validate(schema_path, subject).must_equal false
796
+ end
797
+ end
798
+
799
+ describe 'card_holder' do
800
+ it 'must be present' do
801
+ subject[root_key].delete('card_holder')
802
+ validate(schema_path, subject).must_equal false
803
+ end
804
+
805
+ it 'wont be empty' do
806
+ subject[root_key]['card_holder'] = ''
807
+ validate(schema_path, subject).must_equal false
808
+ end
809
+
810
+ it 'must allow size = 255' do
811
+ subject[root_key]['card_holder'] = 'a' * 255
812
+ validate(schema_path, subject).must_equal true
813
+ end
814
+
815
+ it 'wont allow size > 255' do
816
+ subject[root_key]['card_holder'] = 'a' * 256
817
+ validate(schema_path, subject).must_equal false
818
+ end
819
+ end
820
+
821
+ describe 'card_number' do
822
+ it 'must be present' do
823
+ subject[root_key].delete('card_number')
824
+ validate(schema_path, subject).must_equal false
825
+ end
826
+
827
+ it 'wont be empty' do
828
+ subject[root_key]['card_number'] = ''
829
+ validate(schema_path, subject).must_equal false
830
+ end
831
+
832
+ it 'must allow 13 digits' do
833
+ subject[root_key]['card_number'] = "1" * 13
834
+ validate(schema_path, subject).must_equal true
835
+ end
836
+
837
+ it 'must allow 16 digits' do
838
+ subject[root_key]['card_number'] = '1' * 16
839
+ validate(schema_path, subject).must_equal true
840
+ end
841
+
842
+ it 'wont allow 12 digits' do
843
+ subject[root_key]['card_number'] = '1' * 12
844
+ validate(schema_path, subject).must_equal false
845
+ end
846
+
847
+ it 'wont allow 17 digits' do
848
+ subject[root_key]['card_number'] = '1' * 17
849
+ validate(schema_path, subject).must_equal false
850
+ end
851
+
852
+ it 'wont arbitrary string' do
853
+ subject[root_key]['card_number'] = 'nope an ip'
854
+ validate(schema_path, subject).must_equal false
855
+ end
856
+ end
857
+
858
+ describe 'cvv' do
859
+ it 'presence' do
860
+ subject[root_key].delete('cvv')
861
+ validate(schema_path, subject).must_equal !required
862
+ end
863
+
864
+ it 'wont be empty' do
865
+ subject[root_key]['cvv'] = ''
866
+ validate(schema_path, subject).must_equal false
867
+ end
868
+
869
+ it 'must allow 3 digits' do
870
+ subject[root_key]['cvv'] = "1" * 3
871
+ validate(schema_path, subject).must_equal true
872
+ end
873
+
874
+ it 'must allow 4 digits' do
875
+ subject[root_key]['cvv'] = '1' * 4
876
+ validate(schema_path, subject).must_equal true
877
+ end
878
+
879
+ it 'wont allow 2 digits' do
880
+ subject[root_key]['cvv'] = '1' * 2
881
+ validate(schema_path, subject).must_equal false
882
+ end
883
+
884
+ it 'wont allow 5 digits' do
885
+ subject[root_key]['cvv'] = '1' * 5
886
+ validate(schema_path, subject).must_equal false
887
+ end
888
+
889
+ it 'wont arbitrary string' do
890
+ subject[root_key]['cvv'] = 'nope an ip'
891
+ validate(schema_path, subject).must_equal false
892
+ end
893
+ end
894
+
895
+ describe 'expiration_month' do
896
+ it 'must be present' do
897
+ subject[root_key].delete('expiration_month')
898
+ validate(schema_path, subject).must_equal false
899
+ end
900
+
901
+ it 'wont be empty' do
902
+ subject[root_key]['expiration_month'] = ''
903
+ validate(schema_path, subject).must_equal false
904
+ end
905
+
906
+ it 'must allow 2 digits' do
907
+ subject[root_key]['expiration_month'] = "03"
908
+ validate(schema_path, subject).must_equal true
909
+ end
910
+
911
+ it 'must allow 1 digits' do
912
+ subject[root_key]['expiration_month'] = '1'
913
+ validate(schema_path, subject).must_equal true
914
+ end
915
+
916
+ it 'wont allow 13' do
917
+ subject[root_key]['expiration_month'] = '13'
918
+ validate(schema_path, subject).must_equal false
919
+ end
920
+
921
+ it 'wont allow 20' do
922
+ subject[root_key]['expiration_month'] = '20'
923
+ validate(schema_path, subject).must_equal false
924
+ end
925
+
926
+ it 'wont arbitrary string' do
927
+ subject[root_key]['expiration_month'] = 'nope an ip'
928
+ validate(schema_path, subject).must_equal false
929
+ end
930
+ end
931
+
932
+ describe 'expiration_year' do
933
+ it 'must be present' do
934
+ subject[root_key].delete('expiration_year')
935
+ validate(schema_path, subject).must_equal false
936
+ end
937
+
938
+ it 'wont be empty' do
939
+ subject[root_key]['expiration_year'] = ''
940
+ validate(schema_path, subject).must_equal false
941
+ end
942
+
943
+ it 'must allow 4 digits' do
944
+ subject[root_key]['expiration_year'] = "2013"
945
+ validate(schema_path, subject).must_equal true
946
+ end
947
+
948
+ it 'wont allow 3 digits' do
949
+ subject[root_key]['card_number'] = '013'
950
+ validate(schema_path, subject).must_equal false
951
+ end
952
+
953
+ it 'wont allow 5' do
954
+ subject[root_key]['card_number'] = '20130'
955
+ validate(schema_path, subject).must_equal false
956
+ end
957
+
958
+ it 'wont allow < 2000' do
959
+ subject[root_key]['card_number'] = '1999'
960
+ validate(schema_path, subject).must_equal false
961
+ end
962
+
963
+ it 'wont arbitrary string' do
964
+ subject[root_key]['card_number'] = 'nope an ip'
965
+ validate(schema_path, subject).must_equal false
966
+ end
967
+ end
968
+
969
+ describe 'mpi_params' do
970
+ describe 'the object' do
971
+ it 'wont allow additionalProperties' do
972
+ subject[root_key]['mpi_params']['notInSchema'] = 1
973
+ validate(schema_path, subject).must_equal false
974
+ end
975
+ end
976
+
977
+ it 'must be present' do
978
+ subject[root_key].delete('mpi_params')
979
+ validate(schema_path, subject).must_equal false
980
+ end
981
+
982
+ describe 'cavv' do
983
+ it 'must be present' do
984
+ subject[root_key]['mpi_params'].delete('cavv')
985
+ validate(schema_path, subject).must_equal false
986
+ end
987
+
988
+ it 'wont be empty' do
989
+ subject[root_key]['mpi_params']['cavv'] = ''
990
+ validate(schema_path, subject).must_equal false
991
+ end
992
+
993
+ it 'must allow size = 255' do
994
+ subject[root_key]['mpi_params']['cavv'] = 'a' * 255
995
+ validate(schema_path, subject).must_equal true
996
+ end
997
+
998
+ it 'wont allow size > 255' do
999
+ subject[root_key]['billing_address']['cavv'] = 'a' * 256
1000
+ validate(schema_path, subject).must_equal false
1001
+ end
1002
+ end
1003
+
1004
+ describe 'eci' do
1005
+ it 'must be present' do
1006
+ subject[root_key]['mpi_params'].delete('eci')
1007
+ validate(schema_path, subject).must_equal false
1008
+ end
1009
+
1010
+ it 'wont be empty' do
1011
+ subject[root_key]['mpi_params']['eci'] = ''
1012
+ validate(schema_path, subject).must_equal false
1013
+ end
1014
+
1015
+ it 'must allow size = 255' do
1016
+ subject[root_key]['mpi_params']['eci'] = 'a' * 255
1017
+ validate(schema_path, subject).must_equal true
1018
+ end
1019
+
1020
+ it 'wont allow size > 255' do
1021
+ subject[root_key]['billing_address']['eci'] = 'a' * 256
1022
+ validate(schema_path, subject).must_equal false
1023
+ end
1024
+ end
1025
+
1026
+ describe 'xid' do
1027
+ it 'must be present' do
1028
+ subject[root_key]['mpi_params'].delete('xid')
1029
+ validate(schema_path, subject).must_equal false
1030
+ end
1031
+
1032
+ it 'wont be empty' do
1033
+ subject[root_key]['mpi_params']['xid'] = ''
1034
+ validate(schema_path, subject).must_equal false
1035
+ end
1036
+
1037
+ it 'must allow size = 255' do
1038
+ subject[root_key]['mpi_params']['xid'] = 'a' * 255
1039
+ validate(schema_path, subject).must_equal true
1040
+ end
1041
+
1042
+ it 'wont allow size > 255' do
1043
+ subject[root_key]['billing_address']['xid'] = 'a' * 256
1044
+ validate(schema_path, subject).must_equal false
1045
+ end
1046
+ end
1047
+ end
1048
+
1049
+ describe 'wire_reference_id' do
1050
+ it 'is optional' do
1051
+ subject[root_key].delete('xid')
1052
+ validate(schema_path, subject).must_equal true
1053
+ end
1054
+
1055
+ it 'wont be empty' do
1056
+ subject[root_key]['wire_reference_id'] = ''
1057
+ validate(schema_path, subject).must_equal false
1058
+ end
1059
+
1060
+ it 'must allow size = 10' do
1061
+ subject[root_key]['wire_reference_id'] = 'a' * 10
1062
+ validate(schema_path, subject).must_equal true
1063
+ end
1064
+
1065
+ it 'wont allow size > 10' do
1066
+ subject[root_key]['wire_reference_id'] = 'a' * 11
1067
+ validate(schema_path, subject).must_equal false
1068
+ end
1069
+ end
1070
+
1071
+ describe 'bank_account_holder' do
1072
+ it 'must be present' do
1073
+ subject[root_key].delete('bank_account_holder')
1074
+ validate(schema_path, subject).must_equal false
1075
+ end
1076
+
1077
+ it 'wont be empty' do
1078
+ subject[root_key]['bank_account_holder'] = ''
1079
+ validate(schema_path, subject).must_equal false
1080
+ end
1081
+
1082
+ it 'must allow size = 255' do
1083
+ subject[root_key]['bank_account_holder'] = 'a' * 255
1084
+ validate(schema_path, subject).must_equal true
1085
+ end
1086
+
1087
+ it 'wont allow size > 255' do
1088
+ subject[root_key]['bank_account_holder'] = 'a' * 256
1089
+ validate(schema_path, subject).must_equal false
1090
+ end
1091
+ end
1092
+
1093
+ describe 'bank_account_number' do
1094
+ it 'must be present' do
1095
+ subject[root_key].delete('bank_account_number')
1096
+ validate(schema_path, subject).must_equal false
1097
+ end
1098
+
1099
+ it 'wont be empty' do
1100
+ subject[root_key]['bank_account_number'] = ''
1101
+ validate(schema_path, subject).must_equal false
1102
+ end
1103
+
1104
+ it 'must allow size = 16' do
1105
+ subject[root_key]['bank_account_number'] = 'a' * 16
1106
+ validate(schema_path, subject).must_equal true
1107
+ end
1108
+
1109
+ it 'wont allow size > 16' do
1110
+ subject[root_key]['bank_account_number'] = 'a' * 17
1111
+ validate(schema_path, subject).must_equal false
1112
+ end
1113
+ end
1114
+
1115
+ describe 'bank_number' do
1116
+ it 'must be present' do
1117
+ subject[root_key].delete('bank_number')
1118
+ validate(schema_path, subject).must_equal false
1119
+ end
1120
+
1121
+ it 'wont be empty' do
1122
+ subject[root_key]['bank_number'] = ''
1123
+ validate(schema_path, subject).must_equal false
1124
+ end
1125
+
1126
+ it 'must allow size = 16' do
1127
+ subject[root_key]['bank_number'] = 'a' * 16
1128
+ validate(schema_path, subject).must_equal true
1129
+ end
1130
+
1131
+ it 'wont allow size > 16' do
1132
+ subject[root_key]['bank_number'] = 'a' * 17
1133
+ validate(schema_path, subject).must_equal false
1134
+ end
1135
+ end
1136
+
1137
+ describe 'unique_id' do
1138
+ it 'must be present' do
1139
+ subject[root_key].delete(attr_name)
1140
+ validate(schema_path, subject).must_equal false
1141
+ end
1142
+
1143
+ it 'wont be empty' do
1144
+ subject[root_key][attr_name] = ''
1145
+ validate(schema_path, subject).must_equal false
1146
+ end
1147
+
1148
+ it 'must allow 32 length hex lowercase' do
1149
+ subject[root_key][attr_name] = '71818fe4f7d74531afc9bf7db801c221'
1150
+ validate(schema_path, subject).must_equal true
1151
+ end
1152
+
1153
+
1154
+ it 'wont allow 31 length hex lowercase' do
1155
+ subject[root_key][attr_name] = '71818fe4f7d74531afc9bf7db801c22'
1156
+ validate(schema_path, subject).must_equal false
1157
+ end
1158
+
1159
+ it 'wont allow 33 length hex lowercase' do
1160
+ subject[root_key][attr_name] = '71818fe4f7d74531afc9bf7db801c2211'
1161
+ validate(schema_path, subject).must_equal false
1162
+ end
1163
+
1164
+ it 'wont allow 32 non hex lowercase' do
1165
+ subject[root_key][attr_name] = '71818ge4f7d74531afc9bf7db801c221'
1166
+ validate(schema_path, subject).must_equal false
1167
+ end
1168
+
1169
+ it 'wont allow 32 length hex uppercase' do
1170
+ subject[root_key][attr_name] = '71818FE4F7D74531AFC9BF7DB801C221'
1171
+ validate(schema_path, subject).must_equal false
1172
+ end
1173
+ end
1174
+
1175
+ describe 'v2_unique_id' do
1176
+ it 'must be present' do
1177
+ subject.delete(attr_name)
1178
+ validate(schema_path, subject).must_equal false
1179
+ end
1180
+
1181
+ it 'wont be empty' do
1182
+ subject[attr_name] = ''
1183
+ validate(schema_path, subject).must_equal false
1184
+ end
1185
+
1186
+ it 'must allow 32 length hex lowercase' do
1187
+ subject[attr_name] = '71818fe4f7d74531afc9bf7db801c221'
1188
+ validate(schema_path, subject).must_equal true
1189
+ end
1190
+
1191
+ it 'wont allow 31 length hex lowercase' do
1192
+ subject[attr_name] = '71818fe4f7d74531afc9bf7db801c22'
1193
+ validate(schema_path, subject).must_equal false
1194
+ end
1195
+
1196
+ it 'wont allow 33 length hex lowercase' do
1197
+ subject[attr_name] = '71818fe4f7d74531afc9bf7db801c2211'
1198
+ validate(schema_path, subject).must_equal false
1199
+ end
1200
+
1201
+ it 'wont allow 32 non hex lowercase' do
1202
+ subject[attr_name] = '71818ge4f7d74531afc9bf7db801c221'
1203
+ validate(schema_path, subject).must_equal false
1204
+ end
1205
+
1206
+ it 'wont allow 32 length hex uppercase' do
1207
+ subject[attr_name] = '71818FE4F7D74531AFC9BF7DB801C221'
1208
+ validate(schema_path, subject).must_equal false
1209
+ end
1210
+ end
1211
+
1212
+ describe 'date' do
1213
+ it 'presence' do
1214
+ subject.delete(attr_name)
1215
+ validate(schema_path, subject).must_equal !required
1216
+ end
1217
+
1218
+ it 'wont be empty' do
1219
+ subject[attr_name] = ''
1220
+ validate(schema_path, subject).must_equal false
1221
+ end
1222
+
1223
+ it 'wont be nil' do
1224
+ subject[attr_name] = nil
1225
+ validate(schema_path, subject).must_equal false
1226
+ end
1227
+
1228
+ it 'wont allow 2013-8-1' do
1229
+ subject[attr_name] = '2013-8-1'
1230
+ validate(schema_path, subject).must_equal false
1231
+ end
1232
+
1233
+ it 'must allow 2013-08-01' do
1234
+ subject[attr_name] = '2013-08-01'
1235
+ validate(schema_path, subject).must_equal true
1236
+ end
1237
+
1238
+ it 'wont allow other formats' do
1239
+ subject[attr_name] = "2013/12/01"
1240
+ validate(schema_path, subject).must_equal false
1241
+ end
1242
+
1243
+ it 'wont allow "may 12 2013"' do
1244
+ subject[attr_name] = 'may 12 2013'
1245
+ validate(schema_path, subject).must_equal false
1246
+ end
1247
+
1248
+ it 'wont allow impossible date' do
1249
+ subject['start_date'] = "2013-22-01"
1250
+ validate(schema_path, subject).must_equal false
1251
+
1252
+ subject['start_date'] = "2013-01-41"
1253
+ validate(schema_path, subject).must_equal false
1254
+ end
1255
+ end
1256
+
1257
+ describe 'expiring_notification_time' do
1258
+ it 'presence' do
1259
+ subject.delete(attr_name)
1260
+ validate(schema_path, subject).must_equal !required
1261
+ end
1262
+
1263
+ it 'wont be empty' do
1264
+ subject[attr_name] = ''
1265
+ validate(schema_path, subject).must_equal false
1266
+ end
1267
+
1268
+ it 'wont be nil' do
1269
+ subject[attr_name] = nil
1270
+ validate(schema_path, subject).must_equal false
1271
+ end
1272
+
1273
+ it 'wont allow 0' do
1274
+ subject[attr_name] = 0
1275
+ validate(schema_path, subject).must_equal false
1276
+ end
1277
+
1278
+ it 'must allow 1' do
1279
+ subject[attr_name] = 1
1280
+ validate(schema_path, subject).must_equal true
1281
+ end
1282
+
1283
+ it 'must allow 100' do
1284
+ subject[attr_name] = 100
1285
+ validate(schema_path, subject).must_equal true
1286
+ end
1287
+
1288
+ it 'wont allow 101' do
1289
+ subject[attr_name] = 101
1290
+ validate(schema_path, subject).must_equal false
1291
+ end
1292
+
1293
+ it 'must be postive' do
1294
+ subject[attr_name] = -1
1295
+ validate(schema_path, subject).must_equal false
1296
+ end
1297
+ end
1298
+
1299
+ describe 'active' do
1300
+ it 'presence' do
1301
+ subject.delete(attr_name)
1302
+ validate(schema_path, subject).must_equal !required
1303
+ end
1304
+
1305
+ it 'wont be empty' do
1306
+ subject[attr_name] = ''
1307
+ validate(schema_path, subject).must_equal false
1308
+ end
1309
+
1310
+ it 'wont be nil' do
1311
+ subject[attr_name] = nil
1312
+ validate(schema_path, subject).must_equal false
1313
+ end
1314
+
1315
+ it 'must allow 0' do
1316
+ subject[attr_name] = 0
1317
+ validate(schema_path, subject).must_equal true
1318
+ end
1319
+
1320
+ it 'must allow 1' do
1321
+ subject[attr_name] = 1
1322
+ validate(schema_path, subject).must_equal true
1323
+ end
1324
+
1325
+ it 'must allow true' do
1326
+ subject[attr_name] = true
1327
+ validate(schema_path, subject).must_equal true
1328
+ end
1329
+
1330
+ it 'must allow false' do
1331
+ subject[attr_name] = false
1332
+ validate(schema_path, subject).must_equal true
1333
+ end
1334
+ end
1335
+
1336
+ describe 'boolean' do
1337
+ it 'presence' do
1338
+ subject.delete(attr_name)
1339
+ validate(schema_path, subject).must_equal !required
1340
+ end
1341
+
1342
+ it 'wont be empty' do
1343
+ subject[attr_name] = ''
1344
+ validate(schema_path, subject).must_equal false
1345
+ end
1346
+
1347
+ it 'wont be nil' do
1348
+ subject[attr_name] = nil
1349
+ validate(schema_path, subject).must_equal false
1350
+ end
1351
+
1352
+ it 'must allow 0' do
1353
+ subject[attr_name] = 0
1354
+ validate(schema_path, subject).must_equal true
1355
+ end
1356
+
1357
+ it 'must allow 1' do
1358
+ subject[attr_name] = 1
1359
+ validate(schema_path, subject).must_equal true
1360
+ end
1361
+
1362
+ it 'must allow true' do
1363
+ subject[attr_name] = true
1364
+ validate(schema_path, subject).must_equal true
1365
+ end
1366
+
1367
+ it 'must allow false' do
1368
+ subject[attr_name] = false
1369
+ validate(schema_path, subject).must_equal true
1370
+ end
1371
+
1372
+ it 'wont allow "true"' do
1373
+ subject[attr_name] = "true"
1374
+ validate(schema_path, subject).must_equal false
1375
+ end
1376
+ end
1377
+
1378
+ describe 'recurring_interval' do
1379
+ # code dublication with 'recurring_schedule.interval' because v1 and v2 mix
1380
+ it 'presence' do
1381
+ subject.delete(attr_name)
1382
+ validate(schema_path, subject).must_equal !required
1383
+ end
1384
+
1385
+ it 'must allow "weekly", "monthly", "anually"' do
1386
+ ["weekly", "monthly", "anually"].each do |interval|
1387
+ subject[attr_name] = interval
1388
+ validate(schema_path, subject).must_equal true
1389
+ end
1390
+ end
1391
+
1392
+ it 'wont allow other values' do
1393
+ subject[attr_name] = 'once'
1394
+ validate(schema_path, subject).must_equal false
1395
+
1396
+ subject[attr_name] = 1
1397
+ validate(schema_path, subject).must_equal false
1398
+ end
1399
+ end
1400
+
1401
+ describe 'page' do
1402
+ it 'presence' do
1403
+ subject.delete(attr_name)
1404
+ validate(schema_path, subject).must_equal !required
1405
+ end
1406
+
1407
+ it 'wont allow -1' do
1408
+ subject[attr_name] = -1
1409
+ validate(schema_path, subject).must_equal false
1410
+ end
1411
+
1412
+ it 'wont allow 0' do
1413
+ subject[attr_name] = 0
1414
+ validate(schema_path, subject).must_equal false
1415
+ end
1416
+
1417
+ it 'must allow 1' do
1418
+ subject[attr_name] = 1
1419
+ validate(schema_path, subject).must_equal true
1420
+ end
1421
+
1422
+ it 'must allow 100000' do
1423
+ subject[attr_name] = 100000
1424
+ validate(schema_path, subject).must_equal true
1425
+ end
1426
+
1427
+ it 'wont allow 100001' do
1428
+ subject[attr_name] = 100001
1429
+ validate(schema_path, subject).must_equal false
1430
+ end
1431
+
1432
+ it 'wont allow "1"' do
1433
+ subject[attr_name] = "1"
1434
+ validate(schema_path, subject).must_equal false
1435
+ end
1436
+
1437
+ it 'wont allow ""' do
1438
+ subject[attr_name] = ""
1439
+ validate(schema_path, subject).must_equal false
1440
+ end
1441
+
1442
+ it 'wont allow "foo"' do
1443
+ subject[attr_name] = "foo"
1444
+ validate(schema_path, subject).must_equal false
1445
+ end
1446
+ end
1447
+
1448
+ describe 'per_page' do
1449
+ it 'presence' do
1450
+ subject.delete(attr_name)
1451
+ validate(schema_path, subject).must_equal !required
1452
+ end
1453
+
1454
+ it 'wont allow -1' do
1455
+ subject[attr_name] = -1
1456
+ validate(schema_path, subject).must_equal false
1457
+ end
1458
+
1459
+ it 'wont allow 0' do
1460
+ subject[attr_name] = 0
1461
+ validate(schema_path, subject).must_equal false
1462
+ end
1463
+
1464
+ it 'must allow 1' do
1465
+ subject[attr_name] = 1
1466
+ validate(schema_path, subject).must_equal true
1467
+ end
1468
+
1469
+ it 'must allow 1000' do
1470
+ subject[attr_name] = 1000
1471
+ validate(schema_path, subject).must_equal true
1472
+ end
1473
+
1474
+ it 'wont allow 1001' do
1475
+ subject[attr_name] = 1001
1476
+ validate(schema_path, subject).must_equal false
1477
+ end
1478
+
1479
+ it 'wont allow "1"' do
1480
+ subject[attr_name] = "1"
1481
+ validate(schema_path, subject).must_equal false
1482
+ end
1483
+
1484
+ it 'wont allow ""' do
1485
+ subject[attr_name] = ""
1486
+ validate(schema_path, subject).must_equal false
1487
+ end
1488
+
1489
+ it 'wont allow "foo"' do
1490
+ subject[attr_name] = "foo"
1491
+ validate(schema_path, subject).must_equal false
1492
+ end
1493
+ end
1494
+ end