package streaming_api_test

import (
	"net/http"
	"testing"

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

func TestPostDisconnect(t *testing.T) {
	cfg := liveapi.LoadConfig(t)
	if cfg.TargetName == "sandbox" {
		t.Skip("disconnect 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+"/disconnect", []map[string]any{
		{
			"channel":  "/meta/disconnect",
			"clientId": "invalid-client-id",
		},
	})
	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/disconnect", body[0]["channel"])
	require.Equal(t, true, body[0]["successful"])
}
