2020-04-21 11:21:10 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe API::Entities::User do
|
2021-10-08 02:11:46 -04:00
|
|
|
let_it_be(:timezone) { 'America/Los_Angeles' }
|
|
|
|
|
|
|
|
let(:user) { create(:user, timezone: timezone) }
|
2020-04-21 11:21:10 -04:00
|
|
|
let(:current_user) { create(:user) }
|
2021-10-08 02:11:46 -04:00
|
|
|
let(:entity) { described_class.new(user, current_user: current_user) }
|
2020-04-21 11:21:10 -04:00
|
|
|
|
2021-10-08 02:11:46 -04:00
|
|
|
subject { entity.as_json }
|
2020-04-21 11:21:10 -04:00
|
|
|
|
|
|
|
it 'exposes correct attributes' do
|
2021-06-18 08:10:03 -04:00
|
|
|
expect(subject).to include(:bio, :location, :public_email, :skype, :linkedin, :twitter, :website_url, :organization, :job_title, :work_information, :pronouns)
|
2020-04-21 11:21:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'exposes created_at if the current user can read the user profile' do
|
|
|
|
allow(Ability).to receive(:allowed?).with(current_user, :read_user_profile, user).and_return(true)
|
|
|
|
|
|
|
|
expect(subject).to include(:created_at)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not expose created_at if the current user cannot read the user profile' do
|
|
|
|
allow(Ability).to receive(:allowed?).with(current_user, :read_user_profile, user).and_return(false)
|
|
|
|
|
|
|
|
expect(subject).not_to include(:created_at)
|
|
|
|
end
|
2021-02-01 07:09:03 -05:00
|
|
|
|
|
|
|
it 'exposes user as not a bot' do
|
|
|
|
expect(subject[:bot]).to be_falsey
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with bot user' do
|
|
|
|
let(:user) { create(:user, :security_bot) }
|
|
|
|
|
|
|
|
it 'exposes user as a bot' do
|
|
|
|
expect(subject[:bot]).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
2021-10-08 02:11:46 -04:00
|
|
|
|
|
|
|
it 'exposes local_time' do
|
|
|
|
local_time = '2:30 PM'
|
|
|
|
expect(entity).to receive(:local_time).with(timezone).and_return(local_time)
|
|
|
|
expect(subject[:local_time]).to eq(local_time)
|
|
|
|
end
|
2020-04-21 11:21:10 -04:00
|
|
|
end
|