ghost-listmonk-connector/services/listmonk_client_test.go
troneras 1fd7dad8e4 # This is a combination of 2 commits.
# This is the 1st commit message:

first commit

# This is the commit message #2:

fixed cache
2024-08-21 02:08:01 +02:00

47 lines
1.2 KiB
Go

package services
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestListmonkClient(t *testing.T) {
// Create a mock server
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/api/tx":
w.WriteHeader(http.StatusOK)
w.Write([]byte(`{"data": true}`))
case "/api/subscribers":
w.WriteHeader(http.StatusOK)
w.Write([]byte(`{"data": {"id": 1}}`))
case "/api/campaigns":
w.WriteHeader(http.StatusOK)
w.Write([]byte(`{"data": {"id": 1}}`))
default:
http.Error(w, "Not found", http.StatusNotFound)
}
}))
defer server.Close()
// Create a client that uses the mock server URL
client := &ListmonkClient{
baseURL: server.URL,
client: server.Client(),
}
// Test SendTransactionalEmail
err := client.SendTransactionalEmail(1, "test@example.com", map[string]interface{}{"name": "Test"})
assert.NoError(t, err)
// Test ManageSubscriber
err = client.ManageSubscriber("test@example.com", "Test User", "enabled", []int{1})
assert.NoError(t, err)
// Test CreateCampaign
err = client.CreateCampaign("Test Campaign", "Test Subject", []int{1}, 1, "2023-01-01T00:00:00Z")
assert.NoError(t, err)
}