gitlab-org--gitlab-foss/spec/serializers/member_user_entity_spec.rb

48 lines
1.4 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require 'spec_helper'
RSpec.describe MemberUserEntity do
let_it_be(:user) { create(:user, last_activity_on: Date.today) }
let_it_be(:emoji) { 'slight_smile' }
let_it_be(:user_status) { create(:user_status, user: user, emoji: emoji) }
let(:entity) { described_class.new(user) }
let(:entity_hash) { entity.as_json }
it 'matches json schema' do
expect(entity.to_json).to match_schema('entities/member_user')
end
it 'correctly exposes `avatar_url`' do
avatar_url = 'https://www.gravatar.com/avatar/c4637cb869d5f94c3193bde4f23d4cdc?s=80&d=identicon'
allow(user).to receive(:avatar_url).and_return(avatar_url)
expect(entity_hash[:avatar_url]).to match(avatar_url)
end
it 'correctly exposes `blocked`' do
allow(user).to receive(:blocked?).and_return(true)
expect(entity_hash[:blocked]).to be(true)
end
it 'correctly exposes `two_factor_enabled`' do
allow(user).to receive(:two_factor_enabled?).and_return(true)
expect(entity_hash[:two_factor_enabled]).to be(true)
end
it 'correctly exposes `status.emoji`' do
expect(entity_hash[:status][:emoji]).to match(emoji)
end
it 'correctly exposes `created_at`' do
expect(entity_hash[:created_at]).to be(user.created_at)
end
it 'correctly exposes `last_activity_on`' do
expect(entity_hash[:last_activity_on]).to be(user.last_activity_on)
end
end