factory for stripe responses

This commit is contained in:
Rimian Perkins 2019-08-27 16:06:37 +10:00
parent 1315d240e6
commit c8bcc1eb28
4 changed files with 63 additions and 51 deletions

View File

@ -39,7 +39,6 @@ Accept donations from visitors to your [Discourse](https://www.discourse.org/) f
## TODO
* Handle custom fields
* Acceptance test in RSpec not qunit.
## Tested Credit Card Numbers

View File

@ -35,56 +35,7 @@ module DiscourseDonations
it 'responds ok for anonymous users' do
controller.expects(:current_user).at_least(1).returns(user)
customer = {
"id": "cus_FhHJDzf0OxYtb8",
"object": "customer",
"account_balance": 0,
"address": "null",
"balance": 0,
"created": 1566866533,
"currency": "usd",
"default_source": "null",
"delinquent": false,
"description": "null",
"discount": "null",
"email": "null",
"invoice_prefix": "0BBF354",
"invoice_settings": {
"custom_fields": "null",
"default_payment_method": "null",
"footer": "null"
},
"livemode": false,
"metadata": {},
"name": "null",
"phone": "null",
"preferred_locales": [],
"shipping": "null",
"sources": {
"object": "list",
"data": [],
"has_more": false,
"total_count": 0,
"url": "/v1/customers/cus_FhHJDzf0OxYtb8/sources"
},
"subscriptions": {
"object": "list",
"data": [],
"has_more": false,
"total_count": 0,
"url": "/v1/customers/cus_FhHJDzf0OxYtb8/subscriptions"
},
"tax_exempt": "none",
"tax_ids": {
"object": "list",
"data": [],
"has_more": false,
"total_count": 0,
"url": "/v1/customers/cus_FhHJDzf0OxYtb8/tax_ids"
},
"tax_info": "null",
"tax_info_verification": "null"
}
customer = Fabricate(:customer)
stub_request(:get, /v1\/customers/).to_return(status: 200, body: customer.to_json)

View File

@ -0,0 +1,60 @@
class Customer
attr_accessor :to_json
end
Fabricator(:customer) do
response = {
"id": "cus_FhHJDzf0OxYtb8",
"object": "customer",
"account_balance": 0,
"address": "null",
"balance": 0,
"created": 1566866533,
"currency": "usd",
"default_source": "null",
"delinquent": false,
"description": "null",
"discount": "null",
"email": "null",
"invoice_prefix": "0BBF354",
"invoice_settings": {
"custom_fields": "null",
"default_payment_method": "null",
"footer": "null"
},
"livemode": false,
"metadata": {},
"name": "null",
"phone": "null",
"preferred_locales": [],
"shipping": "null",
"sources": {
"object": "list",
"data": [],
"has_more": false,
"total_count": 0,
"url": "/v1/customers/cus_FhHJDzf0OxYtb8/sources"
},
"subscriptions": {
"object": "list",
"data": [],
"has_more": false,
"total_count": 0,
"url": "/v1/customers/cus_FhHJDzf0OxYtb8/subscriptions"
},
"tax_exempt": "none",
"tax_ids": {
"object": "list",
"data": [],
"has_more": false,
"total_count": 0,
"url": "/v1/customers/cus_FhHJDzf0OxYtb8/tax_ids"
},
"tax_info": "null",
"tax_info_verification": "null"
}.to_json
to_json response
end

2
spec/plugin_helper.rb Normal file
View File

@ -0,0 +1,2 @@
require_relative './fabricators/customer_fabricator.rb'