FEATURE: add user status to user preferences (#18532)

This commit is contained in:
Andrei Prigorshnev
2022-10-12 23:35:25 +04:00
committed by GitHub
parent 231dc10bbd
commit 0fe111e492
9 changed files with 410 additions and 2 deletions

View File

@@ -2472,6 +2472,224 @@ RSpec.describe UsersController do
expect(response.status).to eq(400)
end
end
context "with user status" do
context "as a regular user" do
before do
SiteSetting.enable_user_status = true
sign_in(user)
end
it "sets user status" do
status = {
emoji: "tooth",
description: "off to dentist",
}
put "/u/#{user.username}.json", params: {
status: status
}
expect(response.status).to eq(200)
user.reload
expect(user.user_status).not_to be_nil
expect(user.user_status.emoji).to eq(status[:emoji])
expect(user.user_status.description).to eq(status[:description])
end
it "updates user status" do
user.set_status!("off to dentist", "tooth")
user.reload
new_status = {
emoji: "surfing_man",
description: "surfing",
}
put "/u/#{user.username}.json", params: {
status: new_status
}
expect(response.status).to eq(200)
user.reload
expect(user.user_status).not_to be_nil
expect(user.user_status.emoji).to eq(new_status[:emoji])
expect(user.user_status.description).to eq(new_status[:description])
end
it "clears user status" do
user.set_status!("off to dentist", "tooth")
user.reload
put "/u/#{user.username}.json", params: {
status: nil
}
expect(response.status).to eq(200)
user.reload
expect(user.user_status).to be_nil
end
it "can't set status of another user" do
put "/u/#{user1.username}.json", params: {
status: {
emoji: "tooth",
description: "off to dentist",
}
}
expect(response.status).to eq(403)
user1.reload
expect(user1.user_status).to be_nil
end
it "can't update status of another user" do
old_status = {
emoji: "tooth",
description: "off to dentist",
}
user1.set_status!(old_status[:description], old_status[:emoji])
user1.reload
new_status = {
emoji: "surfing_man",
description: "surfing",
}
put "/u/#{user1.username}.json", params: {
status: new_status
}
expect(response.status).to eq(403)
user1.reload
expect(user1.user_status).not_to be_nil
expect(user1.user_status.emoji).to eq(old_status[:emoji])
expect(user1.user_status.description).to eq(old_status[:description])
end
it "can't clear status of another user" do
user1.set_status!("off to dentist", "tooth")
user1.reload
put "/u/#{user1.username}.json", params: {
status: nil
}
expect(response.status).to eq(403)
user1.reload
expect(user1.user_status).not_to be_nil
end
context 'when user status is disabled' do
before do
SiteSetting.enable_user_status = false
end
it "doesn't set user status" do
put "/u/#{user.username}.json", params: {
status: {
emoji: "tooth",
description: "off to dentist",
}
}
expect(response.status).to eq(200)
user.reload
expect(user.user_status).to be_nil
end
it "doesn't update user status" do
old_status = {
emoji: "tooth",
description: "off to dentist",
}
user.set_status!(old_status[:description], old_status[:emoji])
user.reload
new_status = {
emoji: "surfing_man",
description: "surfing",
}
put "/u/#{user.username}.json", params: {
status: new_status
}
expect(response.status).to eq(200)
user.reload
expect(user.user_status).not_to be_nil
expect(user.user_status.emoji).to eq(old_status[:emoji])
expect(user.user_status.description).to eq(old_status[:description])
end
it "doesn't clear user status" do
user.set_status!("off to dentist", "tooth")
user.reload
put "/u/#{user.username}.json", params: {
status: nil
}
expect(response.status).to eq(200)
user.reload
expect(user.user_status).not_to be_nil
end
end
end
context 'as a staff user' do
before do
SiteSetting.enable_user_status = true
sign_in(moderator)
end
it "sets another user's status" do
status = {
emoji: "tooth",
description: "off to dentist",
}
put "/u/#{user.username}.json", params: {
status: status
}
expect(response.status).to eq(200)
user.reload
expect(user.user_status).not_to be_nil
expect(user.user_status.emoji).to eq(status[:emoji])
expect(user.user_status.description).to eq(status[:description])
end
it "updates another user's status" do
user.set_status!("off to dentist", "tooth")
user.reload
new_status = {
emoji: "surfing_man",
description: "surfing",
}
put "/u/#{user.username}.json", params: {
status: new_status
}
expect(response.status).to eq(200)
user.reload
expect(user.user_status).not_to be_nil
expect(user.user_status.emoji).to eq(new_status[:emoji])
expect(user.user_status.description).to eq(new_status[:description])
end
it "clears another user's status" do
user.set_status!("off to dentist", "tooth")
user.reload
put "/u/#{user.username}.json", params: {
status: nil
}
expect(response.status).to eq(200)
user.reload
expect(user.user_status).to be_nil
end
end
end
end
describe '#badge_title' do