Skip to content

Commit

Permalink
test: Update translate.ex cases
Browse files Browse the repository at this point in the history
  • Loading branch information
kiosion committed Jul 19, 2024
1 parent 1de3bbd commit 86efddf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
6 changes: 2 additions & 4 deletions elixir-api/test/api/post_posts_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,10 @@ defmodule PostPostsTest do
total: length(stub_posts["result"])
)

stub_posts_translatable_calls = length(stub_posts["result"])

Hexerei.HTTP.MockClient
|> Mox.expect(
:get,
2,
length(stub_posts["result"]),
fn url, _headers ->
if String.contains?(url, "count") and String.contains?(url, "total") do
{:ok,
Expand All @@ -244,7 +242,7 @@ defmodule PostPostsTest do
)
|> Mox.expect(
:post,
stub_posts_translatable_calls,
3, # title, desc, and body
fn url, body, _params ->
assert String.contains?(url, "https://translation.googleapis.com/")

Expand Down
18 changes: 6 additions & 12 deletions elixir-api/test/translate_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ defmodule TranslateTest do
stub_post = TestFixtures.stub_post()
stub_posts = TestFixtures.stub_posts()
stub_invalid = %{"someKey" => "someValue"}
stub_translated_text = "someTranslatedText"

Hexerei.HTTP.MockClient
|> Mox.stub(
Expand All @@ -71,7 +72,7 @@ defmodule TranslateTest do
data: %{
translations: [
%{
translatedText: "someTranslatedText"
translatedText: stub_translated_text
}
]
}
Expand Down Expand Up @@ -108,31 +109,24 @@ defmodule TranslateTest do
|> List.first()
|> Map.get("children")
|> List.first()
|> Map.get("text") == "someTranslatedText"
|> Map.get("text") == stub_translated_text

assert is_map(translated_post)

assert translated_post["result"]["body"]
|> List.first()
|> Map.get("children")
|> List.first()
|> Map.get("text") == "someTranslatedText"
|> Map.get("text") == stub_translated_text

assert is_map(translated_posts)
# Posts should not have their body translated
# Posts should have their body translated
assert translated_posts["result"]
|> List.first()
|> Map.get("body")
|> List.first()
|> Map.get("children")
|> List.first()
|> Map.get("text") ==
stub_posts["result"]
|> List.first()
|> Map.get("body")
|> List.first()
|> Map.get("children")
|> List.first()
|> Map.get("text")
|> Map.get("text") == stub_translated_text
end
end

0 comments on commit 86efddf

Please sign in to comment.