Sha256: 2e7c213566ff6d77426fdf3db20a980af1c7470748506153c3eb311ddc900c9b

Contents?: true

Size: 1.86 KB

Versions: 4

Compression:

Stored size: 1.86 KB

Contents

require 'spec_helper'
describe MarketingCloudSDK::Rest do
  let(:client) { MarketingCloudSDK::Client.new }

  subject { client }
  it { should respond_to(:rest_get) }
  it { should respond_to(:rest_client) }
  it { should respond_to(:complete_url) }

  describe '#complete_url' do
    it 'raises an exception when identities are missing' do
      expect { client.complete_url "some_url/%{parent}/%{child}", {parent: 1} }.to raise_exception 'key{child} not found to complete some_url/%{parent}/%{child}'
    end

    it 'returns url with all identities replaced' do
      expect( client.complete_url "some_url/%{parent}/%{child}", {:parent => 1, :child => 2} ).to eq 'some_url/1/2'
    end

    it 'handles identities with string keys' do
      expect( client.complete_url "some_url/%{parent}/%{child}", {'parent'=> 1, 'child'=> 2} ).to eq 'some_url/1/2'
    end

    it 'treats empty values as optional keys' do
      expect( client.complete_url "some_url/%{parent}/%{child}", {'parent'=> 1, 'child'=> ''} ).to eq 'some_url/1'
    end

    it 'handles extra keys' do
      expect( client.complete_url "some_url/%{parent}/%{child}", {'parent'=> 1, 'child'=> '', 'other' => 1} ).to eq 'some_url/1'
    end
  end

  describe '#get_url_properties' do
    it 'returns hash of properties in format string' do
      expect( client.get_url_properties "some_url/%{parent}/%{child}", {'parent'=> 1, 'child'=> '', 'other' => 1} ).to eq({'parent' => 1, 'child' => ''})
    end

    it 'handles missing url properties' do
      expect( client.get_url_properties "some_url/%{parent}/%{child}", {'parent'=> 1, 'other' => 1} ).to eq({'parent' => 1})
    end

    it 'filters url properties from properties leaving query params' do
      properties = {'parent'=> 1, 'other' => 1}
      client.get_url_properties "some_url/%{parent}/%{child}", properties
      expect(properties).to eq 'other' => 1
    end
  end

end

Version data entries

4 entries across 4 versions & 3 rubygems

Version Path
sfmc-fuelsdk-ruby-1.3.1 spec/rest_spec.rb
sfmc-fuelsdk-ruby-1.1.0 spec/rest_spec.rb
dragostsesdk-1.1.0 spec/rest_spec.rb
marketingcloudsdk-1.0.0 spec/rest_spec.rb