|
| 1 | +require "spec_helper" |
| 2 | + |
| 3 | +describe Gitlab::ReplyByEmail do |
| 4 | + describe "self.enabled?" do |
| 5 | + context "when reply by email is enabled" do |
| 6 | + before do |
| 7 | + allow(Gitlab.config.reply_by_email).to receive(:enabled).and_return(true) |
| 8 | + end |
| 9 | + |
| 10 | + context "when the address is valid" do |
| 11 | + before do |
| 12 | + allow(Gitlab.config.reply_by_email).to receive(:address).and_return("replies+%{reply_key}@example.com") |
| 13 | + end |
| 14 | + |
| 15 | + it "returns true" do |
| 16 | + expect(described_class.enabled?).to be_truthy |
| 17 | + end |
| 18 | + end |
| 19 | + |
| 20 | + context "when the address is invalid" do |
| 21 | + before do |
| 22 | + allow(Gitlab.config.reply_by_email).to receive(:address).and_return("[email protected]") |
| 23 | + end |
| 24 | + |
| 25 | + it "returns false" do |
| 26 | + expect(described_class.enabled?).to be_falsey |
| 27 | + end |
| 28 | + end |
| 29 | + end |
| 30 | + |
| 31 | + context "when reply by email is disabled" do |
| 32 | + before do |
| 33 | + allow(Gitlab.config.reply_by_email).to receive(:enabled).and_return(false) |
| 34 | + end |
| 35 | + |
| 36 | + it "returns false" do |
| 37 | + expect(described_class.enabled?).to be_falsey |
| 38 | + end |
| 39 | + end |
| 40 | + end |
| 41 | + |
| 42 | + describe "self.reply_key" do |
| 43 | + context "when enabled" do |
| 44 | + before do |
| 45 | + allow(described_class).to receive(:enabled?).and_return(true) |
| 46 | + end |
| 47 | + |
| 48 | + it "returns a random hex" do |
| 49 | + key = described_class.reply_key |
| 50 | + key2 = described_class.reply_key |
| 51 | + |
| 52 | + expect(key).not_to eq(key2) |
| 53 | + end |
| 54 | + end |
| 55 | + |
| 56 | + context "when disabled" do |
| 57 | + before do |
| 58 | + allow(described_class).to receive(:enabled?).and_return(false) |
| 59 | + end |
| 60 | + |
| 61 | + it "returns nil" do |
| 62 | + expect(described_class.reply_key).to be_nil |
| 63 | + end |
| 64 | + end |
| 65 | + end |
| 66 | + |
| 67 | + context "self.reply_address" do |
| 68 | + before do |
| 69 | + allow(Gitlab.config.reply_by_email).to receive(:address).and_return("replies+%{reply_key}@example.com") |
| 70 | + end |
| 71 | + |
| 72 | + it "returns the address with an interpolated reply key" do |
| 73 | + expect(described_class.reply_address("key")).to eq("[email protected]") |
| 74 | + end |
| 75 | + end |
| 76 | + |
| 77 | + context "self.reply_key_from_address" do |
| 78 | + before do |
| 79 | + allow(Gitlab.config.reply_by_email).to receive(:address).and_return("replies+%{reply_key}@example.com") |
| 80 | + end |
| 81 | + |
| 82 | + it "returns reply key" do |
| 83 | + expect(described_class.reply_key_from_address("[email protected]")).to eq("key") |
| 84 | + end |
| 85 | + end |
| 86 | +end |
0 commit comments