package tests

import (
	"encoding/json"
	"fmt"
	"net/http"
	"testing"
	"time"

	"github.com/pingcap/dbaas/billing2/db"

	"github.com/pingcap/dbaas/billing2/utils/timeutils"
	"github.com/shopspring/decimal"

	"github.com/pingcap/dbaas/billing2/model/payment/paymentsub"

	"github.com/gin-gonic/gin"
	"github.com/pingcap/dbaas/billing2/api"
	"github.com/pingcap/dbaas/billing2/billing_errors"
	"github.com/pingcap/dbaas/billing2/db/entity"
	"github.com/pingcap/dbaas/billing2/forms"
	"github.com/pingcap/dbaas/billing2/model/marketing"
	"github.com/pingcap/dbaas/billing2/utils/ginutils"
	"github.com/pingcap/dbaas/billing2/utils/tests"
	"github.com/pingcap/dbaas/billing2/utils/tests/datainit"
	"github.com/stretchr/testify/suite"
)

var supportPlanModel = &marketing.SupportPlanModel{}

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

func (suite *SupportPlanTestSuite) SetupTest() {
	suite.BillingTestSuite.SetupTest()
	err := supportPlanModel.CreateSupportPlanUnits()
	suite.NoError(err)
	suite.router = gin.New()
	suite.router.Use(ginutils.ErrorMiddleWare)
	tests.MockCentralHandler()
	api.InitializeSupportPlanRouter(ginutils.MyRoute{Route: suite.router})
}

func TestSupportPlanSuite(t *testing.T) {
	suite.Run(t, new(SupportPlanTestSuite))
}

func (suite *SupportPlanTestSuite) TestListPublicSupportPlan() {
	assert := suite.Assert()

	supportPlanV1, err := supportPlanModel.CreateSupportPlan(&forms.SupportPlan{
		Public: true,
		Type:   entity.SupportPlanType_FixedPrice,
		Level:  entity.SupportPlanLevel_Standard,
	})
	assert.NoError(err)

	supportPlanV2, err := supportPlanModel.CreateSupportPlan(&forms.SupportPlan{
		Public:                 true,
		Type:                   entity.SupportPlanType_PercentagePrice,
		Level:                  entity.SupportPlanLevel_Developer,
		FixedChargePrice:       decimal.NewFromFloat(29),
		SupportPricePercentage: decimal.NewFromFloat(0.1),
	})
	assert.NoError(err)

	_, err = supportPlanModel.CreateSupportPlan(&forms.SupportPlan{
		Public: false,
		Type:   entity.SupportPlanType_FixedPrice,
	})
	assert.NoError(err)

	w := tests.PerformGetRequest(suite.router, "/support_plan")
	assert.Equal(http.StatusOK, w.Code)
	response := []forms.SupportPlan{}
	err = json.Unmarshal(w.Body.Bytes(), &response)
	assert.NoError(err)
	assert.Len(response, 2)

	// case-2: delete supportplan
	err = supportPlanModel.DeleteSupportPlan(supportPlanV1.SupportPlanID)
	assert.NoError(err)
	w = tests.PerformGetRequest(suite.router, "/support_plan")
	assert.Equal(http.StatusOK, w.Code)
	response = []forms.SupportPlan{}
	err = json.Unmarshal(w.Body.Bytes(), &response)
	assert.NoError(err)
	assert.Len(response, 1)
	assert.Equal(response[0].Level, supportPlanV2.Level)

	// case-3: get deleted supportplan
	_, err = supportPlanModel.GetSupportPlan(supportPlanV1.SupportPlanID)
	assert.ErrorIs(err, billing_errors.ObjectNotExistsError)
}

