customer/tests/e2e/buy_tariff_test.go

66 lines
2.4 KiB
Go
Raw Normal View History

2023-09-09 22:44:46 +00:00
package e2e_test
import (
"context"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
2024-11-18 07:23:41 +00:00
"gitea.pena/PenaSide/customer/internal/models"
"gitea.pena/PenaSide/customer/pkg/client"
"gitea.pena/PenaSide/customer/tests/helpers"
2023-09-09 22:44:46 +00:00
)
func TestBuyTariff(t *testing.T) {
jwtUtil := helpers.InitializeJWT()
t.Run("Успешная оплата корзины", func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
assert.NotPanics(t, func() {
2024-05-23 15:32:44 +00:00
token, tokenErr := jwtUtil.Create("64ebda4387392e122e5d411f")
2023-09-09 22:44:46 +00:00
if isNoError := assert.NoError(t, tokenErr); !isNoError {
return
}
responseAddCart, errAddCart := client.Patch[models.Account, models.ResponseErrorHTTP](ctx, &client.RequestSettings{
2024-03-11 18:19:39 +00:00
URL: "http://localhost:8082/cart",
2023-09-09 22:44:46 +00:00
Headers: map[string]string{"Authorization": fmt.Sprintf("Bearer %s", token)},
QueryParams: map[string]string{"id": "64e6105384368b75221a5c3e"},
})
if isNoError := assert.NoError(t, errAddCart); !isNoError {
return
}
if isNoRequestError := assert.Nil(t, responseAddCart.Error); !isNoRequestError {
return
}
2024-05-23 15:32:44 +00:00
isUserIDValid := assert.Equal(t, "64ebda4387392e122e5d411f", responseAddCart.Body.UserID)
2023-09-09 22:44:46 +00:00
isCartLengthValid := assert.Equal(t, 1, len(responseAddCart.Body.Cart))
isCartItemValid := assert.Equal(t, "64e6105384368b75221a5c3e", responseAddCart.Body.Cart[0])
if isUserIDValid && isCartItemValid && isCartLengthValid {
responsePay, errPay := client.Post[models.Account, models.ResponseErrorHTTP](ctx, &client.RequestSettings{
2024-03-11 18:19:39 +00:00
URL: "http://localhost:8082/cart/pay",
2023-09-09 22:44:46 +00:00
Headers: map[string]string{"Authorization": fmt.Sprintf("Bearer %s", token)},
})
if isNoError := assert.NoError(t, errPay); !isNoError {
return
}
if isNoRequestError := assert.Nil(t, responsePay.Error); !isNoRequestError {
return
}
2024-05-23 15:32:44 +00:00
assert.Equal(t, "64ebda4387392e122e5d411f", responsePay.Body.UserID)
2023-09-09 22:44:46 +00:00
assert.Equal(t, 0, len(responsePay.Body.Cart))
2024-02-01 09:39:34 +00:00
//assert.Equal(t, responseAddCart.Body.Wallet.Cash-5000, responsePay.Body.Wallet.Cash)
//assert.Equal(t, responseAddCart.Body.Wallet.Money-5000, responsePay.Body.Wallet.Money)
//assert.Equal(t, responseAddCart.Body.Wallet.Spent+5000, responsePay.Body.Wallet.Spent)
2023-09-09 22:44:46 +00:00
assert.Equal(t, responseAddCart.Body.Wallet.PurchasesAmount, responsePay.Body.Wallet.PurchasesAmount)
assert.Equal(t, "RUB", responsePay.Body.Wallet.Currency)
}
})
})
}