Skip to content

Instantly share code, notes, and snippets.

@KamilLelonek
Created May 24, 2020 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KamilLelonek/1bf18d70e5a39cfc6f4ed700403326c0 to your computer and use it in GitHub Desktop.
Save KamilLelonek/1bf18d70e5a39cfc6f4ed700403326c0 to your computer and use it in GitHub Desktop.
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