func (suite *SupportPlanTestSuite) TestTenantBindSupportPlan() {
	assert := suite.Assert()

	tenantID := uint(1)
	datainit.CreateBillingConfig(1, entity.BillingConfigType_DirectCustomer)
	datainit.CreatePaymentMock(tenantID)

	info, err := supportPlanModel.CreateSupportPlan(&forms.SupportPlan{
		Public:                 true,
		Type:                   entity.SupportPlanType_PercentagePrice,
		Level:                  entity.SupportPlanLevel_Standard,
		FixedChargePrice:       decimal.NewFromFloat(49),
		SupportPricePercentage: decimal.NewFromFloat(0.1),
	})
	assert.NoError(err)

	input := &forms.BindedSupportPlanInput{
		SupportPlanID: info.SupportPlanID,
	}
	// case-1
	w := tests.PerformRequest(suite.router, "POST", fmt.Sprintf("/tenants/%d/binded_support_plan/public", tenantID), input)
	assert.Equal(http.StatusOK, w.Code)

	bindedSupportPlan, err := supportPlanModel.GetTenantActiveBindedPlan(tenantID)
	assert.NoError(err)
	assert.Equal(bindedSupportPlan.SupportPlanID, info.SupportPlanID)

	// delete the SupportPlan
	err = supportPlanModel.DeleteSupportPlan(info.SupportPlanID)
	assert.NoError(err)

	// case-2: query bindedSupportPlan, which supportplan has been deleted, but bindedSupportPlan dose not deleted
	var list []forms.BindedSupportPlan
	w = tests.PerformRequest(suite.router, "GET", fmt.Sprintf("/tenants/%d/binded_support_plan/list", tenantID), nil)
	assert.Equal(http.StatusOK, w.Code, w.Body.String())
	err = json.Unmarshal(w.Body.Bytes(), &list)
	assert.NoError(err)
	assert.Len(list, 1)
	assert.Equal(list[0].SupportPlanID, info.SupportPlanID)
}

func (suite *SupportPlanTestSuite) TestTenantBindPrivateSupportPlan() {
	assert := suite.Assert()

	tenantID := uint(1)
	datainit.CreatePaymentMock(tenantID)
	datainit.CreateBillingConfig(tenantID, entity.BillingConfigType_DirectCustomer)

	input := &forms.SupportPlanInput{
		SupportPlan: forms.SupportPlan{
			Public: false,
			Type:   entity.SupportPlanType_FixedPrice,
		},
		ActiveDate: timeutils.GetNow(),
	}
	w := tests.PerformRequest(suite.router, "POST", fmt.Sprintf("/tenants/%d/binded_support_plan/private", tenantID), input)
	assert.Equal(http.StatusOK, w.Code)

	bindedSupportPlan, err := supportPlanModel.GetTenantActiveBindedPlan(tenantID)
	assert.NoError(err)
	assert.Equal(bindedSupportPlan.Public, false)
}

func (suite *SupportPlanTestSuite) TestTenantGetSupportPlanDefault() {
	assert := suite.Assert()

	tenantID := uint(1)
	datainit.CreateBillingConfig(tenantID, entity.BillingConfigType_DirectCustomer)

	w := tests.PerformGetRequest(suite.router, fmt.Sprintf("/tenants/%d/binded_support_plan", tenantID))
	assert.Equal(http.StatusOK, w.Code)

	response := &forms.BindedSupportPlan{}
	err := json.Unmarshal(w.Body.Bytes(), response)
	assert.NoError(err)

	assert.Equal(response.SupportPlan.Level, entity.SupportPlanLevel_Basic)
	datainit.CreatePaymentMock(tenantID)

	w = tests.PerformGetRequest(suite.router, fmt.Sprintf("/tenants/%d/binded_support_plan", tenantID))
	assert.Equal(http.StatusOK, w.Code)

	response = &forms.BindedSupportPlan{}
	err = json.Unmarshal(w.Body.Bytes(), response)
	assert.NoError(err)

	assert.Equal(response.SupportPlan.Level, entity.SupportPlanLevel_Basic)

}

