package main

import (
	"testing"
	"time"

	"github.com/stretchr/testify/require"
)

type TestMail struct{}

func (m TestMail) SendCode(to string, code string) error {
	return nil
}

var testMailer = TestMail{}

func TestCreateCode(t *testing.T) {
	require := require.New(t)

	auth := CreateAuth(testMailer)

	err := auth.CreateCode("test")
	require.NoError(err)

	code, exists := auth.codes["test"]
	require.True(exists)
	require.True(code.Valid.After(time.Now()))
	require.True(auth.IsCodeValid("test", code.Code))
}
