This commit is contained in:
43
cart-grain_test.go
Normal file
43
cart-grain_test.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
messages "git.tornberg.me/go-cart-actor/proto"
|
||||
)
|
||||
|
||||
func TestAddToCart(t *testing.T) {
|
||||
grain, err := spawn(ToCartId("kalle"))
|
||||
if err != nil {
|
||||
t.Errorf("Error spawning: %v\n", err)
|
||||
}
|
||||
if len(grain.Items) != 0 {
|
||||
t.Errorf("Expected 0 items, got %d\n", len(grain.Items))
|
||||
}
|
||||
addItem := messages.AddItem{
|
||||
Quantity: 2,
|
||||
Price: 100,
|
||||
Sku: "123",
|
||||
Name: "Test item",
|
||||
Image: "test.jpg",
|
||||
}
|
||||
ts := time.Now().Unix()
|
||||
msg := &Message{
|
||||
TimeStamp: &ts,
|
||||
Type: AddItemType,
|
||||
Content: &addItem,
|
||||
}
|
||||
result, err := grain.HandleMessage(msg, false)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Error handling message: %v\n", err)
|
||||
}
|
||||
if len(result) == 0 {
|
||||
t.Errorf("Expected result, got nil\n")
|
||||
}
|
||||
if grain.TotalPrice != 200 {
|
||||
t.Errorf("Expected total price 200, got %d\n", grain.TotalPrice)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user