Sha256: 2a79e552650f6670f8be9cf02cca399032fc6a7a77dd9ecf267ff17173c0c320

Contents?: true

Size: 1.79 KB

Versions: 8

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true

require ::File.expand_path("../test_helper", __dir__)

module Stripe
  class CustomerCardTest < Test::Unit::TestCase
    setup do
      # Unfortunately, the OpenAPI spec has an issue where the sources list has the wrong
      # url so we need to mock this call instead.
      customer_json = { id: "cus_123", object: "customer", sources: { object: "list", data: [], has_more: true, url: "/v1/customers/cus_123/sources" } }
      stub_request(:get, "#{Stripe.api_base}/v1/customers/cus_123")
        .to_return(body: JSON.generate(customer_json))

      @customer = Stripe::Customer.retrieve("cus_123")
    end

    should "be listable" do
      sources = @customer.sources.list
      assert sources.data.is_a?(Array)
      # because of the terrible :wildcard nature of sources, the API stub
      # cannot currently replace this response with anything meaningful so we
      # don't assert on the type of individual items like we do in other tests
    end

    should "be creatable" do
      @customer.sources.create(
        source: "tok_123"
      )
      assert_requested :post, "#{Stripe.api_base}/v1/customers/#{@customer.id}/sources"
    end

    should "be deletable" do
      card = Stripe::Card.construct_from(customer: @customer.id,
                                         id: "card_123")
      card.delete
      assert_requested :delete, "#{Stripe.api_base}/v1/customers/#{@customer.id}/sources/card_123"
    end

    should "be saveable" do
      card = Stripe::Card.construct_from(customer: @customer.id,
                                         id: "card_123",
                                         metadata: {})
      card.metadata["key"] = "value"
      card.save
      assert_requested :post, "#{Stripe.api_base}/v1/customers/#{@customer.id}/sources/card_123"
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
stripe-5.31.0 test/stripe/customer_card_test.rb
stripe-5.30.0 test/stripe/customer_card_test.rb
stripe-5.29.1 test/stripe/customer_card_test.rb
stripe-5.29.0 test/stripe/customer_card_test.rb
stripe-5.28.0 test/stripe/customer_card_test.rb
stripe-5.27.0 test/stripe/customer_card_test.rb
stripe-5.26.0 test/stripe/customer_card_test.rb
stripe-5.25.0 test/stripe/customer_card_test.rb