package scenarios_test

// Scenario tests for performance baseline.

import (
	"net/http"
	"testing"
	"time"

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

func TestPERF001_SessionInitLatency(t *testing.T) {
	// Scenario: New session initialization should complete within a
	// reasonable time. The PDF reported >2 minutes for User list,
	// >1 minute for Accounts/Opportunities.
	//
	// This test measures: token acquisition + first API call.
	// Threshold: 30 seconds (generous — real target should be <5s).

	threshold := 30 * time.Second

	start := time.Now()

	// Authenticate (simulates new session)
	client := liveapi.NewAuthenticatedClient(t)

	// First API call (simulates initial data load)
	resp, err := client.Do(http.MethodGet, "/sobjects/Account/describe", "", nil)
	require.NoError(t, err)
	resp.Body.Close()

	elapsed := time.Since(start)
	t.Logf("session init + first API call: %s", elapsed)

	assert.Less(t, elapsed, threshold,
		"session initialization took %s, exceeding %s threshold", elapsed, threshold)
}
