|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'rails_helper' |
| 4 | +require_relative '../support/assign_allowed_group' |
| 5 | + |
| 6 | +RSpec.describe TopicViewSerializer do |
| 7 | + fab!(:user) { Fabricate(:user) } |
| 8 | + fab!(:topic) { Fabricate(:topic) } |
| 9 | + fab!(:post) { Fabricate(:post, topic: topic) } |
| 10 | + let(:guardian) { Guardian.new(user) } |
| 11 | + |
| 12 | + include_context 'A group that is allowed to assign' |
| 13 | + |
| 14 | + before do |
| 15 | + SiteSetting.assign_enabled = true |
| 16 | + add_to_assign_allowed_group(user) |
| 17 | + end |
| 18 | + |
| 19 | + it "includes assigned user in serializer" do |
| 20 | + Assigner.new(topic, user).assign(user) |
| 21 | + serializer = TopicViewSerializer.new(TopicView.new(topic), scope: guardian) |
| 22 | + expect(serializer.as_json[:topic_view][:assigned_to_user][:username]).to eq(user.username) |
| 23 | + expect(serializer.as_json[:topic_view][:assigned_to_group]).to be nil |
| 24 | + end |
| 25 | + |
| 26 | + it "includes assigned group in serializer" do |
| 27 | + Assigner.new(topic, user).assign(assign_allowed_group) |
| 28 | + serializer = TopicViewSerializer.new(TopicView.new(topic), scope: guardian) |
| 29 | + expect(serializer.as_json[:topic_view][:assigned_to_group][:name]).to eq(assign_allowed_group.name) |
| 30 | + expect(serializer.as_json[:topic_view][:assigned_to_user]).to be nil |
| 31 | + end |
| 32 | + |
| 33 | + it "includes priority in serializer" do |
| 34 | + Assigner.new(topic, user).assign(user, priority: 1) |
| 35 | + serializer = TopicViewSerializer.new(TopicView.new(topic), scope: guardian) |
| 36 | + expect(serializer.as_json[:topic_view][:assignment_priority]).to eq(1) |
| 37 | + end |
| 38 | +end |
0 commit comments