add jwt helpers test
All checks were successful
ci/woodpecker/push/lint Pipeline was successful
ci/woodpecker/push/tests Pipeline was successful
ci/woodpecker/push/build Pipeline was successful

This commit is contained in:
qpismont 2025-02-26 20:21:12 +00:00
parent 997a79fcbe
commit 3adfcc890f
2 changed files with 31 additions and 2 deletions

View file

@ -6,8 +6,8 @@ import (
type JWTClaims struct { type JWTClaims struct {
jwt.RegisteredClaims jwt.RegisteredClaims
AccountId string `json:"account_id"` AccountId int `json:"account_id"`
RoleId string `json:"role_id"` RoleId int `json:"role_id"`
} }
var jwtSecret string var jwtSecret string

29
internal/core/jwt_test.go Normal file
View file

@ -0,0 +1,29 @@
package core
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestJWT_GenerateToken(t *testing.T) {
InitJWT("secret")
token, err := SignJWT(JWTClaims{
AccountId: 1,
RoleId: 1,
})
if err != nil {
t.Fatalf("Failed to generate token: %v", err)
}
assert.NotEmpty(t, token)
claims, err := VerifyJWT(token)
if err != nil {
t.Fatalf("Failed to verify token: %v", err)
}
assert.Equal(t, claims.AccountId, 1)
assert.Equal(t, claims.RoleId, 1)
}