func (suite *SupportPlanTestSuite) TestTenantGetSupportPlan() {
	assert := suite.Assert()

	tenantID := uint(1)
	datainit.CreateBillingConfig(tenantID, entity.BillingConfigType_DirectCustomer)
	datainit.CreatePaymentMock(tenantID)
	info, err := supportPlanModel.CreateSupportPlan(&forms.SupportPlan{
		Public: true,
		Type:   entity.SupportPlanType_FixedPrice,
	})
	assert.NoError(err)

	bindedSupportPlanInfo, err := supportPlanModel.BindSupportPlanForPayableCustomer(tenantID, info.SupportPlanID, forms.DateInterval{StartDate: timeutils.GetTimeAddr(timeutils.GetDayDate(timeutils.GetNow()))})
	assert.NoError(err)

	w := tests.PerformGetRequest(suite.router, fmt.Sprintf("/tenants/%d/binded_support_plan", tenantID))
	assert.Equal(http.StatusOK, w.Code)

	assert.NoError(err)
	response := &forms.BindedSupportPlan{}
	err = json.Unmarshal(w.Body.Bytes(), response)
	assert.NoError(err)
	assert.Equal(response.BindedSupportPlanID, bindedSupportPlanInfo.BindedSupportPlanID)

	err = entity.NewPaymentMethodQuerySet(db.GetDB()).TenantIDEq(tenantID).GetUpdater().SetStatus(entity.PaymentMethodStatus_InActive).SetPayable(false).SetUnpayableAt(nil).Update()
	assert.NoError(err)
	w = tests.PerformGetRequest(suite.router, fmt.Sprintf("/tenants/%d/binded_support_plan", tenantID))
	assert.Equal(http.StatusOK, w.Code)
	assert.NoError(err)
	response1 := &forms.BindedSupportPlan{}
	err = json.Unmarshal(w.Body.Bytes(), response1)
	assert.NoError(err)
	assert.Equal(response1.BindedSupportPlanID, bindedSupportPlanInfo.BindedSupportPlanID)

}

func (suite *SupportPlanTestSuite) TestMspCustomerTenantGetSupportPlan() {
	assert := suite.Assert()

	tenantID := uint(211)
	datainit.CreateBillingConfig(tenantID, entity.BillingConfigType_DirectCustomer)

	err := datainit.CreatePaymentMock(tenantID)
	assert.NoError(err)
	info, err := supportPlanModel.CreateSupportPlan(&forms.SupportPlan{
		Public: true,
		Type:   entity.SupportPlanType_FixedPrice,
	})
	assert.NoError(err)

	bindedSupportPlanInfo, err := supportPlanModel.BindSupportPlanForPayableCustomer(tenantID, info.SupportPlanID, forms.DateInterval{StartDate: timeutils.GetTimeAddr(timeutils.GetDayDate(timeutils.GetNow()))})
	assert.NoError(err)

	w := tests.PerformGetRequest(suite.router, fmt.Sprintf("/tenants/%d/binded_support_plan", tenantID))
	assert.Equal(http.StatusOK, w.Code)

	assert.NoError(err)
	response := &forms.BindedSupportPlan{}
	err = json.Unmarshal(w.Body.Bytes(), response)
	assert.NoError(err)
	assert.Equal(response.BindedSupportPlanID, bindedSupportPlanInfo.BindedSupportPlanID)

	datainit.CreateBillingConfig(210, entity.BillingConfigType_MSP)
	billingConfigID := uint(2)
	paymentModel := &paymentsub.PaymentModel{}
	_, err = paymentModel.CreatePaymentMethodAndActive(210, &forms.PaymentMethodCreateQuery{
		PaymentType:           entity.PaymentType_MSP,
		BindedBillingConfigID: &billingConfigID,
	})
	assert.NoError(err)
	w = tests.PerformGetRequest(suite.router, fmt.Sprintf("/tenants/%d/binded_support_plan", 210))
	assert.Equal(http.StatusOK, w.Code)

	assert.NoError(err)
	err = json.Unmarshal(w.Body.Bytes(), response)
	assert.NoError(err)

	assert.Equal(response.Level, bindedSupportPlanInfo.Level)

}

func (suite *SupportPlanTestSuite) TestTenantCancelSupportPlan() {
	assert := suite.Assert()

	tenantID := uint(1)
	datainit.CreateBillingConfig(tenantID, entity.BillingConfigType_DirectCustomer)
	datainit.CreatePaymentMock(tenantID)
	info, err := supportPlanModel.CreateSupportPlan(&forms.SupportPlan{
		Public: false,
		Type:   entity.SupportPlanType_FixedPrice,
	})
	assert.NoError(err)

	_, err = supportPlanModel.BindSupportPlanForPayableCustomer(tenantID, info.SupportPlanID, forms.DateInterval{StartDate: timeutils.GetTimeAddr(timeutils.GetDayDate(timeutils.GetNow()))})
	assert.NoError(err)

	w := tests.PerformRequest(suite.router, "DELETE", fmt.Sprintf("/tenants/%d/binded_support_plan", tenantID), nil)
	assert.Equal(http.StatusOK, w.Code, w.Body.String())
	_, err = supportPlanModel.GetTenantActiveBindedPlan(tenantID)
	assert.Error(err)
	assert.ErrorIs(err, billing_errors.ObjectNotExistsError)

}

