Skip to content

Instantly share code, notes, and snippets.


shankardevy/sales_test.exs Secret

Created Jul 8, 2017
What would you like to do?
defmodule Mango.SalesTest do
use Mango.DataCase
alias Mango.Sales
alias Mango.Sales.Order
alias Mango.Catalog.Product
test "create_cart" do
assert %Order{status: "In Cart"} = Sales.create_cart
test "get_cart/1" do
cart1 = Sales.create_cart
cart2 = Sales.get_cart(
assert ==
test "add_to_cart/2" do
product = %Product{
name: "Tomato",
pack_size: "1 kg",
price: 55,
sku: "A123",
is_seasonal: false, category: "vegetables" } |> Repo.insert!
cart = Sales.create_cart
{:ok, cart} = Sales.add_to_cart(cart, %{"product_id" =>, "quantity" => "2"})
assert [line_item] = cart.line_items
assert line_item.product_id ==
assert line_item.product_name == "Tomato"
assert line_item.pack_size == "1 kg"
assert line_item.quantity == 2
assert line_item.unit_price ==
assert == Decimal.mult(,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment