Fix TestCampaign sending only subscribers, failing listmonk validation
CI / test (push) Successful in 9s
CI / test (push) Successful in 9s
listmonk's /api/campaigns/:id/test handler binds the request into the
same campReq struct create/update use and validates it in full, so a
request with only {"subscribers": [...]} fails with "Invalid length
for name" before subscribers is ever read. TestCampaign now sends the
campaign's full CampaignInput alongside subscribers.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -311,13 +311,17 @@ func TestTestCampaign_SendsSubscribersList(t *testing.T) {
|
||||
defer srv.Close()
|
||||
|
||||
c := New(srv.URL, "u", "t")
|
||||
if err := c.TestCampaign(7, []string{"me@example.com"}); err != nil {
|
||||
in := CampaignInput{Name: "launch", Subject: "Hi", Body: "body", Type: "regular"}
|
||||
if err := c.TestCampaign(7, in, []string{"me@example.com"}); err != nil {
|
||||
t.Fatalf("TestCampaign: %v", err)
|
||||
}
|
||||
subs, ok := gotBody["subscribers"].([]any)
|
||||
if !ok || len(subs) != 1 || subs[0] != "me@example.com" {
|
||||
t.Errorf("expected subscribers=[me@example.com], got %+v", gotBody)
|
||||
}
|
||||
if gotBody["name"] != "launch" {
|
||||
t.Errorf("expected the full campaign body (name=launch) alongside subscribers, got %+v", gotBody)
|
||||
}
|
||||
}
|
||||
|
||||
func TestErrorResponsesAreWrappedWithStatusAndBody(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user