func (suite *SupportPlanTestSuite) TestTenantCancelPublicSupportPlan() {
	assert := suite.Assert()

	tenantID := uint(1)
	datainit.CreateBillingConfig(tenantID, entity.BillingConfigType_DirectCustomer)
	datainit.CreatePaymentMock(tenantID)
	info, err := supportPlanModel.CreateSupportPlan(&forms.SupportPlan{
		Public: false,
		Type:   entity.SupportPlanType_FixedPrice,
	})
	assert.NoError(err)

	_, err = supportPlanModel.BindSupportPlanForPayableCustomer(tenantID, info.SupportPlanID, forms.DateInterval{StartDate: timeutils.GetTimeAddr(timeutils.GetDayDate(timeutils.GetNow()))})
	assert.NoError(err)

	w := tests.PerformRequest(suite.router, "DELETE", fmt.Sprintf("/tenants/%d/binded_support_plan/public", tenantID), nil)
	assert.Equal(http.StatusBadRequest, w.Code, w.Body.String())
}

func (suite *SupportPlanTestSuite) TestMultiBindedSupportPlans() {
	assert := suite.Assert()
	tenantID := uint(1)
	datainit.CreateBillingConfig(tenantID, entity.BillingConfigType_DirectCustomer)
	datainit.CreatePaymentMock(tenantID)
	supportPlanInput := forms.SupportPlanInput{
		SupportPlan: forms.SupportPlan{
			FixedChargePrice:       decimal.NewFromInt(29),
			SupportPricePercentage: decimal.NewFromFloat(0.1),
			Type:                   entity.SupportPlanType_PercentagePrice,
			Level:                  entity.SupportPlanLevel_Developer,
			IsSupportFreeTrial:     true,
		},
		ActiveDate:  datainit.BillingDate.AddDate(0, 0, -1),                        // activeDate = 2021-10-30 00:00:00
		ExpiredDate: timeutils.GetTimeAddr(datainit.BillingDate.AddDate(0, 1, -1)), // expiredDate = 2021-11-30 00:00:00, will be set: 2021-11-30 23:59:59
	}

	timeutils.SetMockNow(datainit.BillingDate) // now = 2021-11-01 00:00:00
	// case-1: activeDate < now()
	w := tests.PerformRequest(suite.router, "POST", fmt.Sprintf("/tenants/%d/binded_support_plan/private", tenantID), supportPlanInput)
	assert.Equal(http.StatusBadRequest, w.Code, w.Body.String())

	// case-2
	supportPlanInput.ActiveDate = datainit.BillingDate // activeDate = 2021-11-01 00:00:00, expiredDate = 2021-11-30 00:00:00, will be set: 2021-11-30 23:59:59
	w = tests.PerformRequest(suite.router, "POST", fmt.Sprintf("/tenants/%d/binded_support_plan/private", tenantID), supportPlanInput)
	assert.Equal(http.StatusOK, w.Code, w.Body.String())
	var ret forms.BindedSupportPlan
	err := json.Unmarshal(w.Body.Bytes(), &ret)
	assert.NoError(err)
	assert.Equal("2021-11-30T23:59:59Z", ret.ExpiredDate.Format("2006-01-02T15:04:05Z"))
	assert.Equal(ret.Status, entity.BindedSupportPlanStatus_ACTIVE)

	// case-3: time conflict
	supportPlanInput.ActiveDate = datainit.BillingDate.AddDate(0, 1, -1)                         // activeDate = 2021-11-30 00:00:00
	supportPlanInput.ExpiredDate = timeutils.GetTimeAddr(datainit.BillingDate.AddDate(0, 2, -1)) // expiredDate = 2021-12-31 00:00:00, will be set: 2021-12-31 23:59:59
	w = tests.PerformRequest(suite.router, "POST", fmt.Sprintf("/tenants/%d/binded_support_plan/private", tenantID), supportPlanInput)
	assert.Equal(http.StatusOK, w.Code, w.Body.String())
	err = json.Unmarshal(w.Body.Bytes(), &ret)
	assert.NoError(err)
	assert.Equal("2021-11-30T00:00:00Z", ret.ActiveDate.Format("2006-01-02T15:04:05Z"))
	assert.Equal("2021-12-31T23:59:59Z", ret.ExpiredDate.Format("2006-01-02T15:04:05Z"))
	assert.Equal(ret.Status, entity.BindedSupportPlanStatus_TOBEACTIVATED)

	// case-4: no time conflict
	supportPlanInput.ActiveDate = datainit.BillingDate.AddDate(0, 2, 0)                          // activeDate = 2022-01-01 00:00:00
	supportPlanInput.ExpiredDate = timeutils.GetTimeAddr(datainit.BillingDate.AddDate(0, 2, 29)) // expiredDate = 2022-01-30 00:00:00, will be set: 2022-01-30 23:59:59
	w = tests.PerformRequest(suite.router, "POST", fmt.Sprintf("/tenants/%d/binded_support_plan/private", tenantID), supportPlanInput)
	assert.Equal(http.StatusOK, w.Code, w.Body.String())
	err = json.Unmarshal(w.Body.Bytes(), &ret)
	assert.NoError(err)
	assert.Equal("2022-01-01T00:00:00Z", ret.ActiveDate.Format("2006-01-02T15:04:05Z"))
	assert.Equal("2022-01-30T23:59:59Z", ret.ExpiredDate.Format("2006-01-02T15:04:05Z"))
	assert.Equal(ret.Status, entity.BindedSupportPlanStatus_TOBEACTIVATED)

	w = tests.PerformRequest(suite.router, "GET", fmt.Sprintf("/tenants/%d/binded_support_plan/list", tenantID), nil)
	var list []forms.BindedSupportPlan
	assert.Equal(http.StatusOK, w.Code, w.Body.String())
	err = json.Unmarshal(w.Body.Bytes(), &list)
	assert.NoError(err)
	assert.Len(list, 3)

	assert.Equal(entity.BindedSupportPlanStatus_ACTIVE, list[0].Status)
	assert.Equal(entity.SupportPlanLevel_Developer, list[0].Level)
	assert.Equal("2021-11-29T23:59:59Z", list[0].ExpiredDate.Format("2006-01-02T15:04:05Z"))

	assert.Equal(entity.BindedSupportPlanStatus_TOBEACTIVATED, list[1].Status)
	assert.Equal(entity.SupportPlanLevel_Developer, list[1].Level)
	assert.Equal("2021-11-30T00:00:00Z", list[1].ActiveDate.Format("2006-01-02T15:04:05Z"))
	assert.Equal("2021-12-31T23:59:59Z", list[1].ExpiredDate.Format("2006-01-02T15:04:05Z"))

	assert.Equal(entity.BindedSupportPlanStatus_TOBEACTIVATED, list[2].Status)
	assert.Equal(entity.SupportPlanLevel_Developer, list[2].Level)
	assert.Equal("2022-01-01T00:00:00Z", list[2].ActiveDate.Format("2006-01-02T15:04:05Z"))
	assert.Equal("2022-01-30T23:59:59Z", list[2].ExpiredDate.Format("2006-01-02T15:04:05Z"))

	// get active BindedSupportPlan
	w = tests.PerformRequest(suite.router, "GET", fmt.Sprintf("/tenants/%d/binded_support_plan", tenantID), nil)
	assert.Equal(http.StatusOK, w.Code, w.Body.String())
	err = json.Unmarshal(w.Body.Bytes(), &ret)
	assert.NoError(err)
	assert.Equal(ret.Level, entity.SupportPlanLevel_Developer)
	assert.Equal("2021-11-29T23:59:59Z", ret.ExpiredDate.Format("2006-01-02T15:04:05Z"))
	assert.Equal(ret.Status, entity.BindedSupportPlanStatus_ACTIVE)

	// delete active BindedSupportPlan, status = "canceled"
	w = tests.PerformRequest(suite.router, "DELETE", fmt.Sprintf("/tenants/%d/binded_support_plan/%d", tenantID, list[0].BindedSupportPlanID), nil)
	assert.Equal(http.StatusOK, w.Code, w.Body.String())
	// request
	w = tests.PerformRequest(suite.router, "GET", fmt.Sprintf("/tenants/%d/binded_support_plan/list", tenantID), nil)
	assert.Equal(http.StatusOK, w.Code, w.Body.String())
	err = json.Unmarshal(w.Body.Bytes(), &list)
	assert.NoError(err)
	assert.Len(list, 4)
	assert.Equal(entity.BindedSupportPlanStatus_ACTIVE, list[0].Status)
	assert.Equal(entity.SupportPlanLevel_Basic, list[0].Level)

	w = tests.PerformRequest(suite.router, "GET", fmt.Sprintf("/tenants/%d/binded_support_plan", tenantID), nil)
	assert.Equal(http.StatusOK, w.Code, w.Body.String())
	err = json.Unmarshal(w.Body.Bytes(), &ret)
	assert.NoError(err)
	assert.Equal(ret.Level, entity.SupportPlanLevel_Basic)

	// no binded active supportplan
	w = tests.PerformRequest(suite.router, "DELETE", fmt.Sprintf("/tenants/%d/binded_support_plan", tenantID), nil)
	assert.Equal(http.StatusNotFound, w.Code, w.Body.String())

	supportPlanInput.ActiveDate = datainit.BillingDate // 2021-11-01 00:00:00
	supportPlanInput.Level = entity.SupportPlanLevel_Standard
	supportPlanInput.ExpiredDate = timeutils.GetTimeAddr(datainit.BillingDate.AddDate(0, 1, -1)) // 2021-11-30 23:59:59
	w = tests.PerformRequest(suite.router, "POST", fmt.Sprintf("/tenants/%d/binded_support_plan/private", tenantID), supportPlanInput)
	assert.Equal(http.StatusOK, w.Code, w.Body.String())
	err = json.Unmarshal(w.Body.Bytes(), &ret)
	assert.NoError(err)
	assert.Equal(entity.SupportPlanLevel_Standard, ret.Level)
	assert.Equal("2021-11-01T00:00:00Z", ret.ActiveDate.Format("2006-01-02T15:04:05Z"))
	assert.Equal("2021-11-30T23:59:59Z", ret.ExpiredDate.Format("2006-01-02T15:04:05Z"))

	w = tests.PerformRequest(suite.router, "DELETE", fmt.Sprintf("/tenants/%d/binded_support_plan", tenantID), nil)
	assert.Equal(http.StatusOK, w.Code, w.Body.String())
}

