Added a basic homepage
This commit is contained in:
parent
d40640a648
commit
12fd3c04ca
113 changed files with 414 additions and 506 deletions
67
internal/form/form_test.go
Normal file
67
internal/form/form_test.go
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
package form
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/camzawacki/personal-site/internal/context"
|
||||
"github.com/camzawacki/personal-site/internal/tests"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type mockForm struct {
|
||||
called bool
|
||||
Submission
|
||||
}
|
||||
|
||||
func (m *mockForm) Submit(_ echo.Context, _ any) error {
|
||||
m.called = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestSubmit(t *testing.T) {
|
||||
m := mockForm{}
|
||||
ctx, _ := tests.NewContext(echo.New(), "/")
|
||||
err := Submit(ctx, &m)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, m.called)
|
||||
}
|
||||
|
||||
func TestGetClear(t *testing.T) {
|
||||
e := echo.New()
|
||||
|
||||
type example struct {
|
||||
Name string `form:"name"`
|
||||
}
|
||||
|
||||
t.Run("get empty context", func(t *testing.T) {
|
||||
// Empty context, still return a form.
|
||||
ctx, _ := tests.NewContext(e, "/")
|
||||
form := Get[example](ctx)
|
||||
assert.NotNil(t, form)
|
||||
})
|
||||
|
||||
t.Run("get non-empty context", func(t *testing.T) {
|
||||
form := example{
|
||||
Name: "test",
|
||||
}
|
||||
ctx, _ := tests.NewContext(e, "/")
|
||||
ctx.Set(context.FormKey, &form)
|
||||
|
||||
// Get again and expect the values were stored.
|
||||
got := Get[example](ctx)
|
||||
require.NotNil(t, got)
|
||||
assert.Equal(t, "test", got.Name)
|
||||
|
||||
// Attempt getting a different type to ensure there's no panic.
|
||||
ret := Get[int](ctx)
|
||||
require.NotNil(t, ret)
|
||||
|
||||
// Clear.
|
||||
Clear(ctx)
|
||||
got = Get[example](ctx)
|
||||
require.NotNil(t, got)
|
||||
assert.Empty(t, got.Name)
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue