]> git.giacomolli.uk - onechat/blobdiff - whatsapp_test.go
Keep scenario tests with their implementation
[onechat] / whatsapp_test.go
index f098c908012013298260094afa083c716ea4217b..9ed4105130920aca9b8cd402a029cde811a12a3c 100644 (file)
@@ -2,6 +2,7 @@ package main
 
 import (
        "errors"
+       "log/slog"
        "os"
        "path/filepath"
        "strings"
@@ -249,12 +250,12 @@ func TestWhatsAppLongFirstConnectionOutageGivesOneNotice(t *testing.T) {
 
                since := time.Now().Format(whatsappTimeLayout)
 
-               time.Sleep(whatsappNoticeDelay)
+               time.Sleep(whatsappOutageNoticeDelay)
                synctest.Wait()
                require.Equal(t, 1, test.events.Count("notice"))
                require.Equal(t, "WhatsApp is disconnected since "+since+". OneChat tries again.", test.events.Last("notice"))
 
-               time.Sleep(whatsappNoticeDelay)
+               time.Sleep(whatsappOutageNoticeDelay)
                synctest.Wait()
                require.Equal(t, 1, test.events.Count("notice"))
                test.fake.mutex.Lock()
@@ -613,18 +614,18 @@ func TestWhatsAppLongDisconnectionGivesOneNotice(t *testing.T) {
                require.True(t, test.fake.Emit(&events.Connected{}))
                require.True(t, test.fake.Emit(&events.Disconnected{}))
                require.True(t, test.fake.Emit(&events.Connected{}))
-               time.Sleep(whatsappNoticeDelay + time.Second)
+               time.Sleep(whatsappOutageNoticeDelay + time.Second)
                synctest.Wait()
                require.Zero(t, test.events.Count("notice"))
 
                require.True(t, test.fake.Emit(&events.Disconnected{}))
                require.True(t, test.fake.Emit(&events.Disconnected{}))
-               time.Sleep(whatsappNoticeDelay)
+               time.Sleep(whatsappOutageNoticeDelay)
                synctest.Wait()
                require.Equal(t, 1, test.events.Count("notice"))
                require.Contains(t, test.events.Last("notice"), "OneChat tries again.")
                require.True(t, test.fake.Emit(&events.Disconnected{}))
-               time.Sleep(whatsappNoticeDelay)
+               time.Sleep(whatsappOutageNoticeDelay)
                synctest.Wait()
                require.Equal(t, 1, test.events.Count("notice"))
 
@@ -753,3 +754,8 @@ func TestSubagentHasNoWhatsAppTools(t *testing.T) {
        require.Equal(t, `error: unknown tool "whatsapp_find"`, box.run(t.Context(), "whatsapp_find", `{"name":"ana"}`))
        require.Equal(t, `error: unknown tool "whatsapp_send"`, box.run(t.Context(), "whatsapp_send", `{"id":"a","chat":"15550002222@s.whatsapp.net","text":"hi"}`))
 }
+
+// whatsappDiscardLog is a logger for a WhatsApp whose log a test does not read.
+func whatsappDiscardLog() *slog.Logger {
+       return slog.New(slog.DiscardHandler)
+}