File: format_attachments_spec.rb

package info (click to toggle)
ruby-slack-messenger 2.3.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 208 kB
  • sloc: ruby: 1,156; makefile: 7
file content (48 lines) | stat: -rw-r--r-- 1,662 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# frozen_string_literal: true

RSpec.describe Slack::Messenger::PayloadMiddleware::FormatAttachments do
  it "passes the text of attachments through linkformatter with options[:formats]" do
    subject = described_class.new(:messenger, formats: [:html])
    expect(Slack::Messenger::Util::LinkFormatter).to receive(:format)
      .with("hello", formats: [:html])
    subject.call(attachments: [{ text: "hello" }])
  end

  it "searches through string or symbol keys" do
    subject = described_class.new(:messenger)
    expect(Slack::Messenger::Util::LinkFormatter).to receive(:format)
      .with("hello", formats: %i[html markdown])
    subject.call("attachments" => [{ "text" => "hello" }])

    subject = described_class.new(:messenger)
    expect(Slack::Messenger::Util::LinkFormatter).to receive(:format)
      .with("hello", formats: %i[html markdown])
    subject.call(attachments: [{ text: "hello" }])
  end

  it "can handle a single attachment" do
    subject = described_class.new(:messenger)
    expect(Slack::Messenger::Util::LinkFormatter).to receive(:format)
      .with("hello", formats: %i[html markdown])
    subject.call(attachments: { text: "hello" })
  end

  it "wraps attachment into array if given as a single hash" do
    params = {
      attachments: { text: "hello" }
    }
    payload = {
      attachments: [{ text: "hello" }]
    }
    subject = described_class.new(:messenger)

    expect(subject.call(params)).to eq payload
  end

  it "returns the payload unmodified if not :attachments key" do
    payload = { foo: :bar }
    subject = described_class.new(:messenger)

    expect(subject.call(payload)).to eq payload
  end
end