Created
May 24, 2020 11:48
-
-
Save KamilLelonek/1bf18d70e5a39cfc6f4ed700403326c0 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 | |
use Pipelinex | |
require Pipelinex | |
@text "Some random STRING." | |
describe "~>" do | |
test "should behave the same as the regular pipe operator" do | |
assert @text | |
|> String.downcase() | |
|> String.split() == | |
@text | |
~> String.downcase() | |
~> String.split() | |
end | |
test "should handle error results" do | |
assert {:error, "invalid API key"} == "API KEY" ~> download() ~> parse() | |
end | |
test "should pass successful flow" do | |
assert %{downloaded_at: _timestamp, message: "valid result"} = 123 ~> download() ~> parse() | |
end | |
defp download(123), do: {:ok, "valid result"} | |
defp download(_), do: {:error, "invalid API key"} | |
defp parse({:ok, message}), do: %{message: message, downloaded_at: Time.utc_now()} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment