Created
May 24, 2020 11:35
-
-
Save KamilLelonek/5b82ab33c4d10158ca3a645ee2d8565b to your computer and use it in GitHub Desktop.
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
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