package streaming_api_test

import (
	"net/http"
	"testing"

	"github.com/nexuscrm/tests/contract/internal/liveapi"
	"github.com/stretchr/testify/require"
)

func TestPostSubscribe(t *testing.T) {
	cfg := liveapi.LoadConfig(t)
	if cfg.TargetName == "sandbox" {
		t.Skip("subscribe smoke coverage is local-only in this phase")
	}

	client := liveapi.NewAuthenticatedClient(t)
	version := cometDVersion(t)

	resp, err := client.DoJSON(http.MethodPost, cfg.RootBaseURL+"/cometd/"+version+"/subscribe", []map[string]any{
		{
			"channel":      "/meta/subscribe",
			"clientId":     "invalid-client-id",
			"subscription": "/topic/ContractSmoke",
		},
	})
	require.NoError(t, err)
	require.Equal(t, http.StatusOK, resp.StatusCode)

	var body []map[string]any
	liveapi.DecodeJSON(t, resp, &body)

	require.Len(t, body, 1)
	require.Equal(t, "/meta/subscribe", body[0]["channel"])
	require.Equal(t, false, body[0]["successful"])
	require.Equal(t, "/topic/ContractSmoke", body[0]["subscription"])
}
