Skip to content

Instantly share code, notes, and snippets.

@KamilLelonek
Created May 24, 2020 11:35
Show Gist options
  • Save KamilLelonek/5b82ab33c4d10158ca3a645ee2d8565b to your computer and use it in GitHub Desktop.
Save KamilLelonek/5b82ab33c4d10158ca3a645ee2d8565b to your computer and use it in GitHub Desktop.
defmodule PipelinexTest do
use ExUnit.Case, async: true
alias Pipelinex.{Video, Rating}
describe "serialize" do
@rating1 %Rating{author: "James Bond", comment: "Quite nice."}
@rating2 %Rating{author: "Sherlock Holmes", comment: "Pretty good."}
@ratings [@rating1, @rating2]
@video %Video{title: "Iron Man 3", ratings: @ratings}
test "should encode nested arguments" do
result =
@video
|> Video.encode()
|> case do
%{"ratings" => ratings} = video ->
%{video | "ratings" => Enum.map(ratings, &Rating.encode/1)}
end
|> Map.values()
|> List.flatten()
assert [
%{"author" => "James Bond", "comment" => "Quite nice."},
%{"author" => "Sherlock Holmes", "comment" => "Pretty good."},
"Iron Man 3"
] = result
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment