updated tests

This commit is contained in:
Alfred Kamanda 2025-01-17 11:45:55 +03:00
parent 4b8505680b
commit 4cc0de59a7
Signed by: Alfred-mk
GPG Key ID: 7EA3D01708908703

View File

@ -14,11 +14,11 @@ import (
"git.defalsify.org/vise.git/persist" "git.defalsify.org/vise.git/persist"
"git.defalsify.org/vise.git/resource" "git.defalsify.org/vise.git/resource"
"git.defalsify.org/vise.git/state" "git.defalsify.org/vise.git/state"
"git.grassecon.net/grassrootseconomics/sarafu-api/models"
"git.grassecon.net/grassrootseconomics/sarafu-api/testutil/testservice"
"git.grassecon.net/grassrootseconomics/sarafu-api/testutil/mocks"
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
"git.grassecon.net/grassrootseconomics/common/pin" "git.grassecon.net/grassrootseconomics/common/pin"
"git.grassecon.net/grassrootseconomics/sarafu-api/models"
"git.grassecon.net/grassrootseconomics/sarafu-api/testutil/mocks"
"git.grassecon.net/grassrootseconomics/sarafu-api/testutil/testservice"
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db" storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
"github.com/alecthomas/assert/v2" "github.com/alecthomas/assert/v2"
@ -84,7 +84,7 @@ func TestNewMenuHandlers(t *testing.T) {
// Test case for valid UserDataStore // Test case for valid UserDataStore
t.Run("Valid UserDataStore", func(t *testing.T) { t.Run("Valid UserDataStore", func(t *testing.T) {
handlers, err := NewMenuHandlers(fm, store, nil, &accountService, mockReplaceSeparator) handlers, err := NewMenuHandlers(fm, store, &accountService, mockReplaceSeparator)
if err != nil { if err != nil {
t.Fatalf("expected no error, got %v", err) t.Fatalf("expected no error, got %v", err)
} }
@ -108,7 +108,7 @@ func TestNewMenuHandlers(t *testing.T) {
// Test case for nil UserDataStore // Test case for nil UserDataStore
t.Run("Nil UserDataStore", func(t *testing.T) { t.Run("Nil UserDataStore", func(t *testing.T) {
handlers, err := NewMenuHandlers(fm, nil, nil, &accountService, mockReplaceSeparator) handlers, err := NewMenuHandlers(fm, nil, &accountService, mockReplaceSeparator)
if err == nil { if err == nil {
t.Fatal("expected an error, got none") t.Fatal("expected an error, got none")
} }
@ -132,16 +132,9 @@ func TestInit(t *testing.T) {
t.Fatal(err.Error()) t.Fatal(err.Error())
} }
adminstore, err := store.NewAdminStore(ctx, "admin_numbers")
if err != nil {
t.Fatal(err.Error())
}
st := state.NewState(128) st := state.NewState(128)
ca := cache.NewCache() ca := cache.NewCache()
flag_admin_privilege, _ := fm.GetFlag("flag_admin_privilege")
tests := []struct { tests := []struct {
name string name string
setup func() (*MenuHandlers, context.Context) setup func() (*MenuHandlers, context.Context)
@ -162,15 +155,12 @@ func TestInit(t *testing.T) {
pe := persist.NewPersister(testStore).WithSession(sessionId).WithContent(st, ca) pe := persist.NewPersister(testStore).WithSession(sessionId).WithContent(st, ca)
h := &MenuHandlers{ h := &MenuHandlers{
flagManager: fm, flagManager: fm,
adminstore: adminstore,
pe: pe, pe: pe,
} }
return h, context.WithValue(ctx, "SessionId", sessionId) return h, context.WithValue(ctx, "SessionId", sessionId)
}, },
input: []byte("1"), input: []byte("1"),
expectedResult: resource.Result{ expectedResult: resource.Result{},
FlagReset: []uint32{flag_admin_privilege},
},
}, },
{ {
name: "Non-admin session initialization", name: "Non-admin session initialization",
@ -178,15 +168,12 @@ func TestInit(t *testing.T) {
pe := persist.NewPersister(testStore).WithSession("0712345678").WithContent(st, ca) pe := persist.NewPersister(testStore).WithSession("0712345678").WithContent(st, ca)
h := &MenuHandlers{ h := &MenuHandlers{
flagManager: fm, flagManager: fm,
adminstore: adminstore,
pe: pe, pe: pe,
} }
return h, context.WithValue(context.Background(), "SessionId", "0712345678") return h, context.WithValue(context.Background(), "SessionId", "0712345678")
}, },
input: []byte("1"), input: []byte("1"),
expectedResult: resource.Result{ expectedResult: resource.Result{},
FlagReset: []uint32{flag_admin_privilege},
},
}, },
{ {
name: "Move to top node on empty input", name: "Move to top node on empty input",
@ -194,16 +181,13 @@ func TestInit(t *testing.T) {
pe := persist.NewPersister(testStore).WithSession(sessionId).WithContent(st, ca) pe := persist.NewPersister(testStore).WithSession(sessionId).WithContent(st, ca)
h := &MenuHandlers{ h := &MenuHandlers{
flagManager: fm, flagManager: fm,
adminstore: adminstore,
pe: pe, pe: pe,
} }
st.Code = []byte("some pending bytecode") st.Code = []byte("some pending bytecode")
return h, context.WithValue(ctx, "SessionId", sessionId) return h, context.WithValue(ctx, "SessionId", sessionId)
}, },
input: []byte(""), input: []byte(""),
expectedResult: resource.Result{ expectedResult: resource.Result{},
FlagReset: []uint32{flag_admin_privilege},
},
}, },
} }