Sha256: f61117665a4c635eb11f3fd1de48030b0de83421c16c020fa9b51654a4e662ee

Contents?: true

Size: 1.41 KB

Versions: 4

Compression:

Stored size: 1.41 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

4 entries across 4 versions & 1 rubygems

Version Path
mangopay-3.0.25 spec/mangopay/idempotency_spec.rb
mangopay-3.0.23 spec/mangopay/idempotency_spec.rb
mangopay-3.0.21 spec/mangopay/idempotency_spec.rb
mangopay-3.0.20 spec/mangopay/idempotency_spec