29 lines
490 B
Go
29 lines
490 B
Go
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, jwtErr := VerifyJWT(token)
|
|
if jwtErr != nil {
|
|
t.Fatalf("Failed to verify token: %v", jwtErr)
|
|
}
|
|
|
|
assert.Equal(t, claims.AccountId, 1)
|
|
assert.Equal(t, claims.RoleId, 1)
|
|
}
|