1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-29 18:52:22 +01:00

installs vcr and adds an integration test for reservation

This commit is contained in:
Nicolas Florentin 2016-04-06 15:15:09 +02:00
parent b6dcacaa8a
commit 83d8bdf9b0
6 changed files with 735 additions and 2 deletions

View File

@ -58,6 +58,8 @@ group :test do
gem 'faker'
gem 'test_after_commit'
gem 'minitest-reporters'
gem 'webmock'
gem 'vcr'
end
group :production do

View File

@ -107,6 +107,8 @@ GEM
sass-rails (<= 5.0.1)
sprockets (< 2.13)
connection_pool (2.2.0)
crack (0.4.3)
safe_yaml (~> 1.0.0)
database_cleaner (1.4.1)
debug_inspector (0.0.2)
descendants_tracker (0.0.4)
@ -161,6 +163,7 @@ GEM
activerecord (>= 4.0.0)
globalid (0.3.6)
activesupport (>= 4.1.0)
hashdiff (0.3.0)
hashie (3.4.2)
highline (1.7.1)
hike (1.2.3)
@ -313,6 +316,7 @@ GEM
tzinfo
rvm-capistrano (1.5.6)
capistrano (~> 2.15.4)
safe_yaml (1.0.4)
sass (3.4.13)
sass-rails (5.0.1)
railties (>= 4.0.0, < 5.0)
@ -395,6 +399,7 @@ GEM
kgio (~> 2.6)
rack
raindrops (~> 0.7)
vcr (3.0.1)
virtus (1.0.5)
axiom-types (~> 0.1)
coercible (~> 1.0)
@ -407,6 +412,10 @@ GEM
binding_of_caller (>= 0.7.2)
railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0)
webmock (1.24.2)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff
PLATFORMS
ruby
@ -475,7 +484,9 @@ DEPENDENCIES
twitter-text
uglifier (>= 1.3.0)
unicorn
vcr
web-console (~> 2.0)
webmock
BUNDLED WITH
1.11.2

View File

@ -0,0 +1,11 @@
# class Reservations::CreateAsAdminTest < ActionDispatch::IntegrationTest
# setup do
# admin = User.with_role(:admin).first
# login_as(admin, scope: :user)
# end
#
# test "admin reserves a machine for a user" do
# availability = Availability.find(5)
#
# end
# end

View File

@ -0,0 +1,60 @@
module Reservations
class CreateTest < ActionDispatch::IntegrationTest
setup do
@user = User.with_role(:member).first
login_as(@user, scope: :user)
end
test "user without plan reserves a machine with success" do
machine = Machine.find(6)
availability = machine.availabilities.first
reservations_count = Reservation.count
invoice_items_count = InvoiceItem.count
VCR.use_cassette("reservations_create_without_plan_success") do
token = Stripe::Token.create(
:card => {
:number => "4242424242424242",
:exp_month => 4,
:exp_year => 1.year.from_now.year,
:cvc => "314"
},
)
post reservations_path, { reservation: {
user_id: @user.id,
reservable_id: machine.id,
reservable_type: machine.class.name,
card_token: token.id,
slots_attributes: [
{ start_at: availability.start_at.to_s(:iso8601),
end_at: (availability.start_at + 1.hour).to_s(:iso8601),
availability_id: availability.id
}
]
}}.to_json, { 'Accept' => Mime::JSON, 'Content-Type' => Mime::JSON.to_s }
end
# general assertions
assert_equal 201, response.status
assert_equal reservations_count + 1, Reservation.count
assert_equal invoice_items_count + 1, InvoiceItem.count
# reservation assertions
reservation = Reservation.last
assert reservation.invoice
assert_equal 1, reservation.invoice.invoice_items.count
# invoice_items
invoice_item = InvoiceItem.last
assert invoice_item.stp_invoice_item_id
assert_equal invoice_item.amount, machine.prices.find_by(group_id: @user.group_id).amount
p json_response(response.body)
end
end
end

