package keeper_test

import (
	"testing"

	sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
	"github.com/stretchr/testify/require"

    "<%= ModulePath %>/x/<%= ModuleName %>/keeper"
    "<%= ModulePath %>/x/<%= ModuleName %>/types"
)

func Test<%= TypeName.PascalCase %>MsgServerCreate(t *testing.T) {
	f := initFixture(t)
	srv := keeper.NewMsgServerImpl(f.keeper)

	<%= MsgSigner.LowerCamel %>, err := f.addressCodec.BytesToString([]byte("signerAddr__________________"))
	require.NoError(t, err)
	expected := &types.MsgCreate<%= TypeName.PascalCase %>{<%= MsgSigner.UpperCamel %>: <%= MsgSigner.LowerCamel %>}
    _, err = srv.Create<%= TypeName.PascalCase %>(f.ctx, expected)
    require.NoError(t, err)
    rst, err := f.keeper.<%= TypeName.UpperCamel %>.Get(f.ctx)
    require.Nil(t, err)
    require.Equal(t, expected.<%= MsgSigner.UpperCamel %>, rst.<%= MsgSigner.UpperCamel %>)
}

func Test<%= TypeName.PascalCase %>MsgServerUpdate(t *testing.T) {
	f := initFixture(t)
	srv := keeper.NewMsgServerImpl(f.keeper)
	
	<%= MsgSigner.LowerCamel %>, err := f.addressCodec.BytesToString([]byte("signerAddr__________________"))
	require.NoError(t, err)

	unauthorizedAddr, err := f.addressCodec.BytesToString([]byte("unauthorizedAddr___________"))
	require.NoError(t, err)

	expected := &types.MsgCreate<%= TypeName.PascalCase %>{<%= MsgSigner.UpperCamel %>: <%= MsgSigner.LowerCamel %>}
	_, err = srv.Create<%= TypeName.PascalCase %>(f.ctx, expected)
	require.NoError(t, err)

	tests := []struct {
		desc    string
		request *types.MsgUpdate<%= TypeName.PascalCase %>
		err     error
	}{
		{
			desc:    "invalid address",
			request: &types.MsgUpdate<%= TypeName.PascalCase %>{<%= MsgSigner.UpperCamel %>: "invalid"},
			err:     sdkerrors.ErrInvalidAddress,
		},
		{
			desc:    "unauthorized",
			request: &types.MsgUpdate<%= TypeName.PascalCase %>{<%= MsgSigner.UpperCamel %>: unauthorizedAddr},
			err:     sdkerrors.ErrUnauthorized,
		},
		{
			desc:    "completed",
			request: &types.MsgUpdate<%= TypeName.PascalCase %>{<%= MsgSigner.UpperCamel %>: <%= MsgSigner.LowerCamel %>},
		},
	}
	for _, tc := range tests {
		t.Run(tc.desc, func(t *testing.T) {
			_, err = srv.Update<%= TypeName.PascalCase %>(f.ctx, tc.request)
			if tc.err != nil {
				require.ErrorIs(t, err, tc.err)
			} else {
				require.NoError(t, err)
				rst, err := f.keeper.<%= TypeName.UpperCamel %>.Get(f.ctx)
				require.Nil(t, err)
				require.Equal(t, expected.<%= MsgSigner.UpperCamel %>, rst.<%= MsgSigner.UpperCamel %>)
			}
		})
	}
}

func Test<%= TypeName.PascalCase %>MsgServerDelete(t *testing.T) {
	f := initFixture(t)
	srv := keeper.NewMsgServerImpl(f.keeper)
	
	<%= MsgSigner.LowerCamel %>, err := f.addressCodec.BytesToString([]byte("signerAddr__________________"))
	require.NoError(t, err)

	unauthorizedAddr, err := f.addressCodec.BytesToString([]byte("unauthorizedAddr___________"))
	require.NoError(t, err)

	_, err = srv.Create<%= TypeName.PascalCase %>(f.ctx, &types.MsgCreate<%= TypeName.PascalCase %>{<%= MsgSigner.UpperCamel %>: <%= MsgSigner.LowerCamel %>})
	require.NoError(t, err)

	tests := []struct {
		desc    string
		request *types.MsgDelete<%= TypeName.PascalCase %>
		err     error
	}{
		{
			desc:    "invalid address",
			request: &types.MsgDelete<%= TypeName.PascalCase %>{<%= MsgSigner.UpperCamel %>: "invalid"},
			err:     sdkerrors.ErrInvalidAddress,
		},
		{
			desc:    "unauthorized",
			request: &types.MsgDelete<%= TypeName.PascalCase %>{<%= MsgSigner.UpperCamel %>: unauthorizedAddr},
			err:     sdkerrors.ErrUnauthorized,
		},
		{
			desc:    "completed",
			request: &types.MsgDelete<%= TypeName.PascalCase %>{<%= MsgSigner.UpperCamel %>: <%= MsgSigner.LowerCamel %>},
		},
	}
	for _, tc := range tests {
		t.Run(tc.desc, func(t *testing.T) {
			_, err = srv.Delete<%= TypeName.PascalCase %>(f.ctx, tc.request)
			if tc.err != nil {
				require.ErrorIs(t, err, tc.err)
			} else {
				require.NoError(t, err)
				found, err := f.keeper.<%= TypeName.UpperCamel %>.Has(f.ctx)
				require.NoError(t, err)
				require.False(t, found)
			}
		})
	}
}
