Merge pull request 'alfred/test-updates' (#15) from alfred/test-updates into master
Reviewed-on: #15
This commit is contained in:
commit
bed7f58e81
@ -102,14 +102,12 @@ func NewMenuHandlers(appFlags *FlagManager, userdataStore db.Db, accountService
|
||||
return h, nil
|
||||
}
|
||||
|
||||
// WithPersister sets persister instance to the handlers.
|
||||
// func (h *MenuHandlers) WithPersister(pe *persist.Persister) *MenuHandlers {
|
||||
// SetPersister sets persister instance to the handlers.
|
||||
func (h *MenuHandlers) SetPersister(pe *persist.Persister) {
|
||||
if h.pe != nil {
|
||||
panic("persister already set")
|
||||
}
|
||||
h.pe = pe
|
||||
//return h
|
||||
}
|
||||
|
||||
// Init initializes the handler for a new session.
|
||||
@ -2307,6 +2305,7 @@ func (h *MenuHandlers) ViewTransactionStatement(ctx context.Context, sym string,
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// persistInitialLanguageCode receives an initial language code and persists it to the store
|
||||
func (h *MenuHandlers) persistInitialLanguageCode(ctx context.Context, sessionId string, code string) error {
|
||||
store := h.userdataStore
|
||||
_, err := store.ReadEntry(ctx, sessionId, storedb.DATA_INITIAL_LANGUAGE_CODE)
|
||||
@ -2339,6 +2338,8 @@ func (h *MenuHandlers) persistLanguageCode(ctx context.Context, code string) err
|
||||
return h.persistInitialLanguageCode(ctx, sessionId, code)
|
||||
}
|
||||
|
||||
// constructAccountAlias retrieves and alias based on the first and family name
|
||||
// and writes the result in DATA_ACCOUNT_ALIAS
|
||||
func (h *MenuHandlers) constructAccountAlias(ctx context.Context) error {
|
||||
var alias string
|
||||
store := h.userdataStore
|
||||
@ -2383,6 +2384,8 @@ func (h *MenuHandlers) constructAccountAlias(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearTemporaryValue empties the DATA_TEMPORARY_VALUE at the main menu to prevent
|
||||
// previously stored data from being accessed
|
||||
func (h *MenuHandlers) ClearTemporaryValue(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
var res resource.Result
|
||||
sessionId, ok := ctx.Value("SessionId").(string)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -66,7 +66,6 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//appHandlers = appHandlers.WithPersister(ls.Pe)
|
||||
appHandlers.SetPersister(ls.Pe)
|
||||
ls.DbRs.AddLocalFunc("check_blocked_status", appHandlers.CheckBlockedStatus)
|
||||
ls.DbRs.AddLocalFunc("set_language", appHandlers.SetLanguage)
|
||||
|
42
profile/profile_test.go
Normal file
42
profile/profile_test.go
Normal file
@ -0,0 +1,42 @@
|
||||
package profile
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/alecthomas/assert/v2"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestInsertOrShift(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
profile Profile
|
||||
index int
|
||||
value string
|
||||
expected []string
|
||||
}{
|
||||
{
|
||||
name: "Insert within range",
|
||||
profile: Profile{ProfileItems: []string{"A", "B", "C"}, Max: 5},
|
||||
index: 1,
|
||||
value: "X",
|
||||
expected: []string{"A", "X"},
|
||||
},
|
||||
{
|
||||
name: "Insert beyond range",
|
||||
profile: Profile{ProfileItems: []string{"A"}, Max: 5},
|
||||
index: 3,
|
||||
value: "Y",
|
||||
expected: []string{"A", "0", "0", "Y"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
p := tt.profile
|
||||
p.InsertOrShift(tt.index, tt.value)
|
||||
require.NotNil(t, p.ProfileItems)
|
||||
assert.Equal(t, tt.expected, p.ProfileItems)
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user