-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add author alias to blost post (#550)
- Loading branch information
Showing
5 changed files
with
142 additions
and
5 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
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
9 changes: 9 additions & 0 deletions
9
priv/repo/migrations/20241229013049_add_microblog_poster_alias.exs
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,9 @@ | ||
defmodule Teiserver.Repo.Migrations.AddMicroblogPosterAlias do | ||
use Ecto.Migration | ||
|
||
def change do | ||
alter table("microblog_posts") do | ||
add :poster_alias, :string | ||
end | ||
end | ||
end |
105 changes: 105 additions & 0 deletions
105
test/teiserver_web/live/microblog/post_form_component_test.exs
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,105 @@ | ||
defmodule TeiserverWeb.Microblog.PostFormComponentTest do | ||
@moduledoc false | ||
use TeiserverWeb.ConnCase | ||
|
||
alias TeiserverWeb.Microblog.PostFormComponent | ||
alias Teiserver.Microblog | ||
|
||
test "create_post works with or without poster_alias" do | ||
post_params = %{ | ||
"contents" => "test", | ||
"discord_channel_id" => "", | ||
"poster_alias" => "", | ||
"poster_id" => 4, | ||
"summary" => "test", | ||
"title" => "test" | ||
} | ||
|
||
{:ok, result} = Microblog.create_post(post_params) | ||
assert result.poster_alias == nil | ||
|
||
post_params = %{ | ||
"contents" => "test", | ||
"discord_channel_id" => "", | ||
"poster_alias" => "Jenny", | ||
"poster_id" => 4, | ||
"summary" => "test", | ||
"title" => "test" | ||
} | ||
|
||
{:ok, result} = Microblog.create_post(post_params) | ||
assert result.poster_alias == "Jenny" | ||
end | ||
|
||
test "Get discord text when discord id present" do | ||
post_params = %{ | ||
"contents" => "test", | ||
"discord_channel_id" => "", | ||
"poster_alias" => "contributor alias", | ||
"poster_id" => 4, | ||
"summary" => "test", | ||
"title" => "test" | ||
} | ||
|
||
{:ok, post} = Microblog.create_post(post_params) | ||
|
||
user = %{ | ||
discord_id: "mydiscordname", | ||
name: "ign" | ||
} | ||
|
||
host = "localhost" | ||
|
||
result = PostFormComponent.create_discord_text(user, post, host) | ||
|
||
assert String.contains?(result, "Posted by <@mydiscordname>") | ||
end | ||
|
||
test "Get discord text when discord id not present and alias is present" do | ||
post_params = %{ | ||
"contents" => "test", | ||
"discord_channel_id" => "", | ||
"poster_alias" => "contributoralias", | ||
"poster_id" => 4, | ||
"summary" => "test", | ||
"title" => "test" | ||
} | ||
|
||
{:ok, post} = Microblog.create_post(post_params) | ||
|
||
user = %{ | ||
discord_id: nil, | ||
name: "ign" | ||
} | ||
|
||
host = "localhost" | ||
|
||
result = PostFormComponent.create_discord_text(user, post, host) | ||
|
||
assert String.contains?(result, "Posted by contributoralias") | ||
end | ||
|
||
test "Get discord text when discord id not present and alias not present" do | ||
post_params = %{ | ||
"contents" => "test", | ||
"discord_channel_id" => "", | ||
"poster_alias" => "", | ||
"poster_id" => 4, | ||
"summary" => "test", | ||
"title" => "test" | ||
} | ||
|
||
{:ok, post} = Microblog.create_post(post_params) | ||
|
||
user = %{ | ||
discord_id: nil, | ||
name: "ingame_name" | ||
} | ||
|
||
host = "localhost" | ||
|
||
result = PostFormComponent.create_discord_text(user, post, host) | ||
|
||
assert String.contains?(result, "Posted by ingame_name") | ||
end | ||
end |