package tests

import (
	"net/http"
	"testing"

	"github.com/gin-gonic/gin"
	"github.com/pingcap/dbaas/billing2/api"
	"github.com/pingcap/dbaas/billing2/utils/ginutils"
	"github.com/pingcap/dbaas/billing2/utils/tests"
	"github.com/stretchr/testify/suite"
)

type MarketTestSuite struct {
	tests.BillingTestSuite
	router *gin.Engine
}

func (suite *MarketTestSuite) SetupTest() {
	suite.BillingTestSuite.SetupTest()
	suite.router = gin.New()
	suite.router.Use(ginutils.ErrorMiddleWare)
	api.InitializeMarketplaceRouter(ginutils.MyRoute{Route: suite.router})

}

func TestMarketTestSuite(t *testing.T) {
	suite.Run(t, new(MarketTestSuite))
}

func (suite *MarketTestSuite) TestMarketplaceAPIRouter() {
	assert := suite.Assert()
	tests.MockMarketplaceHandler()
	w := tests.PerformRequest(suite.router, "GET", "/marketplace/azure/token", nil)
	assert.Equal(http.StatusOK, w.Code)
	//	router.HandleWithError("GET", "/marketplace/azure/subscriptions/:payment_code", s.GetAzureSubscriptions)
	//
	//	router.HandleWithError("DELETE", "/marketplace/azure/subscriptions/:subscription_id", s.DeleteAzureSubscription)
	w = tests.PerformRequest(suite.router, "GET", "/marketplace/azure/subscriptions/test", nil)
	assert.Equal(http.StatusOK, w.Code)

	w = tests.PerformRequest(suite.router, "DELETE", "/marketplace/tenants/1/azure/subscriptions/test", nil)
	assert.Equal(http.StatusNotFound, w.Code)
}
