37 lines
1.2 KiB
Go
37 lines
1.2 KiB
Go
package domain_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
contract "git.cin.su/m/Assistant/contracts/situation"
|
|
"git.cin.su/m/Assistant/modules/situation/domain"
|
|
)
|
|
|
|
func TestFocusStackPushPopKeepsParentAndSeparatesCompanies(t *testing.T) {
|
|
base := contract.FocusFrame{ID: "company-a", PrincipalID: "principal-a", ActorID: "actor", Revision: 1, ContextScopeRef: contract.SemanticReference{OwnerNamespace: "situation", SemanticKind: "context_scope", StableID: "scope-a"}, State: contract.FocusActive, Provenance: contract.FocusExplicitHuman, RecordedAt: 1}
|
|
stack, err := domain.NewFocusStack([]contract.FocusFrame{base})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
child := base
|
|
child.ID = "company-b"
|
|
child.PrincipalID = "principal-b"
|
|
child.ContextScopeRef.StableID = "scope-b"
|
|
stack, err = stack.Push(child)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
current, _ := stack.Current()
|
|
if current.ID != "company-b" || current.ParentFrameRef == nil || *current.ParentFrameRef != "company-a" {
|
|
t.Fatalf("unexpected current %#v", current)
|
|
}
|
|
stack, _, err = stack.Pop()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
current, _ = stack.Current()
|
|
if current.ID != "company-a" {
|
|
t.Fatalf("parent was not resumed: %#v", current)
|
|
}
|
|
}
|