add stuff
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m52s

This commit is contained in:
matst80
2024-11-10 22:46:52 +01:00
parent e8643b5899
commit bc6c3ee692
3 changed files with 47 additions and 1 deletions

43
cart-grain_test.go Normal file
View 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)
}
}