X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/0018014ab36f3de61a4b8a5515009dab803d6c38..1e2df788bbb17653a6df44acd41da2edb109d403:/whatsapp_test.go?ds=inline diff --git a/whatsapp_test.go b/whatsapp_test.go index e0018e5..1ca0a52 100644 --- a/whatsapp_test.go +++ b/whatsapp_test.go @@ -134,6 +134,14 @@ func TestWhatsAppPairsWithACode(t *testing.T) { items <- whatsmeow.QRChannelSuccess asking.WaitFor(t, "WhatsApp is linked to +15550001111.") + // The library connects again after the link with the context of the + // connection, so the end of the pairing must not end it. + connections := fake.Connections() + require.Len(t, connections, 1) + require.Never(t, func() bool { + return connections[0].Err() != nil + }, 200*time.Millisecond, time.Millisecond) + require.Equal(t, []string{whatsappTestNumber}, fake.Phones()) require.Equal(t, "WhatsApp is linked and not connected yet.", whatsapp.Status()) require.Equal(t, "[connected to OneChat]\n", other.Output()) @@ -314,7 +322,7 @@ func TestWhatsAppLongDisconnectionGivesOneNotice(t *testing.T) { whatsappTestSession(t, dir, true) clock := newTestClock() whatsapp, fake, _ := whatsappStartTest(t, dir, clock) - whatsapp.noticeDelay = 50 * time.Millisecond + whatsapp.noticeDelay = 300 * time.Millisecond socket, _ := daemonStartTestWithWhatsApp(t, newModelFake(t), nil, whatsapp) client := terminalStartTestClient(t, socket) client.WaitFor(t, "[connected to OneChat]") @@ -323,7 +331,7 @@ func TestWhatsAppLongDisconnectionGivesOneNotice(t *testing.T) { require.True(t, fake.Emit(&events.Connected{})) require.True(t, fake.Emit(&events.Disconnected{})) require.True(t, fake.Emit(&events.Connected{})) - time.Sleep(100 * time.Millisecond) + time.Sleep(400 * time.Millisecond) require.Equal(t, "[connected to OneChat]\n", client.Output()) clock.now = clock.now.Add(time.Hour) @@ -331,7 +339,7 @@ func TestWhatsAppLongDisconnectionGivesOneNotice(t *testing.T) { require.True(t, fake.Emit(&events.Disconnected{})) client.WaitFor(t, "WhatsApp is disconnected since 2026-01-01 13:00. OneChat tries again.\n") require.True(t, fake.Emit(&events.Disconnected{})) - time.Sleep(100 * time.Millisecond) + time.Sleep(400 * time.Millisecond) require.True(t, fake.Emit(&events.Connected{})) client.WaitFor(t, "WhatsApp is connected again.\n") @@ -448,22 +456,8 @@ func TestWhatsAppCommandArgs(t *testing.T) { } } -// whatsappTestLogTexts returns the texts of the messages in the log of memory, -// after the log holds at least one message. -func whatsappTestLogTexts(t *testing.T, memory *Memory) []string { - t.Helper() - - require.Eventually(t, func() bool { - return memory.Len() > 0 - }, 10*time.Second, time.Millisecond) - - var texts []string - for id := range memory.Len() { - message, err := memory.Message(id) - require.NoError(t, err) - - texts = append(texts, message.Text) - } - - return texts +func TestSubagentHasNoWhatsAppTools(t *testing.T) { + box := &Toolbox{} + 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"}`)) }