Created
August 30, 2021 06:41
-
-
Save percybolmer/304ea8b726736c69d3edc984503de27e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package services | |
import ( | |
"testing" | |
"github.com/google/uuid" | |
"github.com/percybolmer/ddd-go/aggregate" | |
) | |
func init_products(t *testing.T) []aggregate.Product { | |
beer, err := aggregate.NewProduct("Beer", "Healthy Beverage", 1.99) | |
if err != nil { | |
t.Error(err) | |
} | |
peenuts, err := aggregate.NewProduct("Peenuts", "Healthy Snacks", 0.99) | |
if err != nil { | |
t.Error(err) | |
} | |
wine, err := aggregate.NewProduct("Wine", "Healthy Snacks", 0.99) | |
if err != nil { | |
t.Error(err) | |
} | |
products := []aggregate.Product{ | |
beer, peenuts, wine, | |
} | |
return products | |
} | |
func TestOrder_NewOrderService(t *testing.T) { | |
// Create a few products to insert into in memory repo | |
products := init_products(t) | |
os, err := NewOrderService( | |
WithMemoryCustomerRepository(), | |
WithMemoryProductRepository(products), | |
) | |
if err != nil { | |
t.Error(err) | |
} | |
// Add Customer | |
cust, err := aggregate.NewCustomer("Percy") | |
if err != nil { | |
t.Error(err) | |
} | |
err = os.customers.Add(cust) | |
if err != nil { | |
t.Error(err) | |
} | |
// Perform Order for one beer | |
order := []uuid.UUID{ | |
products[0].GetID(), | |
} | |
_, err = os.CreateOrder(cust.GetID(), order) | |
if err != nil { | |
t.Error(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment