update
This commit is contained in:
@@ -85,6 +85,34 @@ func msgOrderCreated(orderId, status string) *messages.OrderCreated {
|
||||
return &messages.OrderCreated{OrderId: orderId, Status: status}
|
||||
}
|
||||
|
||||
func msgSetUserId(userId string) *messages.SetUserId {
|
||||
return &messages.SetUserId{UserId: userId}
|
||||
}
|
||||
|
||||
func msgLineItemMarking(id uint32, typ uint32, marking string) *messages.LineItemMarking {
|
||||
return &messages.LineItemMarking{Id: id, Type: typ, Marking: marking}
|
||||
}
|
||||
|
||||
func msgRemoveLineItemMarking(id uint32) *messages.RemoveLineItemMarking {
|
||||
return &messages.RemoveLineItemMarking{Id: id}
|
||||
}
|
||||
|
||||
func msgSubscriptionAdded(itemId uint32, detailsId, orderRef string) *messages.SubscriptionAdded {
|
||||
return &messages.SubscriptionAdded{ItemId: itemId, DetailsId: detailsId, OrderReference: orderRef}
|
||||
}
|
||||
|
||||
func msgPaymentDeclined() *messages.PaymentDeclined {
|
||||
return &messages.PaymentDeclined{}
|
||||
}
|
||||
|
||||
func msgConfirmationViewed() *messages.ConfirmationViewed {
|
||||
return &messages.ConfirmationViewed{}
|
||||
}
|
||||
|
||||
func msgCreateCheckoutOrder(terms, country string) *messages.CreateCheckoutOrder {
|
||||
return &messages.CreateCheckoutOrder{Terms: terms, Country: country}
|
||||
}
|
||||
|
||||
func ptr[T any](v T) *T { return &v }
|
||||
|
||||
// ----------------------
|
||||
@@ -144,6 +172,15 @@ func TestMutationRegistryCoverage(t *testing.T) {
|
||||
"AddVoucher",
|
||||
"RemoveVoucher",
|
||||
"UpsertSubscriptionDetails",
|
||||
"InventoryReserved",
|
||||
"PreConditionFailed",
|
||||
"SetUserId",
|
||||
"LineItemMarking",
|
||||
"RemoveLineItemMarking",
|
||||
"SubscriptionAdded",
|
||||
"PaymentDeclined",
|
||||
"ConfirmationViewed",
|
||||
"CreateCheckoutOrder",
|
||||
}
|
||||
|
||||
names := reg.(*actor.ProtoMutationRegistry).RegisteredMutations()
|
||||
@@ -542,3 +579,134 @@ func TestSubscriptionDetailsJSONValidation(t *testing.T) {
|
||||
t.Fatalf("empty update should not change meta, got %s", string(g.SubscriptionDetails[id].Meta))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetUserId(t *testing.T) {
|
||||
reg := newRegistry()
|
||||
g := newTestGrain()
|
||||
|
||||
applyOK(t, reg, g, msgSetUserId("user123"))
|
||||
if g.userId != "user123" {
|
||||
t.Fatalf("expected userId=user123, got %s", g.userId)
|
||||
}
|
||||
|
||||
applyErrorContains(t, reg, g, msgSetUserId(""), "cannot be empty")
|
||||
}
|
||||
|
||||
func TestLineItemMarking(t *testing.T) {
|
||||
reg := newRegistry()
|
||||
g := newTestGrain()
|
||||
|
||||
applyOK(t, reg, g, msgAddItem("MARK", 1000, 1, nil))
|
||||
id := g.Items[0].Id
|
||||
|
||||
applyOK(t, reg, g, msgLineItemMarking(id, 1, "Gift message"))
|
||||
if g.Items[0].Marking == nil || g.Items[0].Marking.Type != 1 || g.Items[0].Marking.Text != "Gift message" {
|
||||
t.Fatalf("marking not set correctly: %+v", g.Items[0].Marking)
|
||||
}
|
||||
|
||||
applyErrorContains(t, reg, g, msgLineItemMarking(9999, 2, "Test"), "not found")
|
||||
}
|
||||
|
||||
func TestRemoveLineItemMarking(t *testing.T) {
|
||||
reg := newRegistry()
|
||||
g := newTestGrain()
|
||||
|
||||
applyOK(t, reg, g, msgAddItem("REMOVE", 1000, 1, nil))
|
||||
id := g.Items[0].Id
|
||||
|
||||
// First set a marking
|
||||
applyOK(t, reg, g, msgLineItemMarking(id, 1, "Test marking"))
|
||||
if g.Items[0].Marking == nil || g.Items[0].Marking.Text != "Test marking" {
|
||||
t.Fatalf("marking not set")
|
||||
}
|
||||
|
||||
// Now remove it
|
||||
applyOK(t, reg, g, msgRemoveLineItemMarking(id))
|
||||
if g.Items[0].Marking != nil {
|
||||
t.Fatalf("marking not removed")
|
||||
}
|
||||
|
||||
applyErrorContains(t, reg, g, msgRemoveLineItemMarking(9999), "not found")
|
||||
}
|
||||
|
||||
func TestSubscriptionAdded(t *testing.T) {
|
||||
reg := newRegistry()
|
||||
g := newTestGrain()
|
||||
|
||||
applyOK(t, reg, g, msgAddItem("SUB", 1000, 1, nil))
|
||||
id := g.Items[0].Id
|
||||
|
||||
applyOK(t, reg, g, msgSubscriptionAdded(id, "det123", "ord456"))
|
||||
if g.Items[0].SubscriptionDetailsId != "det123" || g.Items[0].OrderReference != "ord456" || !g.Items[0].IsSubscribed {
|
||||
t.Fatalf("subscription not added: detailsId=%s orderRef=%s isSubscribed=%v",
|
||||
g.Items[0].SubscriptionDetailsId, g.Items[0].OrderReference, g.Items[0].IsSubscribed)
|
||||
}
|
||||
|
||||
applyErrorContains(t, reg, g, msgSubscriptionAdded(9999, "", ""), "not found")
|
||||
}
|
||||
|
||||
func TestPaymentDeclined(t *testing.T) {
|
||||
reg := newRegistry()
|
||||
g := newTestGrain()
|
||||
|
||||
g.CheckoutOrderId = "test-order"
|
||||
applyOK(t, reg, g, msgPaymentDeclined())
|
||||
if g.PaymentStatus != "declined" || g.CheckoutOrderId != "" {
|
||||
t.Fatalf("payment declined not handled: status=%s checkoutId=%s", g.PaymentStatus, g.CheckoutOrderId)
|
||||
}
|
||||
if g.PaymentDeclinedAt.IsZero() {
|
||||
t.Fatalf("PaymentDeclinedAt not set")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfirmationViewed(t *testing.T) {
|
||||
reg := newRegistry()
|
||||
g := newTestGrain()
|
||||
|
||||
// Initial state
|
||||
if g.ConfirmationViewCount != 0 {
|
||||
t.Fatalf("initial view count should be 0, got %d", g.ConfirmationViewCount)
|
||||
}
|
||||
if !g.ConfirmationLastViewedAt.IsZero() {
|
||||
t.Fatalf("initial last viewed should be zero")
|
||||
}
|
||||
|
||||
// First view
|
||||
applyOK(t, reg, g, msgConfirmationViewed())
|
||||
if g.ConfirmationViewCount != 1 {
|
||||
t.Fatalf("view count should be 1, got %d", g.ConfirmationViewCount)
|
||||
}
|
||||
if g.ConfirmationLastViewedAt.IsZero() {
|
||||
t.Fatalf("ConfirmationLastViewedAt not set")
|
||||
}
|
||||
firstTime := g.ConfirmationLastViewedAt
|
||||
|
||||
// Second view
|
||||
applyOK(t, reg, g, msgConfirmationViewed())
|
||||
if g.ConfirmationViewCount != 2 {
|
||||
t.Fatalf("view count should be 2, got %d", g.ConfirmationViewCount)
|
||||
}
|
||||
if g.ConfirmationLastViewedAt == firstTime {
|
||||
t.Fatalf("ConfirmationLastViewedAt should have updated")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateCheckoutOrder(t *testing.T) {
|
||||
reg := newRegistry()
|
||||
g := newTestGrain()
|
||||
|
||||
applyOK(t, reg, g, msgAddItem("CHECKOUT", 1000, 1, nil))
|
||||
|
||||
applyOK(t, reg, g, msgCreateCheckoutOrder("accepted", "SE"))
|
||||
if g.CheckoutOrderId == "" || g.CheckoutStatus != "pending" || g.CheckoutCountry != "SE" {
|
||||
t.Fatalf("checkout order not created: id=%s status=%s country=%s",
|
||||
g.CheckoutOrderId, g.CheckoutStatus, g.CheckoutCountry)
|
||||
}
|
||||
|
||||
// Empty cart
|
||||
g2 := newTestGrain()
|
||||
applyErrorContains(t, reg, g2, msgCreateCheckoutOrder("accepted", ""), "empty cart")
|
||||
|
||||
// Terms not accepted
|
||||
applyErrorContains(t, reg, g, msgCreateCheckoutOrder("no", ""), "terms must be accepted")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user