Sha256: fb94aa7a1323594786cd3cd81baaff2dbc06bf807eae6b2626744ee388c54054

Contents?: true

Size: 1.37 KB

Versions: 47

Compression:

Stored size: 1.37 KB

Contents

describe MangoPay do

  # see https://docs.mangopay.com/api-references/idempotency-support/

  include_context 'users'
  require 'securerandom'

  describe 'post requests' do

    it 'if called with no idempotency key, act independently' do
      u = define_new_natural_user
      u1 = MangoPay::NaturalUser.create(u)
      u2 = MangoPay::NaturalUser.create(u)
      expect(u2['Id']).to be > u1['Id']
    end

    it 'if called with same idempotency key, the 2nd call is blocked' do
      idempotency_key = SecureRandom.uuid
      u = define_new_natural_user
      u1 = MangoPay::NaturalUser.create(u, nil, idempotency_key)
      expect {
        u2 = MangoPay::NaturalUser.create(u, nil, idempotency_key)
      }.to raise_error(MangoPay::ResponseError)
    end

    it 'if called with different idempotency key, act independently and responses may be retreived later' do
      idempotency_key1 = SecureRandom.uuid
      idempotency_key2 = SecureRandom.uuid
      u = define_new_natural_user
      u1 = MangoPay::NaturalUser.create(u, nil, idempotency_key1)
      u2 = MangoPay::NaturalUser.create(u, nil, idempotency_key2)
      expect(u2['Id']).to be > u1['Id']

      resp1 = MangoPay.fetch_response(idempotency_key1)
      resp2 = MangoPay.fetch_response(idempotency_key2)
      expect(resp1['Resource']['Id']).to eq u1['Id']
      expect(resp2['Resource']['Id']).to eq u2['Id']
    end

  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
mangopay-3.28.0 spec/mangopay/idempotency_spec.rb
mangopay-3.27.0 spec/mangopay/idempotency_spec.rb
mangopay-3.26.1 spec/mangopay/idempotency_spec.rb
mangopay-3.26.0 spec/mangopay/idempotency_spec.rb
mangopay-3.25.1 spec/mangopay/idempotency_spec.rb
mangopay-3.25.0 spec/mangopay/idempotency_spec.rb
mangopay-3.24.1 spec/mangopay/idempotency_spec.rb
mangopay-3.24.0 spec/mangopay/idempotency_spec.rb
mangopay-3.23.0 spec/mangopay/idempotency_spec.rb
mangopay-3.22.0 spec/mangopay/idempotency_spec.rb
mangopay-3.21.0 spec/mangopay/idempotency_spec.rb
mangopay-3.20.0 spec/mangopay/idempotency_spec.rb
mangopay-3.19.0 spec/mangopay/idempotency_spec.rb
mangopay-3.18.0 spec/mangopay/idempotency_spec.rb
mangopay-3.17.0 spec/mangopay/idempotency_spec.rb
mangopay-3.16.0 spec/mangopay/idempotency_spec.rb
mangopay-3.15.0 spec/mangopay/idempotency_spec.rb
mangopay-3.14.0 spec/mangopay/idempotency_spec.rb
mangopay-3.13.2 spec/mangopay/idempotency_spec.rb
mangopay-3.12.0 spec/mangopay/idempotency_spec.rb