X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/53c6c8a5a17e2dfc8bd3ff02ab99d29d709dda2f..e73e445bd78ba98271da6b5165f132299fca04b1:/whatsapp_test.go diff --git a/whatsapp_test.go b/whatsapp_test.go index c14571b..db04dc7 100644 --- a/whatsapp_test.go +++ b/whatsapp_test.go @@ -106,6 +106,35 @@ func TestWhatsAppFirstConnectionRetriesStopWhenContextEnds(t *testing.T) { }) } +func TestWhatsAppLinkedPairRequestKeepsFirstConnectionRetries(t *testing.T) { + synctest.Test(t, func(t *testing.T) { + test := whatsappRetryTest(t) + test.fake.connectErr = errors.New("network unavailable") + test.start(t) + synctest.Wait() + + answers := make(chan string, 1) + test.whatsapp.Command("pair 15550001111", func(text string) { + answers <- text + }) + require.Equal(t, "WhatsApp is linked already. Run /whatsapp unlink first.", <-answers) + synctest.Wait() + test.fake.mutex.Lock() + test.fake.connectErr = nil + test.fake.mutex.Unlock() + time.Sleep(whatsappRetryDelay) + synctest.Wait() + require.Len(t, test.fake.Connections(), 2) + require.True(t, test.fake.Emit(&events.Connected{})) + require.True(t, test.fake.Emit(&events.OfflineSyncCompleted{})) + require.Contains(t, test.whatsapp.Status(), "linked and connected since") + time.Sleep(whatsappRetryLimit) + synctest.Wait() + require.Len(t, test.fake.Connections(), 2) + require.Equal(t, "first connect failed, retrying: network unavailable\nconnected again after 2s\n", test.logs.String()) + }) +} + func TestWhatsAppFirstConnectionRetriesStopForLinkChanges(t *testing.T) { testCases := []struct { name string @@ -123,12 +152,6 @@ func TestWhatsAppFirstConnectionRetriesStopForLinkChanges(t *testing.T) { test.fake.Emit(&events.LoggedOut{}) }, }, - { - name: "pair command", - stop: func(test *WhatsAppRetryTest) { - test.whatsapp.Command("pair 15550001111", func(text string) {}) - }, - }, { name: "permanent disconnect", stop: func(test *WhatsAppRetryTest) {