2021-08-26 09:16:22 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-12-23 15:36:08 -05:00
|
|
|
require "rails_helper"
|
2021-08-26 09:16:22 -04:00
|
|
|
|
|
|
|
describe UserCardSerializer do
|
|
|
|
let(:user) { Fabricate(:user) }
|
2023-12-06 01:26:40 -05:00
|
|
|
let(:serializer) { described_class.new(user, scope: Guardian.new, root: false) }
|
2021-08-26 09:16:22 -04:00
|
|
|
let(:json) { serializer.as_json }
|
|
|
|
|
|
|
|
it "accepted_answers serializes number of accepted answers" do
|
2021-09-13 12:26:43 -04:00
|
|
|
post1 = Fabricate(:post, user: user)
|
|
|
|
DiscourseSolved.accept_answer!(post1, Discourse.system_user)
|
2021-08-26 09:16:22 -04:00
|
|
|
expect(serializer.as_json[:accepted_answers]).to eq(1)
|
|
|
|
|
2021-09-13 12:26:43 -04:00
|
|
|
post2 = Fabricate(:post, user: user)
|
|
|
|
DiscourseSolved.accept_answer!(post2, Discourse.system_user)
|
2021-08-26 09:16:22 -04:00
|
|
|
expect(serializer.as_json[:accepted_answers]).to eq(2)
|
2021-09-13 12:26:43 -04:00
|
|
|
|
|
|
|
DiscourseSolved.unaccept_answer!(post1)
|
|
|
|
expect(serializer.as_json[:accepted_answers]).to eq(1)
|
2021-08-26 09:16:22 -04:00
|
|
|
end
|
|
|
|
end
|