X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/723f6e18adc6482ed913e1618c8a76e981720c2b..2a528fe2981639cf099c713a6be16b8ea0e2cc67:/routes_test.go?ds=inline diff --git a/routes_test.go b/routes_test.go index dda77ea..6e11c7a 100644 --- a/routes_test.go +++ b/routes_test.go @@ -46,48 +46,49 @@ func TestRoutesRefuseUnknownSourcesAndNonchildren(t *testing.T) { cause string }{ { - name: "unknown kind", + name: "refuses unknown kind", source: "mail:inbox", agent: "Garden", cause: "unknown source kind", }, { - name: "missing kind", + name: "refuses missing kind", source: whatsappTestFamily.String(), agent: "Garden", cause: "unknown source kind", }, { - name: "empty chat", + name: "refuses empty chat", source: "whatsapp:", agent: "Garden", cause: "invalid WhatsApp source", }, { - name: "unknown chat kind", + name: "refuses unknown chat kind", source: "whatsapp:example@unknown", agent: "Garden", cause: "invalid WhatsApp source", }, { - name: "root is not a child", + name: "refuses root is not a child", source: "whatsapp:" + whatsappTestFamily.String(), agent: "OneChat", cause: "must be a child", }, { - name: "unknown child", + name: "refuses unknown child", source: "whatsapp:" + whatsappTestFamily.String(), agent: "Other", cause: "must be a child", }, { - name: "empty child", + name: "refuses empty child", source: "whatsapp:" + whatsappTestFamily.String(), agent: "", cause: "must be a child", }, } + for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { arguments := `{"source":"` + tc.source + `","agent":"` + tc.agent + `"}` @@ -122,6 +123,7 @@ func TestWhatsAppStatusListsRoutes(t *testing.T) { whatsapp.Command("status", func(text string) { answer = text }) + require.Contains(t, answer, "WhatsApp is not linked.") require.Contains(t, answer, "WhatsApp routes:\nwhatsapp:"+whatsappTestFamily.String()+" -> Garden") } @@ -132,18 +134,19 @@ func TestInvalidRouteFileStopsStartup(t *testing.T) { text string }{ { - name: "invalid JSON", + name: "stops startup for invalid JSON", text: "{", }, { - name: "unknown source", + name: "stops startup for unknown source", text: `{"mail:inbox":"Garden"}`, }, { - name: "empty destination", + name: "stops startup for empty destination", text: `{"whatsapp:example@lid":""}`, }, } + for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { path := filepath.Join(t.TempDir(), "routes.json")