defmodule TwittertexTest do
use ExUnit.Case
doctest Twittertex
defp tweet_json(name) do
contents = File.read!(Path.join(["test", "tweets", "#{name}.json"]))
Jason.decode!(contents)
end
test "URLs and hashtags" do
json = tweet_json("display_guidelines")
assert Twittertex.format_tweet(json) ==
"Along with our new #Twitterbird, we've also updated our Display Guidelines: dev.twitter.com/terms/display-… ^JC"
end
test "photo and hashtags" do
json = tweet_json("piglets")
assert Twittertex.format_tweet(json) ==
"Just piggin lovely.
#smithillsfarm #kunekune #piglets #cuddling pic.twitter.com/mPMZlracLP"
end
test "mentions" do
json = tweet_json("kanye")
assert Twittertex.format_tweet(json) ==
"Hi @jack Dorsey, can you guys please take down all the fake Kanye accounts."
end
test "extended" do
json = tweet_json("extended")
assert Twittertex.format_tweet(json) ==
"@twitter @TwitterDev has more details about these changes at blog.twitter.com/2016/doing-mor…. Thanks for making @twitter more expressive! pic.twitter.com/AWmiH870F7"
end
test "URLs and hashtags with provided link_opts" do
json = tweet_json("display_guidelines")
opts = [link_opts: [target: "_blank", class: "foo"]]
assert Twittertex.format_tweet(json, opts) ==
"Along with our new #Twitterbird, we've also updated our Display Guidelines: dev.twitter.com/terms/display-… ^JC"
end
end