mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: IMAP archive fix and group list mailbox code unification (#10355)
* Fixed an issue I introduced in the last PR where I am just archiving everything regardless of whether it is actually archived in Discourse man_facepalming * Refactor group list_mailboxes IMAP code to use providers, add specs, and add provider code to get the correct prodivder
This commit is contained in:
27
spec/lib/imap/providers/detector_spec.rb
Normal file
27
spec/lib/imap/providers/detector_spec.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Imap::Providers::Detector do
|
||||
it "returns the gmail provider if the gmail imap server is used" do
|
||||
config = {
|
||||
server: "imap.gmail.com",
|
||||
port: 993,
|
||||
ssl: true,
|
||||
username: "test@gmail.com",
|
||||
password: "testpassword1"
|
||||
}
|
||||
expect(described_class.init_with_detected_provider(config)).to be_a(Imap::Providers::Gmail)
|
||||
end
|
||||
|
||||
it "returns the generic provider if we don't have a special provider defined" do
|
||||
config = {
|
||||
server: "imap.yo.com",
|
||||
port: 993,
|
||||
ssl: true,
|
||||
username: "test@yo.com",
|
||||
password: "testpassword1"
|
||||
}
|
||||
expect(described_class.init_with_detected_provider(config)).to be_a(Imap::Providers::Generic)
|
||||
end
|
||||
end
|
||||
73
spec/lib/imap/providers/gmail_spec.rb
Normal file
73
spec/lib/imap/providers/gmail_spec.rb
Normal file
@@ -0,0 +1,73 @@
|
||||
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Imap::Providers::Gmail do
|
||||
fab!(:username) { "test@generic.com" }
|
||||
fab!(:password) { "test1!" }
|
||||
fab!(:provider) do
|
||||
described_class.new(
|
||||
"imap.generic.com",
|
||||
{
|
||||
port: 993,
|
||||
ssl: true,
|
||||
username: username,
|
||||
password: password
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
let(:imap_stub) { stub }
|
||||
let(:x_gm_thrid) { Imap::Providers::Gmail::X_GM_THRID }
|
||||
let(:x_gm_labels) { Imap::Providers::Gmail::X_GM_LABELS }
|
||||
before do
|
||||
described_class.any_instance.stubs(:imap).returns(imap_stub)
|
||||
end
|
||||
|
||||
describe "#store" do
|
||||
it "converts LABELS store to special X-GM-LABELS" do
|
||||
Imap::Providers::Generic.any_instance.expects(:store).with(
|
||||
63, x_gm_labels, ["\\Inbox"], ["\\Inbox", "test"]
|
||||
)
|
||||
provider.store(63, "LABELS", ["\\Inbox"], ["\\Inbox", "test"])
|
||||
end
|
||||
end
|
||||
|
||||
describe "#tag_to_label" do
|
||||
it "converts important to special gmail label \\Important" do
|
||||
expect(provider.tag_to_label("important")).to eq("\\Important")
|
||||
end
|
||||
|
||||
it "converts starred to special gmail label \\Starred" do
|
||||
expect(provider.tag_to_label("starred")).to eq("\\Starred")
|
||||
end
|
||||
end
|
||||
|
||||
describe "#archive" do
|
||||
it "gets the thread ID for the UID, and removes the Inbox label from all UIDs in the thread" do
|
||||
main_uid = 78
|
||||
fake_thrid = '4398634986239754'
|
||||
imap_stub.expects(:uid_fetch).with(main_uid, [x_gm_thrid]).returns(
|
||||
[stub(attr: { x_gm_thrid => fake_thrid })]
|
||||
)
|
||||
imap_stub.expects(:uid_search).with("#{x_gm_thrid} #{fake_thrid}").returns([79, 80])
|
||||
provider.expects(:emails).with([79, 80], ["UID", "LABELS"]).returns(
|
||||
[
|
||||
{
|
||||
"UID" => 79,
|
||||
"LABELS" => ["\\Inbox", "seen"]
|
||||
},
|
||||
{
|
||||
"UID" => 80,
|
||||
"LABELS" => ["\\Inbox", "seen"]
|
||||
}
|
||||
]
|
||||
)
|
||||
provider.expects(:store).with(79, "LABELS", ["\\Inbox", "seen"], ["seen"])
|
||||
provider.expects(:store).with(80, "LABELS", ["\\Inbox", "seen"], ["seen"])
|
||||
|
||||
provider.archive(main_uid)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user