package keeper_test

import (
	"testing"

    sdk "github.com/cosmos/cosmos-sdk/types"
	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)

	for i := 0; i < 5; i++ {
		resp, err := srv.Create<%= TypeName.PascalCase %>(f.ctx, &types.MsgCreate<%= TypeName.PascalCase %>{<%= MsgSigner.UpperCamel %>: <%= MsgSigner.LowerCamel %>})
		require.NoError(t, err)
		require.Equal(t, i, int(resp.Id))
	}
}

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)

	_, 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.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:    "key not found",
			request: &types.MsgUpdate<%= TypeName.PascalCase %>{<%= MsgSigner.UpperCamel %>: <%= MsgSigner.LowerCamel %>, Id: 10},
			err:     sdkerrors.ErrKeyNotFound,
		},
		{
			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)
			}
		})
	}
}

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:    "key not found",
			request: &types.MsgDelete<%= TypeName.PascalCase %>{<%= MsgSigner.UpperCamel %>: <%= MsgSigner.LowerCamel %>, Id: 10},
			err:     sdkerrors.ErrKeyNotFound,
		},
		{
			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)
			}
		})
	}
}
