package repository

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

	"github.com/tj/assert"
)

func TestRequestPDMetaStorePopulatesRUVersion(t *testing.T) {
	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		_, _ = w.Write([]byte(`[
			{
				"KeyspaceID":"1",
				"KeyspaceName":"ks1",
				"ClusterId":"1001",
				"TenantID":"11",
				"ProjectID":"21",
				"Encrypted":true,
				"IsBranch":false,
				"MinRCU":0,
				"MaxRCU":0,
				"RUVersion":"2"
			}
		]`))
	}))
	defer server.Close()

	repo := &PDMetaStoreClient{client: *server.Client()}
	clusters, err := repo.requestPDMetaStore(context.TODO(), server.URL)
	assert.Nil(t, err)
	assert.Equal(t, 1, len(clusters))
	assert.Equal(t, "2", clusters[0].RUVersion)
}
