Sha256: 47e7f38466c29517d0803ac1d5d3098a42457b836ab1d4390e84ec170b0a22e8

Contents?: true

Size: 1.69 KB

Versions: 16

Compression:

Stored size: 1.69 KB

Contents

require 'spec_helper'

describe "user_identities" do
  let(:client) { create_client }
  let(:user)   { client.users.create(email: mock_email, name: mock_uuid, verified: true) }

  include_examples "zendesk resource", {
    :create_params => lambda { { value: "ey+#{mock_uuid}@example.org", type: "email", user_id: user.id } },
    :update_params => lambda { { verified: true } },
    :fetch_params  => lambda { |uc| { "user_id" => uc.user_id, "id" => uc.id } },
    :collection    => lambda { client.user_identities(user_id: user.id) },
    :paged         => false,
    :search        => false,
  }

  describe "#create_user_identity" do
    let(:another_user) { client.users.create(email: mock_email, name: mock_uuid, verified: true) }

    it "should prevent duplicate identities across users" do
      expect {
        client.create_user_identity("user_identity" => { "type" => "email", "value" => user.email, "user_id" => another_user.id })
      }.to raise_exception(Zendesk2::Error, /is already being used by another user/)
    end

    it "should prevent duplicate identities on the same user" do
      expect {
        client.create_user_identity("user_identity" => { "type" => "email", "value" => user.email, "user_id" => user.id })
      }.to raise_exception(Zendesk2::Error, /is already being used by another user/)
    end

    it "should be allowed if the user is deleted" do
      email = user.email
      user.destroy

      expect {
        client.create_user_identity(
          "user_identity" => {
            "type"    => "email",
            "value"   => email,
            "user_id" => another_user.id,
          }
        )
      }.to change { another_user.identities.all.count }.by(1)
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
zendesk2-1.6.1 spec/user_identities_spec.rb
zendesk2-1.5.17 spec/user_identities_spec.rb
zendesk2-1.5.16 spec/user_identities_spec.rb
zendesk2-1.5.15 spec/user_identities_spec.rb
zendesk2-1.5.14 spec/user_identities_spec.rb
zendesk2-1.5.13 spec/user_identities_spec.rb
zendesk2-1.5.12 spec/user_identities_spec.rb
zendesk2-1.5.11 spec/user_identities_spec.rb
zendesk2-1.5.10 spec/user_identities_spec.rb
zendesk2-1.5.9 spec/user_identities_spec.rb
zendesk2-1.5.8 spec/user_identities_spec.rb
zendesk2-1.5.7 spec/user_identities_spec.rb
zendesk2-1.5.6 spec/user_identities_spec.rb
zendesk2-1.5.5 spec/user_identities_spec.rb
zendesk2-1.5.4 spec/user_identities_spec.rb
zendesk2-1.5.3 spec/user_identities_spec.rb