View File

@ -1,13 +1,20 @@
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'vcr'
require 'sidekiq/testing'
Sidekiq::Testing.fake!
require 'minitest/reporters'
VCR.configure do |config|
config.cassette_library_dir = "test/vcr_cassettes"
config.hook_into :webmock
end
Sidekiq::Testing.inline!
Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new({ color: true })]
class ActiveSupport::TestCase
# Add more helper methods to be used by all tests here...

View File

@ -0,0 +1,642 @@
---
http_interactions:
- request:
method: post
uri: https://api.stripe.com/v1/tokens
body:
encoding: UTF-8
string: card[number]=4242424242424242&card[exp_month]=4&card[exp_year]=2017&card[cvc]=314
headers:
Accept:
- "*/*; q=0.5, application/xml"
Accept-Encoding:
- gzip, deflate
User-Agent:
- Stripe/v1 RubyBindings/1.30.2
Authorization:
- Bearer sk_test_mGokO9TGtrVxMOyK4yZiktBE
Content-Type:
- application/x-www-form-urlencoded
X-Stripe-Client-User-Agent:
- '{"bindings_version":"1.30.2","lang":"ruby","lang_version":"2.3.0 p0 (2015-12-25)","platform":"x86_64-darwin14","engine":"ruby","publisher":"stripe","uname":"Darwin
MBP-sleede-Nicolas.local 14.5.0 Darwin Kernel Version 14.5.0: Wed Jul 29 02:26:53
PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64","hostname":"MBP-sleede-Nicolas.local"}'
Content-Length:
- '81'
response:
status:
code: 200
message: OK
headers:
Server:
- nginx
Date:
- Wed, 06 Apr 2016 09:46:39 GMT
Content-Type:
- application/json
Content-Length:
- '778'
Connection:
- keep-alive
Access-Control-Allow-Credentials:
- 'true'
Access-Control-Allow-Methods:
- GET, POST, HEAD, OPTIONS, DELETE
Access-Control-Allow-Origin:
- "*"
Access-Control-Max-Age:
- '300'
Cache-Control:
- no-cache, no-store
Request-Id:
- req_8DeYuCEulJlrPp
Stripe-Version:
- '2015-10-16'
Strict-Transport-Security:
- max-age=31556926; includeSubDomains
body:
encoding: UTF-8
string: |
{
"id": "tok_17xDFD2sOmf47Nz9JD1vbrAJ",
"object": "token",
"card": {
"id": "card_17xDFD2sOmf47Nz9LbJShTlw",
"object": "card",
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": null,
"address_zip_check": null,
"brand": "Visa",
"country": "US",
"cvc_check": "unchecked",
"dynamic_last4": null,
"exp_month": 4,
"exp_year": 2017,
"fingerprint": "o52jybR7bnmNn6AT",
"funding": "credit",
"last4": "4242",
"metadata": {},
"name": null,
"tokenization_method": null
},
"client_ip": "86.76.5.109",
"created": 1459935999,
"livemode": false,
"type": "card",
"used": false
}
http_version:
recorded_at: Wed, 06 Apr 2016 09:46:39 GMT
- request:
method: post
uri: https://api.stripe.com/v1/invoiceitems
body:
encoding: UTF-8
string: customer=cus_8CzAgnSeFbDuG2&amount=3200&currency=eur&description=FORM1%2B+imprimante+3D+lundi+11+avril+2016+14h00+-+15%3A00
headers:
Accept:
- "*/*; q=0.5, application/xml"
Accept-Encoding:
- gzip, deflate
User-Agent:
- Stripe/v1 RubyBindings/1.30.2
Authorization:
- Bearer sk_test_mGokO9TGtrVxMOyK4yZiktBE
Content-Type:
- application/x-www-form-urlencoded
X-Stripe-Client-User-Agent:
- '{"bindings_version":"1.30.2","lang":"ruby","lang_version":"2.3.0 p0 (2015-12-25)","platform":"x86_64-darwin14","engine":"ruby","publisher":"stripe","uname":"Darwin
MBP-sleede-Nicolas.local 14.5.0 Darwin Kernel Version 14.5.0: Wed Jul 29 02:26:53
PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64","hostname":"MBP-sleede-Nicolas.local"}'
Content-Length:
- '123'
response:
status:
code: 200
message: OK
headers:
Server:
- nginx
Date:
- Wed, 06 Apr 2016 09:46:41 GMT
Content-Type:
- application/json
Content-Length:
- '471'
Connection:
- keep-alive
Access-Control-Allow-Credentials:
- 'true'
Access-Control-Allow-Methods:
- GET, POST, HEAD, OPTIONS, DELETE
Access-Control-Allow-Origin:
- "*"
Access-Control-Max-Age:
- '300'
Cache-Control:
- no-cache, no-store
Request-Id:
- req_8DeYBFB42AoW5m
Stripe-Version:
- '2015-10-16'
Strict-Transport-Security:
- max-age=31556926; includeSubDomains
body:
encoding: UTF-8
string: |
{
"id": "ii_17xDFF2sOmf47Nz90VoIJ17e",
"object": "invoiceitem",
"amount": 3200,
"currency": "eur",
"customer": "cus_8CzAgnSeFbDuG2",
"date": 1459936001,
"description": "FORM1+ imprimante 3D lundi 11 avril 2016 14h00 - 15:00",
"discountable": true,
"invoice": null,
"livemode": false,
"metadata": {},
"period": {
"start": 1459936001,
"end": 1459936001
},
"plan": null,
"proration": false,
"quantity": null,
"subscription": null
}
http_version:
recorded_at: Wed, 06 Apr 2016 09:46:41 GMT
- request:
method: get
uri: https://api.stripe.com/v1/customers/cus_8CzAgnSeFbDuG2
body:
encoding: US-ASCII
string: ''
headers:
Accept:
- "*/*; q=0.5, application/xml"
Accept-Encoding:
- gzip, deflate
User-Agent:
- Stripe/v1 RubyBindings/1.30.2
Authorization:
- Bearer sk_test_mGokO9TGtrVxMOyK4yZiktBE
Content-Type:
- application/x-www-form-urlencoded
X-Stripe-Client-User-Agent:
- '{"bindings_version":"1.30.2","lang":"ruby","lang_version":"2.3.0 p0 (2015-12-25)","platform":"x86_64-darwin14","engine":"ruby","publisher":"stripe","uname":"Darwin
MBP-sleede-Nicolas.local 14.5.0 Darwin Kernel Version 14.5.0: Wed Jul 29 02:26:53
PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64","hostname":"MBP-sleede-Nicolas.local"}'
response:
status:
code: 200
message: OK
headers:
Server:
- nginx
Date:
- Wed, 06 Apr 2016 09:46:42 GMT
Content-Type:
- application/json
Content-Length:
- '649'
Connection:
- keep-alive
Access-Control-Allow-Credentials:
- 'true'
Access-Control-Allow-Methods:
- GET, POST, HEAD, OPTIONS, DELETE
Access-Control-Allow-Origin:
- "*"
Access-Control-Max-Age:
- '300'
Cache-Control:
- no-cache, no-store
Request-Id:
- req_8DeYGJn0xDlBIk
Stripe-Version:
- '2015-10-16'
Strict-Transport-Security:
- max-age=31556926; includeSubDomains
body:
encoding: UTF-8
string: |
{
"id": "cus_8CzAgnSeFbDuG2",
"object": "customer",
"account_balance": 0,
"created": 1459782030,
"currency": "eur",
"default_source": null,
"delinquent": false,
"description": "Jean Dupont",
"discount": null,
"email": "jean.dupont@gmail.com",
"livemode": false,
"metadata": {},
"shipping": null,
"sources": {
"object": "list",
"data": [],
"has_more": false,
"total_count": 0,
"url": "/v1/customers/cus_8CzAgnSeFbDuG2/sources"
},
"subscriptions": {
"object": "list",
"data": [],
"has_more": false,
"total_count": 0,
"url": "/v1/customers/cus_8CzAgnSeFbDuG2/subscriptions"
}
}
http_version:
recorded_at: Wed, 06 Apr 2016 09:46:42 GMT
- request:
method: post
uri: https://api.stripe.com/v1/customers/cus_8CzAgnSeFbDuG2/sources
body:
encoding: UTF-8
string: card=tok_17xDFD2sOmf47Nz9JD1vbrAJ
headers:
Accept:
- "*/*; q=0.5, application/xml"
Accept-Encoding:
- gzip, deflate
User-Agent:
- Stripe/v1 RubyBindings/1.30.2
Authorization:
- Bearer sk_test_mGokO9TGtrVxMOyK4yZiktBE
Content-Type:
- application/x-www-form-urlencoded
X-Stripe-Client-User-Agent:
- '{"bindings_version":"1.30.2","lang":"ruby","lang_version":"2.3.0 p0 (2015-12-25)","platform":"x86_64-darwin14","engine":"ruby","publisher":"stripe","uname":"Darwin
MBP-sleede-Nicolas.local 14.5.0 Darwin Kernel Version 14.5.0: Wed Jul 29 02:26:53
PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64","hostname":"MBP-sleede-Nicolas.local"}'
Content-Length:
- '33'
response:
status:
code: 200
message: OK
headers:
Server:
- nginx
Date:
- Wed, 06 Apr 2016 09:46:42 GMT
Content-Type:
- application/json
Content-Length:
- '577'
Connection:
- keep-alive
Access-Control-Allow-Credentials:
- 'true'
Access-Control-Allow-Methods:
- GET, POST, HEAD, OPTIONS, DELETE
Access-Control-Allow-Origin:
- "*"
Access-Control-Max-Age:
- '300'
Cache-Control:
- no-cache, no-store
Request-Id:
- req_8DeYMzh7lG57bt
Stripe-Version:
- '2015-10-16'
Strict-Transport-Security:
- max-age=31556926; includeSubDomains
body:
encoding: UTF-8
string: |
{
"id": "card_17xDFD2sOmf47Nz9LbJShTlw",
"object": "card",
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": null,
"address_zip_check": null,
"brand": "Visa",
"country": "US",
"customer": "cus_8CzAgnSeFbDuG2",
"cvc_check": "pass",
"dynamic_last4": null,
"exp_month": 4,
"exp_year": 2017,
"fingerprint": "o52jybR7bnmNn6AT",
"funding": "credit",
"last4": "4242",
"metadata": {},
"name": null,
"tokenization_method": null
}
http_version:
recorded_at: Wed, 06 Apr 2016 09:46:42 GMT
- request:
method: post
uri: https://api.stripe.com/v1/invoices
body:
encoding: UTF-8
string: customer=cus_8CzAgnSeFbDuG2
headers:
Accept:
- "*/*; q=0.5, application/xml"
Accept-Encoding:
- gzip, deflate
User-Agent:
- Stripe/v1 RubyBindings/1.30.2
Authorization:
- Bearer sk_test_mGokO9TGtrVxMOyK4yZiktBE
Content-Type:
- application/x-www-form-urlencoded
X-Stripe-Client-User-Agent:
- '{"bindings_version":"1.30.2","lang":"ruby","lang_version":"2.3.0 p0 (2015-12-25)","platform":"x86_64-darwin14","engine":"ruby","publisher":"stripe","uname":"Darwin
MBP-sleede-Nicolas.local 14.5.0 Darwin Kernel Version 14.5.0: Wed Jul 29 02:26:53
PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64","hostname":"MBP-sleede-Nicolas.local"}'
Content-Length:
- '27'
response:
status:
code: 200
message: OK
headers:
Server:
- nginx
Date:
- Wed, 06 Apr 2016 09:46:43 GMT
Content-Type:
- application/json
Content-Length:
- '1428'
Connection:
- keep-alive
Access-Control-Allow-Credentials:
- 'true'
Access-Control-Allow-Methods:
- GET, POST, HEAD, OPTIONS, DELETE
Access-Control-Allow-Origin:
- "*"
Access-Control-Max-Age:
- '300'
Cache-Control:
- no-cache, no-store
Request-Id:
- req_8DeYs6PUiVx1DN
Stripe-Version:
- '2015-10-16'
Strict-Transport-Security:
- max-age=31556926; includeSubDomains
body:
encoding: UTF-8
string: |
{
"id": "in_17xDFH2sOmf47Nz9DpUY5b3U",
"object": "invoice",
"amount_due": 3200,
"application_fee": null,
"attempt_count": 0,
"attempted": false,
"charge": null,
"closed": false,
"currency": "eur",
"customer": "cus_8CzAgnSeFbDuG2",
"date": 1459936003,
"description": null,
"discount": null,
"ending_balance": null,
"forgiven": false,
"lines": {
"object": "list",
"data": [
{
"id": "ii_17xDFF2sOmf47Nz90VoIJ17e",
"object": "line_item",
"amount": 3200,
"currency": "eur",
"description": "FORM1+ imprimante 3D lundi 11 avril 2016 14h00 - 15:00",
"discountable": true,
"livemode": false,
"metadata": {},
"period": {
"start": 1459936001,
"end": 1459936001
},
"plan": null,
"proration": false,
"quantity": null,
"subscription": null,
"type": "invoiceitem"
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/invoices/in_17xDFH2sOmf47Nz9DpUY5b3U/lines"
},
"livemode": false,
"metadata": {},
"next_payment_attempt": 1459939603,
"paid": false,
"period_end": 1459936003,
"period_start": 1459936003,
"receipt_number": null,
"starting_balance": 0,
"statement_descriptor": null,
"subscription": null,
"subtotal": 3200,
"tax": null,
"tax_percent": null,
"total": 3200,
"webhooks_delivered_at": null
}
http_version:
recorded_at: Wed, 06 Apr 2016 09:46:43 GMT
- request:
method: post
uri: https://api.stripe.com/v1/invoices/in_17xDFH2sOmf47Nz9DpUY5b3U/pay
body:
encoding: ASCII-8BIT
string: ''
headers:
Accept:
- "*/*; q=0.5, application/xml"
Accept-Encoding:
- gzip, deflate
User-Agent:
- Stripe/v1 RubyBindings/1.30.2
Authorization:
- Bearer sk_test_mGokO9TGtrVxMOyK4yZiktBE
Content-Type:
- application/x-www-form-urlencoded
X-Stripe-Client-User-Agent:
- '{"bindings_version":"1.30.2","lang":"ruby","lang_version":"2.3.0 p0 (2015-12-25)","platform":"x86_64-darwin14","engine":"ruby","publisher":"stripe","uname":"Darwin
MBP-sleede-Nicolas.local 14.5.0 Darwin Kernel Version 14.5.0: Wed Jul 29 02:26:53
PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64","hostname":"MBP-sleede-Nicolas.local"}'
Content-Length:
- '0'
response:
status:
code: 200
message: OK
headers:
Server:
- nginx
Date:
- Wed, 06 Apr 2016 09:46:44 GMT
Content-Type:
- application/json
Content-Length:
- '1447'
Connection:
- keep-alive
Access-Control-Allow-Credentials:
- 'true'
Access-Control-Allow-Methods:
- GET, POST, HEAD, OPTIONS, DELETE
Access-Control-Allow-Origin:
- "*"
Access-Control-Max-Age:
- '300'
Cache-Control:
- no-cache, no-store
Request-Id:
- req_8DeYRzymQv71IY
Stripe-Version:
- '2015-10-16'
Strict-Transport-Security:
- max-age=31556926; includeSubDomains
body:
encoding: UTF-8
string: |
{
"id": "in_17xDFH2sOmf47Nz9DpUY5b3U",
"object": "invoice",
"amount_due": 3200,
"application_fee": null,
"attempt_count": 1,
"attempted": true,
"charge": "ch_17xDFI2sOmf47Nz9KHMAQUmF",
"closed": true,
"currency": "eur",
"customer": "cus_8CzAgnSeFbDuG2",
"date": 1459936003,
"description": null,
"discount": null,
"ending_balance": 0,
"forgiven": false,
"lines": {
"object": "list",
"data": [
{
"id": "ii_17xDFF2sOmf47Nz90VoIJ17e",
"object": "line_item",
"amount": 3200,
"currency": "eur",
"description": "FORM1+ imprimante 3D lundi 11 avril 2016 14h00 - 15:00",
"discountable": true,
"livemode": false,
"metadata": {},
"period": {
"start": 1459936001,
"end": 1459936001
},
"plan": null,
"proration": false,
"quantity": null,
"subscription": null,
"type": "invoiceitem"
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/invoices/in_17xDFH2sOmf47Nz9DpUY5b3U/lines"
},
"livemode": false,
"metadata": {},
"next_payment_attempt": null,
"paid": true,
"period_end": 1459936003,
"period_start": 1459936003,
"receipt_number": null,
"starting_balance": 0,
"statement_descriptor": null,
"subscription": null,
"subtotal": 3200,
"tax": null,
"tax_percent": null,
"total": 3200,
"webhooks_delivered_at": 1459936003
}
http_version:
recorded_at: Wed, 06 Apr 2016 09:46:44 GMT
- request:
method: delete
uri: https://api.stripe.com/v1/customers/cus_8CzAgnSeFbDuG2/sources/card_17xDFD2sOmf47Nz9LbJShTlw
body:
encoding: US-ASCII
string: ''
headers:
Accept:
- "*/*; q=0.5, application/xml"
Accept-Encoding:
- gzip, deflate
User-Agent:
- Stripe/v1 RubyBindings/1.30.2
Authorization:
- Bearer sk_test_mGokO9TGtrVxMOy
Content-Type:
- application/x-www-form-urlencoded
X-Stripe-Client-User-Agent:
- '{"bindings_version":"1.30.2","lang":"ruby","lang_version":"2.3.0 p0 (2015-12-25)","platform":"x86_64-darwin14","engine":"ruby","publisher":"stripe","uname":"Darwin
MBP-sleede-Nicolas.local 14.5.0 Darwin Kernel Version 14.5.0: Wed Jul 29 02:26:53
PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64","hostname":"MBP-sleede-Nicolas.local"}'
response:
status:
code: 200
message: OK
headers:
Server:
- nginx
Date:
- Wed, 06 Apr 2016 09:46:45 GMT
Content-Type:
- application/json
Content-Length:
- '63'
Connection:
- keep-alive
Access-Control-Allow-Credentials:
- 'true'
Access-Control-Allow-Methods:
- GET, POST, HEAD, OPTIONS, DELETE
Access-Control-Allow-Origin:
- "*"
Access-Control-Max-Age:
- '300'
Cache-Control:
- no-cache, no-store
Request-Id:
- req_8DeYSokbVz2FOu
Stripe-Version:
- '2015-10-16'
Strict-Transport-Security:
- max-age=31556926; includeSubDomains
body:
encoding: UTF-8
string: |
{
"deleted": true,
"id": "card_17xDFD2sOmf47Nz9LbJShTlw"
}
http_version:
recorded_at: Wed, 06 Apr 2016 09:46:45 GMT
recorded_with: VCR 3.0.1