package opsapi

import (
	"bytes"
	"net/http"
	"net/http/httptest"
	"testing"

	"github.com/gin-gonic/gin"
	"github.com/stretchr/testify/assert"
)

func TestHelmReleaseDiffRoute(t *testing.T) {
	gin.SetMode(gin.TestMode)
	router := gin.New()
	route(router)

	body := []byte(`{"name":"alertmanager-regional","namespace":"observability","component":"alertmanager","config":{"version":"1.2.3"}}`)
	req := httptest.NewRequest(http.MethodPost, "/ops/api/v1/helmreleases/diff", bytes.NewReader(body))
	req.Header.Set("Content-Type", "application/json")
	resp := httptest.NewRecorder()

	router.ServeHTTP(resp, req)

	assert.Equal(t, http.StatusOK, resp.Code)
	assert.Contains(t, resp.Body.String(), `"safeToApply":false`)
	assert.Contains(t, resp.Body.String(), `config.sourceRef.url is required for helm diff`)
}
