2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-01-11 13:09:06 -05:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe UserSummarySerializer do
|
|
|
|
it "returns expected data" do
|
2019-01-03 12:03:01 -05:00
|
|
|
UserActionManager.enable
|
2019-01-11 13:09:06 -05:00
|
|
|
user = Fabricate(:user)
|
2019-01-13 20:49:37 -05:00
|
|
|
liked_user = Fabricate(:user, name: "John Doe", username: "john_doe")
|
|
|
|
liked_post = create_post(user: liked_user)
|
2019-01-03 12:03:01 -05:00
|
|
|
PostActionCreator.like(user, liked_post)
|
2019-01-11 13:09:06 -05:00
|
|
|
|
|
|
|
guardian = Guardian.new(user)
|
|
|
|
summary = UserSummary.new(user, guardian)
|
|
|
|
serializer = UserSummarySerializer.new(summary, scope: guardian, root: false)
|
|
|
|
json = serializer.as_json
|
|
|
|
|
2019-01-13 20:56:10 -05:00
|
|
|
expect(json[:likes_given]).to eq(1)
|
2019-01-11 13:09:06 -05:00
|
|
|
expect(json[:likes_received]).to be_present
|
|
|
|
expect(json[:posts_read_count]).to be_present
|
|
|
|
expect(json[:topic_count]).to be_present
|
|
|
|
expect(json[:time_read]).to be_present
|
2019-01-13 20:49:37 -05:00
|
|
|
expect(json[:most_liked_users][0][:count]).to eq(1)
|
|
|
|
expect(json[:most_liked_users][0][:name]).to eq("John Doe")
|
|
|
|
expect(json[:most_liked_users][0][:username]).to eq("john_doe")
|
|
|
|
expect(json[:most_liked_users][0][:avatar_template]).to eq(liked_user.avatar_template)
|
|
|
|
|
|
|
|
# do not include full name if disabled
|
|
|
|
SiteSetting.enable_names = false
|
|
|
|
expect(serializer.as_json[:most_liked_users][0][:name]).to eq(nil)
|
2019-01-11 13:09:06 -05:00
|
|
|
end
|
|
|
|
end
|