mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-10-04 00:00:47 -04:00
* Bump Rubocop to 0.57.2 * Style/StderrPuts: Use warn instead of .puts * Style/ExpandPathArguments: Use expand_path('../test_helper', __dir__) instead of expand_path('../../test_helper', __FILE__) * Style/Encoding: Unnecessary utf-8 encoding comment * Style/StringLiterals: Prefer double-quoted strings * Style/AccessModifierDeclarations * Style/FormatStringToken: Prefer annotated tokens * Naming/UncommunicativeMethodParamName * Metrics/LineLength: set maximum line length to 100 characters * Style/IfUnlessModifier: Favor modifier if usage when having a single-line body * Style/ClassVars * Metrics/LineLength: set maximum line length to 80 characters (default) * Style/AccessModifierDeclarations: EnforcedStyle: inline
80 lines
2.6 KiB
Ruby
80 lines
2.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require ::File.expand_path("../test_helper", __dir__)
|
|
|
|
module Stripe
|
|
# This is a strict copy of `FileTest`, except that it uses
|
|
# `Stripe::FileUpload` instead of `Stripe::File`.
|
|
class FileUploadTest < Test::Unit::TestCase
|
|
should "be listable" do
|
|
files = Stripe::FileUpload.list
|
|
assert_requested :get, "#{Stripe.api_base}/v1/files"
|
|
assert files.data.is_a?(Array)
|
|
assert files.data[0].is_a?(Stripe::FileUpload)
|
|
end
|
|
|
|
should "be retrievable" do
|
|
file = Stripe::FileUpload.retrieve("file_123")
|
|
assert_requested :get, "#{Stripe.api_base}/v1/files/file_123"
|
|
assert file.is_a?(Stripe::FileUpload)
|
|
end
|
|
|
|
context ".create" do
|
|
setup do
|
|
# We don't point to the same host for the API and uploads in
|
|
# production, but `stripe-mock` supports both APIs.
|
|
Stripe.uploads_base = Stripe.api_base
|
|
|
|
# Set `api_base` to `nil` to ensure that these requests are _not_ sent
|
|
# to the default API hostname. `api_base` is reset when each test
|
|
# starts so this won't affect the global state.
|
|
Stripe.api_base = nil
|
|
end
|
|
|
|
should "be creatable with a File" do
|
|
file = Stripe::FileUpload.create(
|
|
purpose: "dispute_evidence",
|
|
file: ::File.new(__FILE__),
|
|
file_link_data: { create: true }
|
|
)
|
|
assert_requested :post, "#{Stripe.uploads_base}/v1/files"
|
|
assert file.is_a?(Stripe::FileUpload)
|
|
end
|
|
|
|
should "be creatable with a Tempfile" do
|
|
tempfile = Tempfile.new("foo")
|
|
tempfile.write("Hello world")
|
|
tempfile.rewind
|
|
|
|
file = Stripe::FileUpload.create(
|
|
purpose: "dispute_evidence",
|
|
file: tempfile,
|
|
file_link_data: { create: true }
|
|
)
|
|
assert_requested :post, "#{Stripe.uploads_base}/v1/files"
|
|
assert file.is_a?(Stripe::FileUpload)
|
|
end
|
|
|
|
should "be creatable with Faraday::UploadIO" do
|
|
file = Stripe::FileUpload.create(
|
|
purpose: "dispute_evidence",
|
|
file: Faraday::UploadIO.new(::File.new(__FILE__), nil),
|
|
file_link_data: { create: true }
|
|
)
|
|
assert_requested :post, "#{Stripe.uploads_base}/v1/files"
|
|
assert file.is_a?(Stripe::FileUpload)
|
|
end
|
|
end
|
|
|
|
should "be deserializable when `object=file`" do
|
|
file = Stripe::Util.convert_to_stripe_object({ object: "file" }, {})
|
|
assert file.is_a?(Stripe::FileUpload)
|
|
end
|
|
|
|
should "be deserializable when `object=file_upload`" do
|
|
file = Stripe::Util.convert_to_stripe_object({ object: "file_upload" }, {})
|
|
assert file.is_a?(Stripe::FileUpload)
|
|
end
|
|
end
|
|
end
|