]> git.giacomolli.uk - onechat/blobdiff - whatsapp_import_test.go
Select notification targets by stable ID
[onechat] / whatsapp_import_test.go
index 382d4bf8e8839cf7bd619254afb8d85f359e228b..eed22fd0a705c6e3d85954b5024e96cc68b80732 100644 (file)
@@ -705,24 +705,46 @@ func TestWhatsAppImportRefusesPendingDeliveriesAndKeepsRestartSafe(t *testing.T)
 }
 
 func TestWhatsAppImportBlocksPendingNotificationsButNotCompletedReceipts(t *testing.T) {
 }
 
 func TestWhatsAppImportBlocksPendingNotificationsButNotCompletedReceipts(t *testing.T) {
-       server := newModelFake(t)
-       test := newDaemonMessageTest(t, t.TempDir(), server)
-       _, err := test.messages.Notify(&NotifyInput{
-               Source: "check",
-               ID:     "1",
-               Text:   "A result.",
-       })
-       require.NoError(t, err)
+       testCases := []struct {
+               name  string
+               index int
+       }{
+               {
+                       name: "blocks only pending root notifications",
+               },
+               {
+                       name:  "blocks only pending child notifications",
+                       index: 1,
+               },
+       }
 
 
-       root := test.agents[0].agent
-       directory := root.dir
-       require.ErrorContains(t, whatsappImportIdle(directory, root), "pending deliveries")
-       require.NoError(t, whatsappImportIdle(directory, test.agents[1].agent))
-       require.NoError(t, test.messages.Notifications(test.loops[0]))
-       require.NoError(t, test.loops[0].turn(t.Context()))
-       require.Len(t, test.Queue(t).Notifications, 1)
-       require.Empty(t, test.Queue(t).Pending)
-       require.NoError(t, whatsappImportIdle(directory, root))
+       for _, tc := range testCases {
+               t.Run(tc.name, func(t *testing.T) {
+                       server := newModelFake(t)
+                       server.reply = func(w http.ResponseWriter, _ ModelFakeCall) {
+                               modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("")}, 100, 0, 5))
+                       }
+
+                       test := newDaemonMessageTest(t, t.TempDir(), server)
+                       _, err := test.messages.Notify(&NotifyInput{
+                               AgentID: test.agents[tc.index].agent.config.ID,
+                               Source:  "check",
+                               ID:      "1",
+                               Text:    "A result.",
+                       })
+                       require.NoError(t, err)
+
+                       target := test.agents[tc.index].agent
+                       directory := test.agents[0].agent.dir
+                       require.ErrorContains(t, whatsappImportIdle(directory, target), "pending deliveries")
+                       require.NoError(t, whatsappImportIdle(directory, test.agents[tc.index^1].agent))
+                       require.NoError(t, test.messages.Notifications(test.loops[tc.index]))
+                       require.NoError(t, test.loops[tc.index].turn(t.Context()))
+                       require.Len(t, test.Queue(t).Notifications, 1)
+                       require.Empty(t, test.Queue(t).Pending)
+                       require.NoError(t, whatsappImportIdle(directory, target))
+               })
+       }
 }
 
 func TestWhatsAppImportPendingDeliveriesBlockOnlyTheirTarget(t *testing.T) {
 }
 
 func TestWhatsAppImportPendingDeliveriesBlockOnlyTheirTarget(t *testing.T) {