2019-05-12 22:37:49 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
require "rails_helper"
|
|
|
|
require_relative "../dummy_provider"
|
2017-07-05 18:00:58 -04:00
|
|
|
|
2021-07-13 15:36:16 -04:00
|
|
|
RSpec.describe DiscourseChatIntegration::Manager do
|
2022-10-03 15:36:52 -04:00
|
|
|
include_context "with dummy provider"
|
2017-07-13 17:13:03 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
let(:chan1) { DiscourseChatIntegration::Channel.create!(provider: "dummy") }
|
|
|
|
let(:chan2) { DiscourseChatIntegration::Channel.create!(provider: "dummy") }
|
2017-07-13 17:13:03 -04:00
|
|
|
|
2017-08-01 15:53:39 -04:00
|
|
|
let(:category) { Fabricate(:category) }
|
|
|
|
let(:tag1) { Fabricate(:tag) }
|
|
|
|
let(:tag2) { Fabricate(:tag) }
|
|
|
|
let(:tag3) { Fabricate(:tag) }
|
2017-07-05 18:00:58 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
describe ".process_command" do
|
|
|
|
describe "add new rule" do
|
2017-08-01 15:53:39 -04:00
|
|
|
# Not testing how filters are merged here, that's done in .smart_create_rule
|
|
|
|
# We just want to make sure the commands are being interpretted correctly
|
2017-07-19 13:22:50 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
it "should add a new rule correctly" do
|
|
|
|
response = DiscourseChatIntegration::Helper.process_command(chan1, ["watch", category.slug])
|
2017-07-19 13:22:50 -04:00
|
|
|
|
2017-08-01 15:53:39 -04:00
|
|
|
expect(response).to eq(I18n.t("chat_integration.provider.dummy.create.created"))
|
|
|
|
|
2021-07-13 15:36:16 -04:00
|
|
|
rule = DiscourseChatIntegration::Rule.all.first
|
2017-08-01 15:53:39 -04:00
|
|
|
expect(rule.channel).to eq(chan1)
|
2022-12-29 07:31:05 -05:00
|
|
|
expect(rule.filter).to eq("watch")
|
2017-08-01 15:53:39 -04:00
|
|
|
expect(rule.category_id).to eq(category.id)
|
|
|
|
expect(rule.tags).to eq(nil)
|
|
|
|
end
|
2017-07-19 13:22:50 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
it "should work with all four filter types" do
|
|
|
|
response =
|
|
|
|
DiscourseChatIntegration::Helper.process_command(chan1, ["thread", category.slug])
|
2020-06-15 11:45:25 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
rule = DiscourseChatIntegration::Rule.all.first
|
|
|
|
expect(rule.filter).to eq("thread")
|
2017-07-19 13:22:50 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
response = DiscourseChatIntegration::Helper.process_command(chan1, ["watch", category.slug])
|
2017-07-19 13:22:50 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
rule = DiscourseChatIntegration::Rule.all.first
|
|
|
|
expect(rule.filter).to eq("watch")
|
2017-07-19 13:22:50 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
response =
|
|
|
|
DiscourseChatIntegration::Helper.process_command(chan1, ["follow", category.slug])
|
2017-07-19 13:22:50 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
rule = DiscourseChatIntegration::Rule.all.first
|
|
|
|
expect(rule.filter).to eq("follow")
|
2017-07-19 13:22:50 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
response = DiscourseChatIntegration::Helper.process_command(chan1, ["mute", category.slug])
|
2017-07-19 13:22:50 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
rule = DiscourseChatIntegration::Rule.all.first
|
|
|
|
expect(rule.filter).to eq("mute")
|
|
|
|
end
|
2017-07-19 13:22:50 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
it "errors on incorrect categories" do
|
|
|
|
response = DiscourseChatIntegration::Helper.process_command(chan1, %w[watch blah])
|
2017-08-01 15:53:39 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
expect(response).to eq(
|
|
|
|
I18n.t(
|
|
|
|
"chat_integration.provider.dummy.not_found.category",
|
|
|
|
name: "blah",
|
|
|
|
list: "uncategorized",
|
|
|
|
),
|
|
|
|
)
|
|
|
|
end
|
2017-07-19 13:22:50 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
context "with tags enabled" do
|
|
|
|
before { SiteSetting.tagging_enabled = true }
|
2017-07-19 13:22:50 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
it "should add a new tag rule correctly" do
|
|
|
|
response =
|
|
|
|
DiscourseChatIntegration::Helper.process_command(chan1, ["watch", "tag:#{tag1.name}"])
|
2017-07-19 13:22:50 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
expect(response).to eq(I18n.t("chat_integration.provider.dummy.create.created"))
|
2017-07-19 13:22:50 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
rule = DiscourseChatIntegration::Rule.all.first
|
|
|
|
expect(rule.channel).to eq(chan1)
|
|
|
|
expect(rule.filter).to eq("watch")
|
|
|
|
expect(rule.category_id).to eq(nil)
|
|
|
|
expect(rule.tags).to eq([tag1.name])
|
|
|
|
end
|
2017-08-01 15:53:39 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
it "should work with a category and multiple tags" do
|
|
|
|
response =
|
|
|
|
DiscourseChatIntegration::Helper.process_command(
|
|
|
|
chan1,
|
|
|
|
["watch", category.slug, "tag:#{tag1.name}", "tag:#{tag2.name}"],
|
|
|
|
)
|
2017-08-01 15:53:39 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
expect(response).to eq(I18n.t("chat_integration.provider.dummy.create.created"))
|
2017-07-19 13:22:50 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
rule = DiscourseChatIntegration::Rule.all.first
|
|
|
|
expect(rule.channel).to eq(chan1)
|
|
|
|
expect(rule.filter).to eq("watch")
|
|
|
|
expect(rule.category_id).to eq(category.id)
|
|
|
|
expect(rule.tags).to contain_exactly(tag1.name, tag2.name)
|
|
|
|
end
|
2017-07-19 13:22:50 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
it "errors on incorrect tags" do
|
|
|
|
response =
|
|
|
|
DiscourseChatIntegration::Helper.process_command(
|
|
|
|
chan1,
|
|
|
|
["watch", category.slug, "tag:blah"],
|
|
|
|
)
|
|
|
|
expect(response).to eq(
|
|
|
|
I18n.t("chat_integration.provider.dummy.not_found.tag", name: "blah"),
|
|
|
|
)
|
2017-07-19 13:22:50 -04:00
|
|
|
end
|
2022-12-29 07:31:05 -05:00
|
|
|
end
|
2017-08-01 15:53:39 -04:00
|
|
|
end
|
2017-07-19 13:22:50 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
describe "remove rule" do
|
|
|
|
it "removes the rule" do
|
|
|
|
rule1 =
|
|
|
|
DiscourseChatIntegration::Rule.create(
|
|
|
|
channel: chan1,
|
|
|
|
filter: "watch",
|
|
|
|
category_id: category.id,
|
|
|
|
tags: [tag1.name, tag2.name],
|
|
|
|
)
|
2017-07-19 13:22:50 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
expect(DiscourseChatIntegration::Rule.all.size).to eq(1)
|
2017-08-01 15:53:39 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
response = DiscourseChatIntegration::Helper.process_command(chan1, %w[remove 1])
|
2017-07-19 13:22:50 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
expect(response).to eq(I18n.t("chat_integration.provider.dummy.delete.success"))
|
2017-07-19 13:22:50 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
expect(DiscourseChatIntegration::Rule.all.size).to eq(0)
|
|
|
|
end
|
2017-07-19 13:22:50 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
it "errors correctly" do
|
|
|
|
response = DiscourseChatIntegration::Helper.process_command(chan1, %w[remove 1])
|
|
|
|
expect(response).to eq(I18n.t("chat_integration.provider.dummy.delete.error"))
|
2017-07-19 13:22:50 -04:00
|
|
|
end
|
2022-12-29 07:31:05 -05:00
|
|
|
end
|
2017-07-19 13:22:50 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
describe "help command" do
|
|
|
|
it "should return the right response" do
|
|
|
|
response = DiscourseChatIntegration::Helper.process_command(chan1, ["help"])
|
|
|
|
expect(response).to eq(I18n.t("chat_integration.provider.dummy.help"))
|
2017-07-19 13:22:50 -04:00
|
|
|
end
|
2022-12-29 07:31:05 -05:00
|
|
|
end
|
2017-07-19 13:22:50 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
describe "status command" do
|
|
|
|
it "should return the right response" do
|
|
|
|
response = DiscourseChatIntegration::Helper.process_command(chan1, ["status"])
|
|
|
|
expect(response).to eq(DiscourseChatIntegration::Helper.status_for_channel(chan1))
|
2017-07-19 13:22:50 -04:00
|
|
|
end
|
2022-12-29 07:31:05 -05:00
|
|
|
end
|
2017-07-19 13:22:50 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
describe "unknown command" do
|
|
|
|
it "should return the right response" do
|
|
|
|
response = DiscourseChatIntegration::Helper.process_command(chan1, ["somerandomtext"])
|
|
|
|
expect(response).to eq(I18n.t("chat_integration.provider.dummy.parse_error"))
|
2017-07-19 13:22:50 -04:00
|
|
|
end
|
2022-12-29 07:31:05 -05:00
|
|
|
end
|
2017-07-19 13:22:50 -04:00
|
|
|
end
|
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
describe ".status_for_channel" do
|
|
|
|
context "with no rules" do
|
|
|
|
it "includes the heading" do
|
2021-07-13 15:36:16 -04:00
|
|
|
string = DiscourseChatIntegration::Helper.status_for_channel(chan1)
|
2022-12-29 07:31:05 -05:00
|
|
|
expect(string).to include("dummy.status.header")
|
2017-07-05 18:00:58 -04:00
|
|
|
end
|
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
it "includes the no_rules string" do
|
2021-07-13 15:36:16 -04:00
|
|
|
string = DiscourseChatIntegration::Helper.status_for_channel(chan1)
|
2022-12-29 07:31:05 -05:00
|
|
|
expect(string).to include("dummy.status.no_rules")
|
2017-07-05 18:00:58 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
context "with some rules" do
|
2017-08-01 15:53:39 -04:00
|
|
|
let(:group) { Fabricate(:group) }
|
2017-07-05 18:00:58 -04:00
|
|
|
before do
|
2022-12-29 07:31:05 -05:00
|
|
|
DiscourseChatIntegration::Rule.create!(
|
|
|
|
channel: chan1,
|
|
|
|
filter: "watch",
|
|
|
|
category_id: category.id,
|
|
|
|
tags: nil,
|
|
|
|
)
|
|
|
|
DiscourseChatIntegration::Rule.create!(
|
|
|
|
channel: chan1,
|
|
|
|
filter: "mute",
|
|
|
|
category_id: nil,
|
|
|
|
tags: nil,
|
|
|
|
)
|
|
|
|
DiscourseChatIntegration::Rule.create!(
|
|
|
|
channel: chan1,
|
|
|
|
filter: "follow",
|
|
|
|
category_id: nil,
|
|
|
|
tags: [tag1.name],
|
|
|
|
)
|
|
|
|
DiscourseChatIntegration::Rule.create!(
|
|
|
|
channel: chan1,
|
|
|
|
filter: "watch",
|
|
|
|
type: "group_message",
|
|
|
|
group_id: group.id,
|
|
|
|
)
|
|
|
|
DiscourseChatIntegration::Rule.create!(
|
|
|
|
channel: chan2,
|
|
|
|
filter: "watch",
|
|
|
|
category_id: 1,
|
|
|
|
tags: nil,
|
|
|
|
)
|
2018-10-17 00:57:38 -04:00
|
|
|
|
|
|
|
SiteSetting.tagging_enabled = false
|
2017-07-05 18:00:58 -04:00
|
|
|
end
|
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
it "displays the correct rules" do
|
2021-07-13 15:36:16 -04:00
|
|
|
string = DiscourseChatIntegration::Helper.status_for_channel(chan1)
|
2022-12-29 07:31:05 -05:00
|
|
|
expect(string.scan("status.rule_string").size).to eq(4)
|
2017-07-05 18:00:58 -04:00
|
|
|
end
|
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
it "only displays tags for rules with tags" do
|
2021-07-13 15:36:16 -04:00
|
|
|
string = DiscourseChatIntegration::Helper.status_for_channel(chan1)
|
2022-12-29 07:31:05 -05:00
|
|
|
expect(string.scan("rule_string_tags_suffix").size).to eq(0)
|
2017-07-05 18:00:58 -04:00
|
|
|
|
|
|
|
SiteSetting.tagging_enabled = true
|
2021-07-13 15:36:16 -04:00
|
|
|
string = DiscourseChatIntegration::Helper.status_for_channel(chan1)
|
2022-12-29 07:31:05 -05:00
|
|
|
expect(string.scan("rule_string_tags_suffix").size).to eq(1)
|
2017-07-05 18:00:58 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
describe ".delete_by_index" do
|
2017-08-01 15:53:39 -04:00
|
|
|
let(:category2) { Fabricate(:category) }
|
|
|
|
let(:category3) { Fabricate(:category) }
|
2017-07-06 16:36:50 -04:00
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
it "deletes the correct rule" do
|
2017-08-01 15:53:39 -04:00
|
|
|
# Three identical rules, with different filters
|
2017-07-26 16:14:29 -04:00
|
|
|
# Status will be sorted by precedence
|
2017-07-06 16:36:50 -04:00
|
|
|
# be in this order
|
2022-12-29 07:31:05 -05:00
|
|
|
rule1 =
|
|
|
|
DiscourseChatIntegration::Rule.create(
|
|
|
|
channel: chan1,
|
|
|
|
filter: "mute",
|
|
|
|
category_id: category.id,
|
|
|
|
tags: [tag1.name, tag2.name],
|
|
|
|
)
|
|
|
|
rule2 =
|
|
|
|
DiscourseChatIntegration::Rule.create(
|
|
|
|
channel: chan1,
|
|
|
|
filter: "watch",
|
|
|
|
category_id: category2.id,
|
|
|
|
tags: [tag1.name, tag2.name],
|
|
|
|
)
|
|
|
|
rule3 =
|
|
|
|
DiscourseChatIntegration::Rule.create(
|
|
|
|
channel: chan1,
|
|
|
|
filter: "follow",
|
|
|
|
category_id: category3.id,
|
|
|
|
tags: [tag1.name, tag2.name],
|
|
|
|
)
|
2017-07-06 16:36:50 -04:00
|
|
|
|
2021-07-13 15:36:16 -04:00
|
|
|
expect(DiscourseChatIntegration::Rule.all.size).to eq(3)
|
2017-07-06 16:36:50 -04:00
|
|
|
|
2021-07-13 15:36:16 -04:00
|
|
|
expect(DiscourseChatIntegration::Helper.delete_by_index(chan1, 2)).to eq(:deleted)
|
2017-07-06 16:36:50 -04:00
|
|
|
|
2021-07-13 15:36:16 -04:00
|
|
|
expect(DiscourseChatIntegration::Rule.all.size).to eq(2)
|
2022-12-29 07:31:05 -05:00
|
|
|
expect(DiscourseChatIntegration::Rule.all.map(&:category_id)).to contain_exactly(
|
|
|
|
category.id,
|
|
|
|
category3.id,
|
|
|
|
)
|
2017-07-06 16:36:50 -04:00
|
|
|
end
|
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
it "fails gracefully for out of range indexes" do
|
|
|
|
rule1 =
|
|
|
|
DiscourseChatIntegration::Rule.create(
|
|
|
|
channel: chan1,
|
|
|
|
filter: "watch",
|
|
|
|
category_id: category.id,
|
|
|
|
tags: [tag1.name, tag2.name],
|
|
|
|
)
|
2017-07-06 16:36:50 -04:00
|
|
|
|
2021-07-13 15:36:16 -04:00
|
|
|
expect(DiscourseChatIntegration::Helper.delete_by_index(chan1, -1)).to eq(false)
|
|
|
|
expect(DiscourseChatIntegration::Helper.delete_by_index(chan1, 0)).to eq(false)
|
|
|
|
expect(DiscourseChatIntegration::Helper.delete_by_index(chan1, 2)).to eq(false)
|
2017-07-06 16:36:50 -04:00
|
|
|
|
2021-07-13 15:36:16 -04:00
|
|
|
expect(DiscourseChatIntegration::Helper.delete_by_index(chan1, 1)).to eq(:deleted)
|
2017-07-06 16:36:50 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
describe ".smart_create_rule" do
|
|
|
|
it "creates a rule when there are none" do
|
|
|
|
val =
|
|
|
|
DiscourseChatIntegration::Helper.smart_create_rule(
|
|
|
|
channel: chan1,
|
|
|
|
filter: "watch",
|
|
|
|
category_id: category.id,
|
|
|
|
tags: [tag1.name],
|
|
|
|
)
|
2017-07-05 20:11:26 -04:00
|
|
|
expect(val).to eq(:created)
|
|
|
|
|
2021-07-13 15:36:16 -04:00
|
|
|
record = DiscourseChatIntegration::Rule.all.first
|
2017-07-13 17:13:03 -04:00
|
|
|
expect(record.channel).to eq(chan1)
|
2022-12-29 07:31:05 -05:00
|
|
|
expect(record.filter).to eq("watch")
|
2017-07-05 20:11:26 -04:00
|
|
|
expect(record.category_id).to eq(category.id)
|
|
|
|
expect(record.tags).to eq([tag1.name])
|
|
|
|
end
|
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
it "updates a rule when it has the same category and tags" do
|
|
|
|
existing =
|
|
|
|
DiscourseChatIntegration::Rule.create!(
|
|
|
|
channel: chan1,
|
|
|
|
filter: "watch",
|
|
|
|
category_id: category.id,
|
|
|
|
tags: [tag2.name, tag1.name],
|
|
|
|
)
|
|
|
|
|
|
|
|
val =
|
|
|
|
DiscourseChatIntegration::Helper.smart_create_rule(
|
|
|
|
channel: chan1,
|
|
|
|
filter: "mute",
|
|
|
|
category_id: category.id,
|
|
|
|
tags: [tag1.name, tag2.name],
|
|
|
|
)
|
2017-07-05 20:11:26 -04:00
|
|
|
|
|
|
|
expect(val).to eq(:updated)
|
|
|
|
|
2021-07-13 15:36:16 -04:00
|
|
|
expect(DiscourseChatIntegration::Rule.all.size).to eq(1)
|
2022-12-29 07:31:05 -05:00
|
|
|
expect(DiscourseChatIntegration::Rule.all.first.filter).to eq("mute")
|
2017-07-05 20:11:26 -04:00
|
|
|
end
|
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
it "updates a rule when it has the same category and filter" do
|
|
|
|
existing =
|
|
|
|
DiscourseChatIntegration::Rule.create(
|
|
|
|
channel: chan1,
|
|
|
|
filter: "watch",
|
|
|
|
category_id: category.id,
|
|
|
|
tags: [tag1.name, tag2.name],
|
|
|
|
)
|
|
|
|
|
|
|
|
val =
|
|
|
|
DiscourseChatIntegration::Helper.smart_create_rule(
|
|
|
|
channel: chan1,
|
|
|
|
filter: "watch",
|
|
|
|
category_id: category.id,
|
|
|
|
tags: [tag1.name, tag3.name],
|
|
|
|
)
|
2017-07-05 20:11:26 -04:00
|
|
|
|
|
|
|
expect(val).to eq(:updated)
|
|
|
|
|
2021-07-13 15:36:16 -04:00
|
|
|
expect(DiscourseChatIntegration::Rule.all.size).to eq(1)
|
2022-12-29 07:31:05 -05:00
|
|
|
expect(DiscourseChatIntegration::Rule.all.first.tags).to contain_exactly(
|
|
|
|
tag1.name,
|
|
|
|
tag2.name,
|
|
|
|
tag3.name,
|
|
|
|
)
|
2017-07-05 20:11:26 -04:00
|
|
|
end
|
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
it "destroys duplicate rules on save" do
|
|
|
|
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: "watch")
|
|
|
|
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: "watch")
|
2021-07-13 15:36:16 -04:00
|
|
|
expect(DiscourseChatIntegration::Rule.all.size).to eq(2)
|
2022-12-29 07:31:05 -05:00
|
|
|
val =
|
|
|
|
DiscourseChatIntegration::Helper.smart_create_rule(
|
|
|
|
channel: chan1,
|
|
|
|
filter: "watch",
|
|
|
|
category_id: nil,
|
|
|
|
tags: nil,
|
|
|
|
)
|
2017-07-05 20:11:26 -04:00
|
|
|
expect(val).to eq(:updated)
|
2021-07-13 15:36:16 -04:00
|
|
|
expect(DiscourseChatIntegration::Rule.all.size).to eq(1)
|
2017-07-05 20:11:26 -04:00
|
|
|
end
|
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
it "returns false on error" do
|
|
|
|
val = DiscourseChatIntegration::Helper.smart_create_rule(channel: chan1, filter: "blah")
|
2017-07-05 20:11:26 -04:00
|
|
|
|
|
|
|
expect(val).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-12-29 07:31:05 -05:00
|
|
|
describe ".save_transcript" do
|
|
|
|
it "saves a transcript to redis" do
|
2021-07-13 15:36:16 -04:00
|
|
|
key = DiscourseChatIntegration::Helper.save_transcript("Some content here")
|
2017-07-24 11:13:53 -04:00
|
|
|
|
2019-12-03 04:45:32 -05:00
|
|
|
expect(Discourse.redis.get("chat_integration:transcript:#{key}")).to eq("Some content here")
|
2017-08-01 15:53:39 -04:00
|
|
|
|
2019-12-03 04:45:32 -05:00
|
|
|
ttl = Discourse.redis.pttl("chat_integration:transcript:#{key}")
|
2017-07-24 12:48:06 -04:00
|
|
|
|
|
|
|
# Slight hack since freeze_time doens't work on redis
|
2019-12-03 04:45:32 -05:00
|
|
|
expect(Discourse.redis.pttl("chat_integration:transcript:#{key}")).to be <= (3601 * 1000)
|
|
|
|
expect(Discourse.redis.pttl("chat_integration:transcript:#{key}")).to be >= (3599 * 1000)
|
2017-07-24 11:13:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-05-30 12:13:55 -04:00
|
|
|
describe ".formatted_display_name" do
|
2022-12-29 07:31:05 -05:00
|
|
|
let(:user) { Fabricate(:user, name: "John Smith", username: "js1") }
|
2022-05-30 12:13:55 -04:00
|
|
|
|
|
|
|
it "prioritizes correctly" do
|
|
|
|
SiteSetting.prioritize_username_in_ux = true
|
2022-12-29 07:31:05 -05:00
|
|
|
expect(DiscourseChatIntegration::Helper.formatted_display_name(user)).to eq(
|
|
|
|
"@#{user.username} (John Smith)",
|
|
|
|
)
|
2022-05-30 12:13:55 -04:00
|
|
|
SiteSetting.prioritize_username_in_ux = false
|
2022-12-29 07:31:05 -05:00
|
|
|
expect(DiscourseChatIntegration::Helper.formatted_display_name(user)).to eq(
|
|
|
|
"John Smith (@#{user.username})",
|
|
|
|
)
|
2022-05-30 12:13:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "only displays one when name/username are similar" do
|
|
|
|
user.update!(username: "john_smith")
|
|
|
|
SiteSetting.prioritize_username_in_ux = true
|
2022-12-29 07:31:05 -05:00
|
|
|
expect(DiscourseChatIntegration::Helper.formatted_display_name(user)).to eq(
|
|
|
|
"@#{user.username}",
|
|
|
|
)
|
2022-05-30 12:13:55 -04:00
|
|
|
SiteSetting.prioritize_username_in_ux = false
|
|
|
|
expect(DiscourseChatIntegration::Helper.formatted_display_name(user)).to eq("John Smith")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "only displays username when names are disabled" do
|
|
|
|
SiteSetting.enable_names = false
|
|
|
|
|
|
|
|
SiteSetting.prioritize_username_in_ux = true
|
2022-12-29 07:31:05 -05:00
|
|
|
expect(DiscourseChatIntegration::Helper.formatted_display_name(user)).to eq(
|
|
|
|
"@#{user.username}",
|
|
|
|
)
|
2022-05-30 12:13:55 -04:00
|
|
|
SiteSetting.prioritize_username_in_ux = false
|
2022-12-29 07:31:05 -05:00
|
|
|
expect(DiscourseChatIntegration::Helper.formatted_display_name(user)).to eq(
|
|
|
|
"@#{user.username}",
|
|
|
|
)
|
2022-05-30 12:13:55 -04:00
|
|
|
end
|
|
|
|
end
|
2017-08-01 15:53:39 -04:00
|
|
|
end
|