0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-08 17:53:55 +08:00
discourse/plugins/chat/spec/system/archive_channel_spec.rb
Régis Hanol d1a27693cf
FIX: Normalize tag-chooser tags to names in RSS polling and chat archive (#41654)
### What

Since #36678, `tag-chooser`/`mini-tag-chooser` emit an array of tag
**objects** instead of tag name strings. Two consumers still assumed
name strings and broke:

1. **RSS polling feed form** — the client-side required-tag validation
compared the category's required tag *names* against the selected tag
*objects*, so the comparison always failed. A feed pointed at a category
with a required tag group could never be saved from the UI, even when
the required tag was selected (reported on meta).

2. **Chat "archive channel → new topic"** — the selected tags were
POSTed as objects, which the controller's `tags: []` strong parameter
rejects, so the destination topic was created without any of the chosen
tags.

### Fix

Both consumers now map the tag objects to their `.name` before comparing
/ submitting, matching what the server (`normalize_tags`) and
select-kit's own `validateCreate` already do.

### Tests

Extended the existing system specs rather than adding new ones:
- RSS polling admin spec: the "saves the configuration" test's category
now requires the tag it selects, so the save exercises the required-tag
validation.
- Chat archive spec: the "works" test now selects a tag and asserts it
reaches the archive (`destination_tags`).
2026-07-13 14:19:14 +02:00

141 lines
4.3 KiB
Ruby
Vendored
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# frozen_string_literal: true
RSpec.describe "Archive channel" do
fab!(:channel_1, :chat_channel)
let(:chat) { PageObjects::Pages::Chat.new }
let(:channel) { PageObjects::Pages::ChatChannel.new }
before do
SiteSetting.navigation_menu = "sidebar"
chat_system_bootstrap
sign_in(current_user)
end
context "when archiving is disabled" do
context "when admin user" do
fab!(:current_user, :admin)
before { sign_in(current_user) }
it "doesnt allow to archive a channel" do
chat.visit_channel_settings(channel_1)
expect(page).to have_no_content(I18n.t("js.chat.channel_settings.archive_channel"))
end
end
end
context "when archiving is enabled" do
before { SiteSetting.chat_allow_archiving_channels = true }
context "when regular user" do
fab!(:current_user, :user)
before { sign_in(current_user) }
it "doesnt allow to archive a channel" do
chat.visit_channel_settings(channel_1)
expect(page).to have_no_content(I18n.t("js.chat.channel_settings.archive_channel"))
end
end
context "when admin user" do
fab!(:current_user, :admin)
before { sign_in(current_user) }
it "allows to archive a channel" do
chat.visit_channel_settings(channel_1)
expect(page).to have_content(I18n.t("js.chat.channel_settings.archive_channel"))
end
context "when archiving" do
it "works" do
SiteSetting.tagging_enabled = true
tag = Fabricate(:tag, name: "archived")
Jobs.run_immediately!
chat.visit_channel_settings(channel_1)
click_button(I18n.t("js.chat.channel_settings.archive_channel"))
find("#split-topic-name").fill_in(with: "An interesting topic for cats")
tag_chooser =
PageObjects::Components::SelectKit.new(".chat-to-topic-selector .tag-chooser")
tag_chooser.expand
tag_chooser.search(tag.name)
tag_chooser.select_row_by_name(tag.name)
tag_chooser.collapse
click_button(I18n.t("js.chat.channel_archive.title"))
expect(page).to have_css(".chat-channel-archive-status", wait: 15)
try_until_success do
archive = Chat::ChannelArchive.find_by(chat_channel: channel_1)
expect(archive&.destination_tags).to eq([tag.name])
end
end
context "when archived channels had unreads" do
let(:other_user) { Fabricate(:user) }
before do
channel_1.add(current_user)
channel_1.add(other_user)
end
it "clears unread indicators" do
Jobs.run_immediately!
Fabricate(
:chat_message,
chat_channel: channel_1,
user: other_user,
message: "this is fine @#{current_user.username}",
use_service: true,
)
visit("/")
expect(page.find(".chat-channel-unread-indicator")).to have_content(1)
chat.visit_channel_settings(channel_1)
click_button(I18n.t("js.chat.channel_settings.archive_channel"))
find("#split-topic-name").fill_in(with: "An interesting topic for cats")
click_button(I18n.t("js.chat.channel_archive.title"))
expect(page).to have_no_css(".chat-channel-unread-indicator")
end
end
end
context "when archiving failed" do
before { channel_1.update!(status: :read_only) }
fab!(:archive) do
Chat::ChannelArchive.create!(
chat_channel: channel_1,
archived_by: current_user,
destination_topic_title: "This will be the archive topic",
destination_category_id: channel_1.chatable_id,
total_messages: 2,
archived_messages: 1,
archive_error: "Something went wrong",
)
end
it "can be retried" do
chat.visit_channel(channel_1)
click_button(I18n.t("js.chat.channel_archive.retry"))
Jobs::Chat::ChannelArchive.new.execute(chat_channel_archive_id: archive.id)
archive_link = find(".chat-channel-archive-status a")
expect(archive_link[:href]).to end_with("/t/-/#{archive.reload.destination_topic_id}")
end
end
end
end
end