// Copyright 2024 Patial Tech. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package user import ( "errors" "testing" "time" ) func FuzzNewVerifyEmailToken(f *testing.F) { f.Add(int64(123)) f.Fuzz(func(t *testing.T, userID int64) { _, err := newTokenToVerifyEmail(userID, time.Millisecond*100) if err != nil { t.Errorf("failed for input %d, %v", userID, err) } }) } func TestEmailToken(t *testing.T) { uID := int64(1234) // create a token t1, err := newTokenToVerifyEmail(uID, time.Millisecond*100) if err != nil { t.Error(err) return } // let decode token id, err := tokenToVerifyEmail(t1) if err != nil { t.Error(err) return } else if uID != id { t.Error("uid and decoded id are not same, ", uID, "!=", id) } // lets wait and try decode again time.Sleep(time.Millisecond * 100) _, err = tokenToVerifyEmail(t1) if !errors.Is(err, ErrExpiredToken) { t.Error("expected expired token error") } }