Skip to content

Commit 6cadede

Browse files
committed
WIP
1 parent 5ee03e9 commit 6cadede

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

config/examples/test.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This is an example Postal configuration file for use in
1+
# This is an example Postal configuration file for use in
22
# test environments. For a production example, see
33
# the https://github.com/postalserver/install repository.
44

@@ -7,14 +7,14 @@ version: 2
77
main_db:
88
host: 127.0.0.1
99
username: root
10-
password:
10+
password:
1111
database: postal-test
1212

1313
message_db:
1414
host: 127.0.0.1
1515
username: root
16-
password:
17-
prefix: postal-test
16+
password:
17+
prefix: postal
1818

1919
logging:
2020
enabled: false

spec/helpers/general_helpers.rb

+9
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,13 @@ def create_plain_text_message(server, text, to = "[email protected]", override_at
1212
server.message_db.message(result[:id])
1313
end
1414

15+
def create_html_message(server, html, to = "[email protected]", override_attributes = {})
16+
domain = create(:domain, owner: server)
17+
attributes = { from: "test@#{domain.name}", subject: "Test HTML Message" }.merge(override_attributes)
18+
attributes[:to] = to
19+
attributes[:html_body] = html
20+
message = OutgoingMessagePrototype.new(server, "127.0.0.1", "testsuite", attributes)
21+
result = message.create_message(to)
22+
server.message_db.message(result[:id])
23+
end
1524
end

spec/lib/postal/message_parser_spec.rb

+27
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,31 @@
2222
expect(parser.new_body).to match(/^Hello world! https:\/\/click\.#{message.domain.name}/)
2323
expect(parser.tracked_links).to eq 1
2424
end
25+
26+
it "should not replace links in messages if the header is set to no" do
27+
message = create_plain_text_message(server, "Hello world! http://github.com/atech/postal", "[email protected]", { custom_headers: { "x-track-clicks" => "no" } })
28+
create(:track_domain, server: server, domain: message.domain)
29+
parser = Postal::MessageParser.new(message)
30+
expect(parser.actioned?).to be false
31+
expect(parser.new_body).to include("Hello world! http://github.com/atech/postal")
32+
expect(parser.tracked_links).to eq 0
33+
end
34+
35+
it "should insert tracking pixels in messages" do
36+
message = create_html_message(server, "<p>Hello world! <a href='http://github.com/atech/postal'>Github</a></p>", "[email protected]")
37+
create(:track_domain, server: server, domain: message.domain)
38+
parser = Postal::MessageParser.new(message)
39+
expect(parser.actioned?).to be true
40+
expect(parser.new_body).to match(/<p class='ampimg' style='display:none;visibility:none;margin:0;padding:0;line-height:0;'><img src='https:\/\/click\.#{message.domain.name}/)
41+
expect(parser.tracked_images).to eq 1
42+
end
43+
44+
it "should not insert tracking pixels in messages if the header is set to no" do
45+
message = create_html_message(server, "<p>Hello world! <a href='http://github.com/atech/postal'>Github</a></p>", "[email protected]", { custom_headers: { "x-track-opens" => "no" } })
46+
create(:track_domain, server: server, domain: message.domain)
47+
parser = Postal::MessageParser.new(message)
48+
expect(parser.actioned?).to be true
49+
expect(parser.new_body).to_not include("<p class='ampimg' style='display:none;visibility:none;margin:0;padding:0;line-height:0;'><img src='https:\/\/click\.#{message.domain.name}")
50+
expect(parser.tracked_images).to eq 0
51+
end
2552
end

0 commit comments

Comments
 (0)