Skip to content

Instantly share code, notes, and snippets.

@shankardevy

shankardevy/crm_test.exs Secret

Last active Jul 8, 2017
Embed
What would you like to do?
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