package repositories import ( "strings" "testing" ) /* A shift belongs to a business, not to one of its shops. Both halves of this used to demand an outlet, so the same two windows had to be re-entered at every branch a tenant owns — which is how the third branch quietly gets 07:00–15:30 and nobody notices until a cashier is filed under hours that do not exist. A tenant that works 07:00–15:00 works those hours everywhere. `locationid = 0` is now the ordinary case. A named outlet still works, because one shop may genuinely run differently and those rows already exist. */ func TestATimeIsAcceptedInBothFormsTheClientsSend(t *testing.T) { // `` gives "07:00"; some browsers and every hand-typed // value give "07:00:00"; `ridershifts` stores the seconds form already. for _, tc := range []struct{ in, want string }{ {"07:00", "07:00"}, {"07:00:00", "07:00"}, {" 23:59 ", "23:59"}, {"00:00", "00:00"}, } { got, err := normaliseShiftTime(tc.in) if err != nil { t.Fatalf("%q: %v", tc.in, err) } if got != tc.want { t.Fatalf("%q became %q, want %q", tc.in, got, tc.want) } } } func TestSomethingThatIsNotATimeOfDayIsRefused(t *testing.T) { for _, bad := range []string{"", " ", "7:00", "24:00", "07:60", "morning", "07", "7pm"} { if _, err := normaliseShiftTime(bad); err == nil { t.Fatalf("%q was accepted as a time of day", bad) } } } func TestTheTimeErrorSaysWhatShapeIsWanted(t *testing.T) { // "invalid" tells somebody nothing. The message names the format, because // the most common wrong answer is a valid time in the wrong notation. _, err := normaliseShiftTime("7pm") if err == nil || !strings.Contains(err.Error(), "HH:MM") { t.Fatalf("the refusal does not say what to type: %v", err) } }