generated from PenaSide/GolangTemplate
add test
This commit is contained in:
parent
370a2c7e2c
commit
145066f06f
@ -60,13 +60,11 @@ func Run(config *models.Config, logger *zap.Logger) (appErr error) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println("do brokers")
|
||||
|
||||
brokers := initialize.NewBrokers(initialize.BrokersDeps{
|
||||
Logger: logger,
|
||||
TariffClient: kafkaTariffClient,
|
||||
})
|
||||
fmt.Println("brokers")
|
||||
|
||||
clients := initialize.NewClients(initialize.ClientsDeps{
|
||||
Logger: logger,
|
||||
@ -78,7 +76,6 @@ func Run(config *models.Config, logger *zap.Logger) (appErr error) {
|
||||
VerificationURL: &config.Service.VerificationMicroservice.URL,
|
||||
TemplategenURL: &config.Service.TemplategenMicroserviceURL.URL,
|
||||
})
|
||||
fmt.Println("clients")
|
||||
|
||||
repositories := initialize.NewRepositories(initialize.RepositoriesDeps{
|
||||
Logger: logger,
|
||||
|
@ -43,7 +43,6 @@ func (receiver *HubadminClient) GetTariff(ctx context.Context, accessToken strin
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Errorf("failed to join path on <GetTariff> of <HubadminClient>: %w", err), errors.ErrInternalError)
|
||||
}
|
||||
fmt.Println(tariffURL)
|
||||
|
||||
response, err := client.Get[models.Tariff, models.FastifyError](ctx, &client.RequestSettings{
|
||||
URL: tariffURL,
|
||||
|
@ -188,7 +188,13 @@ func (receiver *HistoryRepository) GetRecentTariffs(ctx context.Context, userID
|
||||
// TODO:tests.
|
||||
func (receiver *HistoryRepository) GetHistoryByID(ctx context.Context, historyID string) (*models.ReportHistory, errors.Error) {
|
||||
history := &models.ReportHistory{}
|
||||
err := receiver.mongoDB.FindOne(ctx, bson.M{"_id": historyID}).Decode(history)
|
||||
|
||||
objID, err := primitive.ObjectIDFromHex(historyID)
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Errorf("failed to convert history ID: %w", err), errors.ErrInternalError)
|
||||
}
|
||||
|
||||
err = receiver.mongoDB.FindOne(ctx, bson.M{"_id": objID}).Decode(history)
|
||||
if err != nil {
|
||||
receiver.logger.Error(
|
||||
"failed to find by id in <GetHistoryById> of <HistoryRepository>",
|
||||
|
@ -606,8 +606,6 @@ func (api *API2) CalculateLTV(ctx echo.Context) error {
|
||||
return api.error(ctx, http.StatusBadRequest, "failed to bind request")
|
||||
}
|
||||
|
||||
fmt.Println(req)
|
||||
|
||||
if req.From > req.To && req.To != 0 {
|
||||
api.logger.Error("From timestamp must be less than To timestamp unless To is 0")
|
||||
return api.error(ctx, http.StatusBadRequest, "From timestamp must be less than To timestamp unless To is 0")
|
||||
@ -625,8 +623,6 @@ func (api *API2) CalculateLTV(ctx echo.Context) error {
|
||||
LTV: ltv,
|
||||
}
|
||||
|
||||
fmt.Println(response)
|
||||
|
||||
return ctx.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
@ -655,18 +651,22 @@ func (api *API2) GetRecentTariffs(ctx echo.Context) error {
|
||||
}
|
||||
|
||||
func (api *API2) SendReport(ctx echo.Context) error {
|
||||
fmt.Println("SendReport")
|
||||
historyID := ctx.Param("id")
|
||||
if historyID == "" {
|
||||
var req SendReportJSONBody
|
||||
if err := ctx.Bind(&req); err != nil {
|
||||
api.logger.Error("failed to bind request", zap.Error(err))
|
||||
return api.error(ctx, http.StatusBadRequest, "failed to bind request")
|
||||
}
|
||||
|
||||
if req.Id == "" {
|
||||
api.logger.Error("history id is missing in <GetHistoryById> of <HistoryService>")
|
||||
return api.error(ctx, http.StatusBadRequest, "history id is missing")
|
||||
}
|
||||
|
||||
tariffs, err := api.history.GetHistoryByID(ctx.Request().Context(), historyID)
|
||||
tariffs, err := api.history.GetHistoryByID(ctx.Request().Context(), req.Id)
|
||||
if err != nil {
|
||||
api.logger.Error(
|
||||
"failed to get history by id in <GetHistoryById> of <HistoryService>",
|
||||
zap.String("historyID", historyID),
|
||||
zap.String("historyID", req.Id),
|
||||
zap.Error(err),
|
||||
)
|
||||
return api.errorOld(ctx, err)
|
||||
@ -675,7 +675,7 @@ func (api *API2) SendReport(ctx echo.Context) error {
|
||||
if tariffs.Key != models.CustomerHistoryKeyPayCart {
|
||||
api.logger.Error(
|
||||
"invalid history record key",
|
||||
zap.String("historyID", historyID),
|
||||
zap.String("historyID", req.Id),
|
||||
zap.Error(err),
|
||||
)
|
||||
return api.error(ctx, http.StatusBadRequest, "invalid history record key")
|
||||
@ -685,7 +685,7 @@ func (api *API2) SendReport(ctx echo.Context) error {
|
||||
if err != nil {
|
||||
api.logger.Error(
|
||||
"failed to get history of sorting by date created in <GetDocNumber> of <HistoryService>",
|
||||
zap.String("historyID", historyID),
|
||||
zap.String("historyID", req.Id),
|
||||
zap.Error(err),
|
||||
)
|
||||
return api.errorOld(ctx, err)
|
||||
@ -728,7 +728,7 @@ func (api *API2) SendReport(ctx echo.Context) error {
|
||||
totalAmount += privilege.Amount
|
||||
}
|
||||
data := models.RespGeneratorService{
|
||||
DocNumber: historyMap[historyID] + 1,
|
||||
DocNumber: historyMap[req.Id] + 1,
|
||||
Date: time.Now().Format("2006-01-02"),
|
||||
OrgTaxNum: verifuser.TaxNumber,
|
||||
OrgName: models.Name{Orgname: "Orgname"},
|
||||
|
@ -402,19 +402,19 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL
|
||||
Handler: si,
|
||||
}
|
||||
|
||||
router.DELETE(baseURL+"/account", wrapper.DeleteAccount)//-
|
||||
router.DELETE(baseURL+"/account", wrapper.DeleteAccount)
|
||||
router.GET(baseURL+"/account", wrapper.GetAccount)
|
||||
router.PATCH(baseURL+"/account", wrapper.ChangeAccount)
|
||||
router.POST(baseURL+"/account", wrapper.AddAccount)
|
||||
router.DELETE(baseURL+"/account/:userId", wrapper.DeleteDirectAccount)//-
|
||||
router.DELETE(baseURL+"/account/:userId", wrapper.DeleteDirectAccount)
|
||||
router.GET(baseURL+"/account/:userId", wrapper.GetDirectAccount)
|
||||
router.PATCH(baseURL+"/account/:userId", wrapper.SetAccountVerificationStatus)
|
||||
router.GET(baseURL+"/accounts", wrapper.PaginationAccounts)
|
||||
router.DELETE(baseURL+"/cart", wrapper.RemoveFromCart)//-
|
||||
router.PATCH(baseURL+"/cart", wrapper.Add2cart)//+
|
||||
router.POST(baseURL+"/cart/pay", wrapper.PayCart)//+
|
||||
router.DELETE(baseURL+"/cart", wrapper.RemoveFromCart)
|
||||
router.PATCH(baseURL+"/cart", wrapper.Add2cart)
|
||||
router.POST(baseURL+"/cart/pay", wrapper.PayCart)
|
||||
router.GET(baseURL+"/currencies", wrapper.GetCurrencies)
|
||||
router.PUT(baseURL+"/currencies", wrapper.UpdateCurrencies)//-
|
||||
router.PUT(baseURL+"/currencies", wrapper.UpdateCurrencies)
|
||||
router.GET(baseURL+"/history", wrapper.GetHistory)
|
||||
router.POST(baseURL+"/history/ltv", wrapper.CalculateLTV)
|
||||
router.GET(baseURL+"/recent", wrapper.GetRecentTariffs)
|
||||
|
@ -20,9 +20,9 @@ func TestSendReport(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
historyID := "641b2d73e0e07a7e90b59616"
|
||||
historyID := "65bb62f606b4708f85c7d152"
|
||||
|
||||
token, tokenErr := jwtUtil.Create("64e5d9830fcca0596d82c0c1")
|
||||
token, tokenErr := jwtUtil.Create("64e5d9830fcca0596d82c0c7")
|
||||
assert.NoError(t, tokenErr)
|
||||
|
||||
responseSendReport, errSendReport := client.Post[interface{}, models.ResponseErrorHTTP](ctx, &client.RequestSettings{
|
||||
|
Loading…
Reference in New Issue
Block a user