func (suite *SupportPlanTestSuite) TestListTenantBindedSupportPlans() {
	assert := suite.Assert()
	tenantID := uint(1)
	datainit.CreateBillingConfig(tenantID, entity.BillingConfigType_DirectCustomer) // 2021-10-01 00:00:00
	datainit.CreatePaymentMock(tenantID)

	// case-1: has not subscribe any supportPlan
	w := tests.PerformGetRequest(suite.router, fmt.Sprintf("/tenants/%d/binded_support_plan/details", tenantID))
	assert.Equal(http.StatusOK, w.Code)
	response1 := &forms.BindedSupportPlanDetails{}
	err := json.Unmarshal(w.Body.Bytes(), response1)
	assert.NoError(err)
	assert.Equal(response1.IsEligibleForFreeTrial, true)
	assert.Equal(len(response1.BindedSupportPlans), 0)

	info, err := supportPlanModel.CreateSupportPlan(&forms.SupportPlan{
		FixedChargePrice:       decimal.NewFromInt(29),
		SupportPricePercentage: decimal.NewFromFloat(0.2),
		Type:                   entity.SupportPlanType_PercentagePrice,
		Public:                 false,
		Level:                  entity.SupportPlanLevel_Developer,
		IsSupportFreeTrial:     true,
	})
	assert.NoError(err)

	timeutils.GetNowFunc = func() time.Time {
		return datainit.BillingDate // now = 2021-11-01 00:00:00
	}
	// bind and active
	bindedInfo, err := supportPlanModel.BindSupportPlanForPayableCustomer(tenantID, info.SupportPlanID, forms.DateInterval{StartDate: timeutils.GetTimeAddr(timeutils.GetNow())})
	assert.NoError(err)
	assert.Equal(bindedInfo.IsEligibleForFreeTrial, true)

	// case-2: has subscribe supportplan
	w = tests.PerformGetRequest(suite.router, fmt.Sprintf("/tenants/%d/binded_support_plan/details", tenantID))
	assert.Equal(http.StatusOK, w.Code)
	assert.NoError(err)
	response1 = &forms.BindedSupportPlanDetails{}
	err = json.Unmarshal(w.Body.Bytes(), response1)
	assert.NoError(err)
	assert.Equal(response1.IsEligibleForFreeTrial, false)
	assert.Equal(len(response1.BindedSupportPlans), 1)
}
