spec: for anonymous messages

fixes VICE-2432
flag=discussion_anonymity

Test Plan:
1) Review Specs.
2) Ensure they are appropriate

Change-Id: If3bfaddf186f72ea6c363b855ae4e50833540b6a
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/283215
Reviewed-by: Caleb Guanzon <cguanzon@instructure.com>
QA-Review: Omar Soto-Fortuño <omar.soto@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Caleb Guanzon <cguanzon@instructure.com>
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
This commit is contained in:
Chawn Neal 2022-01-20 11:27:38 -06:00
parent 90cf047e00
commit c72b28f506
3 changed files with 109 additions and 1 deletions

View File

@ -51,5 +51,20 @@ describe "new_discussion_entry" do
msg = generate_message(notification_name, path_type, asset) msg = generate_message(notification_name, path_type, asset)
expect(msg.body.include?("replying to this message")).to eq false expect(msg.body.include?("replying to this message")).to eq false
end end
context "fully anonymous topic" do
let(:anonymous_topic) { discussion_topic_model(anonymous_state: "full_anonymity") }
before :once do
@user = user_model(name: "Chawn Neal")
@object = anonymous_topic.discussion_entries.create!(user: @user)
end
it "does not render user name" do
msg = generate_message(notification_name, path_type, @object)
expect(msg.body).to match(/Anonymous\s\w+\sreplied\sto/)
expect(msg.body).not_to include(@user.short_name)
end
end
end end
end end

View File

@ -21,6 +21,7 @@
describe DiscussionEntry do describe DiscussionEntry do
let(:topic) { discussion_topic_model } let(:topic) { discussion_topic_model }
let(:anonymous_topic) { discussion_topic_model(anonymous_state: "full_anonymity") } let(:anonymous_topic) { discussion_topic_model(anonymous_state: "full_anonymity") }
let(:partially_anonymous_topic) { discussion_topic_model(anonymous_state: "partial_anonymity") }
describe "callback lifecycle" do describe "callback lifecycle" do
before(:once) do before(:once) do
@ -863,7 +864,7 @@ describe DiscussionEntry do
end end
end end
describe "author_name" do describe "#author_name" do
let(:user) { user_model(name: "John Doe") } let(:user) { user_model(name: "John Doe") }
let(:entry) { topic.discussion_entries.create!(message: "Hello!", user: user) } let(:entry) { topic.discussion_entries.create!(message: "Hello!", user: user) }
let(:anon_entry) { anonymous_topic.discussion_entries.create!(message: "Hello!", user: user) } let(:anon_entry) { anonymous_topic.discussion_entries.create!(message: "Hello!", user: user) }
@ -879,5 +880,41 @@ describe DiscussionEntry do
it "returns You as anonymous author name" do it "returns You as anonymous author name" do
expect(anon_entry.author_name(user)).to eq "John Doe" expect(anon_entry.author_name(user)).to eq "John Doe"
end end
context "discussion_topic.anonymous?" do
context "TeacherEnrollment" do
it "returns user.short_name" do
anonymous_topic.course.enroll_user(user, "TeacherEnrollment", enrollment_state: "active")
entry = anonymous_topic.discussion_entries.create!(message: "Hello!", user: user)
expect(entry.author_name).to eq(user.short_name)
end
end
context "TaEnrollment" do
it "returns user.short_name" do
anonymous_topic.course.enroll_user(user, "TaEnrollment", enrollment_state: "active")
entry = anonymous_topic.discussion_entries.create!(message: "Hello!", user: user)
expect(entry.author_name).to eq(user.short_name)
end
end
context "DesignerEnrollment" do
it "returns user.short_name" do
anonymous_topic.course.enroll_user(user, "DesignerEnrollment", enrollment_state: "active")
entry = anonymous_topic.discussion_entries.create!(message: "Hello!", user: user)
expect(entry.author_name).to eq(user.short_name)
end
end
context "discussion_topic partial_anonymity && !entry.is_anonymous_author" do
it "returns user.short_name" do
entry = partially_anonymous_topic.discussion_entries.create!(message: "Hello!", user: user, is_anonymous_author: false)
expect(entry.author_name).to eq(user.short_name)
end
end
end
end end
end end

View File

@ -197,6 +197,62 @@ describe Message do
end end
end end
describe "#author_avatar_url" do
context "discussion entry and discussion_topic is anonymous" do
it "returns correct url" do
discussion_topic_model
@topic.update(anonymous_state: "full_anonymity")
@discussion_entry = @topic.discussion_entries.create!(user: user_model)
message_model(context: @discussion_entry)
expect(@topic).to be_anonymous
expect(@message.author_avatar_url).to eq("https://canvas.instructure.com/images/messages/avatar-50.png")
end
end
end
describe "#author_short_name" do
context "discussion entry and discussion_topic is anonymous" do
it "returns discussion entry author_name" do
discussion_topic_model
@topic.update(anonymous_state: "full_anonymity")
@discussion_entry = @topic.discussion_entries.create!(user: user_model)
message_model(context: @discussion_entry)
expect(@topic).to be_anonymous
expect(@message.author_short_name).to eq(@discussion_entry.author_name)
end
end
end
describe "#infer_from_name" do
context "discussion entry and discussion_topic is anonymous" do
it "returns discussion entry author_name" do
discussion_topic_model
@topic.update(anonymous_state: "full_anonymity")
@discussion_entry = @topic.discussion_entries.create!(user: user_model)
message_model(context: @discussion_entry)
expect(@topic).to be_anonymous
expect(@message.from_name).to eq(@discussion_entry.author_name)
end
end
end
describe "#author_email_address" do
context "discussion entry and discussion_topic is anonymous" do
it "returns nil" do
discussion_topic_model
@topic.update(anonymous_state: "full_anonymity")
@discussion_entry = @topic.discussion_entries.create!(user: user_model)
message_model(context: @discussion_entry)
expect(@topic).to be_anonymous
expect(@message.author_email_address).to be_nil
end
end
end
it "raises an error when trying to re-save an existing message" do it "raises an error when trying to re-save an existing message" do
message_model message_model
@message.body = "something else" @message.body = "something else"