Skip to content

Instantly share code, notes, and snippets.

@shankardevy
Last active July 8, 2017 06:20
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 shankardevy/f0127229cb2ba2624ab51b62cf7caca5 to your computer and use it in GitHub Desktop.
Save shankardevy/f0127229cb2ba2624ab51b62cf7caca5 to your computer and use it in GitHub Desktop.
defmodule Mango.CRMTest do
use Mango.DataCase
alias Mango.CRM
alias Mango.CRM.Customer
test "build_customer/0 returns a customer changeset" do
assert %Ecto.Changeset{data: %Customer{}} = CRM.build_customer
end
test "build_customer/1 returns a customer changeset with values applied" do
attrs = %{"name" => "John"}
changeset = CRM.build_customer(attrs)
assert changeset.params == attrs
end
# >>> Add these two tests from here.
test "create_customer/1 returns a customer for valid data" do
valid_attrs = %{
"name" => "John",
"email" => "john@example.com",
"password" => "secret",
"residence_area" => "Area 1",
"phone" => "1111"
}
assert {:ok, customer} = CRM.create_customer(valid_attrs)
assert Comeonin.Bcrypt.checkpw(valid_attrs["password"], customer.password_hash)
end
test "create_customer/1 returns a changeset for invalid data" do
invalid_attrs = %{}
assert {:error, %Ecto.Changeset{}} = CRM.create_customer(invalid_attrs)
end
# <<< Upto here.
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment