scim_identity_spec.rb 1.68 KB
Newer Older
1 2 3 4
# frozen_string_literal: true

require 'spec_helper'

5
RSpec.describe ScimIdentity do
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
  describe 'relations' do
    it { is_expected.to belong_to(:group) }
    it { is_expected.to belong_to(:user) }
  end

  describe 'validations' do
    let_it_be(:user) { create(:user) }
    let_it_be(:group) { create(:group) }

    context 'with existing user and group' do
      before do
        create(:scim_identity, user: user, group: group, extern_uid: user.email)
      end

      it 'returns false for a duplicate identity with the same extern_uid' do
        identity = user.scim_identities.build(group: group, extern_uid: user.email)

        expect(identity.validate).to eq(false)
      end

      it 'returns false for a duplicate identity with different extern_uid' do
        identity = user.scim_identities.build(group: group, extern_uid: '1234abcd')

        expect(identity.validate).to eq(false)
      end

      it 'returns true when a different group is used' do
        other_group = create(:group)
        identity = user.scim_identities.build(group: other_group, extern_uid: user.email)

        expect(identity.validate).to eq(true)
      end

      it 'returns false for a duplicate extern_uid with different case' do
        identity = user.scim_identities.build(group: group, extern_uid: user.email.upcase)

        expect(identity.validate).to eq(false)
      end
    end
  end

  describe '.with_extern_uid' do
    it 'finds identity regardless of case' do
      user = create(:user)
      group = create(:group)

52
      identity = user.scim_identities.create!(group: group, extern_uid: user.email)
53 54 55 56 57

      expect(group.scim_identities.with_extern_uid(user.email.upcase).first).to eq identity
    end
  end
end