package streaming_api_test

import (
	"net/http"
	"testing"

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

func TestPostConnect(t *testing.T) {
	cfg := liveapi.LoadConfig(t)
	if cfg.TargetName == "sandbox" {
		t.Skip("connect 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+"/connect", []map[string]any{
		{
			"channel":        "/meta/connect",
			"clientId":       "invalid-client-id",
			"connectionType": "long-polling",
		},
	})
	require.NoError(t, err)
	require.Equal(t, http.StatusOK, resp.StatusCode)

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

	require.NotEmpty(t, body)
	require.Equal(t, "/meta/connect", body[0]["channel"])
	require.Equal(t, false, body[0]["successful"])
}
