Sha256: 4a41e17247776ffa29d94a99d275a4d2abb284299dcabf90db947b9bdd62031a

Contents?: true

Size: 1.81 KB

Versions: 1

Compression:

Stored size: 1.81 KB

Contents

require 'spec_helper'

describe SendgridThreads::Api do

  let(:connection_mock) { instance_double("Api") }
  let(:connection_params) do
    {key: 'foobar', secret: 'abc123'}
  end

  before(:all) do
    Timecop.freeze(Time.utc(2015, 11, 01, 12))
  end

  after(:all) do
    Timecop.return
  end

  it "initializes a valid connection" do
    expect(SendgridThreads::Client).to receive(:new).with(connection_params).and_return(connection_mock)
    SendgridThreads::Api.new(connection_params)
  end

  describe "v1" do
    let(:user_id) { "12345678" }
    let(:traits) do
      {email: "test@example.com", name: "Sendgrid Tester"}
    end
    let(:properties) do
      {plan: 1, subscription: 2}
    end

    before do
      allow(SendgridThreads::Client).to receive(:new).with(connection_params).and_return(connection_mock)
    end

    subject { SendgridThreads::Api.new(connection_params) }

    it "#identify" do
      expect(connection_mock).to receive(:post).with(
        "identify", {userId: user_id, traits: traits, timestamp: "2015-11-01T12:00:00.000Z"}
      )
      subject.identify(user_id, traits)
    end

    it "#track" do
      expect(connection_mock).to receive(:post).with(
        "track", {userId: user_id, event: "event", timestamp: "2015-11-01T12:00:00.000Z", properties: properties }
      )
      subject.track(user_id, "event", properties)
    end

    it "#page_view" do
      expect(connection_mock).to receive(:post).with(
        "page", {userId: user_id, name: "Page Name", timestamp: "2015-11-01T12:00:00.000Z", properties: properties }
      )
      subject.page_view(user_id, "Page Name", properties)
    end

    it "#remove" do
      expect(connection_mock).to receive(:post).with(
        "remove", {userId: user_id, timestamp: "2015-11-01T12:00:00.000Z" }
      )
      subject.remove(user_id)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sendgrid-threads-0.1.0 spec/sendgrid_threads/api_spec.rb