]> git.giacomolli.uk - onechat/blobdiff - whatsapp_test.go
Log failed summary builds
[onechat] / whatsapp_test.go
index 1ca0a52318d6cf85a8cf141d87773a74013ada0b..5c38d59123714b757bea6d4d330d1672fed0ab60 100644 (file)
@@ -37,12 +37,38 @@ func TestWhatsAppStatusFollowsTheConnection(t *testing.T) {
 func TestWhatsAppStatusOfAFirstConnectionThatFailed(t *testing.T) {
        dir := t.TempDir()
        whatsappTestSession(t, dir, true)
 func TestWhatsAppStatusOfAFirstConnectionThatFailed(t *testing.T) {
        dir := t.TempDir()
        whatsappTestSession(t, dir, true)
-       whatsapp, fake, _ := whatsappStartTest(t, dir, newTestClock())
+       whatsapp, fake, logs := whatsappStartTest(t, dir, newTestClock())
        daemonStartTestWithWhatsApp(t, newModelFake(t), nil, whatsapp)
 
        <-fake.connects
        require.True(t, fake.Emit(&events.Disconnected{}))
        require.Equal(t, "WhatsApp is linked and disconnected since 2026-01-01 12:00.", whatsapp.Status())
        daemonStartTestWithWhatsApp(t, newModelFake(t), nil, whatsapp)
 
        <-fake.connects
        require.True(t, fake.Emit(&events.Disconnected{}))
        require.Equal(t, "WhatsApp is linked and disconnected since 2026-01-01 12:00.", whatsapp.Status())
+       require.Equal(t, "new WhatsApp messages wait, because the first connection failed (the next try is automatic)\n", logs.String())
+}
+
+func TestWhatsAppLogsEachChangeOfTheConnectionOnce(t *testing.T) {
+       dir := t.TempDir()
+       whatsappTestSession(t, dir, true)
+       clock := newTestClock()
+       whatsapp, fake, logs := whatsappStartTest(t, dir, clock)
+       daemonStartTestWithWhatsApp(t, newModelFake(t), nil, whatsapp)
+
+       <-fake.connects
+       require.True(t, fake.Emit(&events.Connected{}))
+       clock.now = clock.now.Add(time.Minute)
+       require.True(t, fake.Emit(&events.Disconnected{}))
+       clock.now = clock.now.Add(time.Minute)
+       require.True(t, fake.Emit(&events.Disconnected{}))
+       clock.now = clock.now.Add(25 * time.Second)
+       require.True(t, fake.Emit(&events.Connected{}))
+
+       require.Equal(t, []string{
+               "WhatsApp is connected, and new messages come in",
+               "new WhatsApp messages wait, because the connection is lost (the next try is automatic)",
+               "WhatsApp is connected again, after 1m25s",
+       }, strings.Split(strings.TrimSuffix(logs.String(), "\n"), "\n"))
+       require.NotContains(t, logs.String(), whatsappTestNumber)
+       require.NotContains(t, logs.String(), whatsappTestLID)
 }
 
 func TestWhatsAppIsNotLinkedWithoutALinkedDevice(t *testing.T) {
 }
 
 func TestWhatsAppIsNotLinkedWithoutALinkedDevice(t *testing.T) {
@@ -370,7 +396,7 @@ func TestWhatsAppLogsNoOwnNumber(t *testing.T) {
        require.Eventually(t, func() bool {
                return logs.String() != ""
        }, 10*time.Second, time.Millisecond)
        require.Eventually(t, func() bool {
                return logs.String() != ""
        }, 10*time.Second, time.Millisecond)
-       require.Equal(t, "connect: no route for OWN@s.whatsapp.net and OWN@lid\n", logs.String())
+       require.Equal(t, "WhatsApp messages do not come, because the connection failed, and it is tried again only at a restart of the daemon: no route for OWN@s.whatsapp.net and OWN@lid\n", logs.String())
 }
 
 func TestWhatsAppPhone(t *testing.T) {
 }
 
 func TestWhatsAppPhone(t *testing.T) {