forked from thechangelog/changelog.com
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace names with mastodon handles when episode hosts/guests have them
- Loading branch information
1 parent
1080928
commit abba958
Showing
2 changed files
with
91 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
defmodule Changelog.Social.SocialTest do | ||
use Changelog.SchemaCase | ||
|
||
import Mock | ||
|
||
alias Changelog.Social | ||
|
||
describe "post/1" do | ||
test "creates a status with applicable data" do | ||
podcast = insert(:podcast, mastodon_token: "12345") | ||
episode = insert(:published_episode, podcast: podcast) | ||
|
||
with_mock(Social.Client, create_status: fn _, _ -> {:ok, %{body: %{"url" => "https://test.com"}}} end) do | ||
Social.post(episode) | ||
|
||
assert called(Social.Client.create_status("12345", :_)) | ||
assert Repo.get(Changelog.Episode, episode.id).socialize_url == "https://test.com" | ||
end | ||
end | ||
end | ||
|
||
describe "description/1" do | ||
test "replaces nothing when no hosts or guests" do | ||
episode = insert(:episode, summary: "Jerod interviews Uncle Buck & Buck Cherry about some cool stuff") | ||
|
||
assert Social.description(episode) == episode.summary | ||
end | ||
|
||
test "replaces referenced names with mastodon handles" do | ||
host1 = insert(:person, name: "Jerod Santo", mastodon_handle: "[email protected]") | ||
host2 = insert(:person, name: "Adam Stac", mastodon_handle: nil) | ||
host3 = insert(:person, name: "Gerhard Lazu", mastodon_handle: "[email protected]") | ||
guest1 = insert(:person, name: "Uncle Buck", mastodon_handle: "") | ||
guest2 = insert(:person, name: "Buck Cherry", mastodon_handle: "[email protected]") | ||
|
||
episode = insert(:episode, summary: "Jerod, Gerhard Lazu & Adam Stac interviews Uncle Buck & Buck Cherry about some cool stuff") | ||
|
||
insert(:episode_host, episode: episode, person: host1) | ||
insert(:episode_host, episode: episode, person: host2) | ||
insert(:episode_host, episode: episode, person: host3) | ||
insert(:episode_guest, episode: episode, person: guest1) | ||
insert(:episode_guest, episode: episode, person: guest2) | ||
|
||
expected = "@[email protected], @[email protected] & Adam Stac interviews Uncle Buck & @[email protected] about some cool stuff" | ||
|
||
assert Social.description(episode) == expected | ||
end | ||
end | ||
end |