package services import "testing" /* Assignment has one failure mode worth defending against, and it is silent. Taking somebody off a branch is a legitimate thing to do, and it is expressed as `locationid` 0. But a body that lost the field, a form that posted a blank, or a client that dropped it all arrive as 0 too — so inferring "unassign" from the zero would let a network hiccup quietly turn somebody out of their shop. The person would keep signing in and keep being told "No store assigned", and nothing would say why. */ func TestUnassigningMustBeAskedForExplicitly(t *testing.T) { if _, err := ResolveAssignment(0, false); err == nil { t.Fatal("a missing locationid was treated as a request to unassign") } } func TestAnExplicitUnassignIsHonoured(t *testing.T) { location, err := ResolveAssignment(0, true) if err != nil { t.Fatalf("an explicit unassign was refused: %v", err) } if location != 0 { t.Fatalf("want 0, got %d", location) } } // The caller said what they wanted. Preferring a leftover id would be the same // silent guess, running the other way. func TestUnassignBeatsALeftoverBranchId(t *testing.T) { location, err := ResolveAssignment(1172, true) if err != nil || location != 0 { t.Fatalf("want 0 with no error, got %d / %v", location, err) } } func TestANamedBranchPassesThrough(t *testing.T) { location, err := ResolveAssignment(1172, false) if err != nil || location != 1172 { t.Fatalf("want 1172 with no error, got %d / %v", location, err) } } // A negative id is not a branch and is not an unassign — it is a bug upstream, // and it should stop here rather than be rounded into either. func TestANegativeBranchIdIsRefused(t *testing.T) { if _, err := ResolveAssignment(-3, false); err == nil { t.Fatal("a negative locationid was accepted") } }