Use FlagManager instead of asm flagparser directly
This commit is contained in:
parent
ecac4ae009
commit
879baa03fc
@ -8,11 +8,11 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
|
|
||||||
"git.defalsify.org/vise.git/logging"
|
"git.defalsify.org/vise.git/logging"
|
||||||
"git.defalsify.org/vise.git/asm"
|
|
||||||
|
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
|
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
|
||||||
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/internal/cmd"
|
"git.grassecon.net/grassrootseconomics/sarafu-vise/internal/cmd"
|
||||||
|
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/application"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -41,10 +41,9 @@ func main() {
|
|||||||
}
|
}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||||
|
|
||||||
pfp := path.Join(scriptDir, "pp.csv")
|
pfp := path.Join(scriptDir, "pp.csv")
|
||||||
flagParser := asm.NewFlagParser().WithDebug()
|
flagParser, err := application.NewFlagManager(pfp)
|
||||||
_, err = flagParser.Load(pfp)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "flagparser fail: %v\n", err)
|
fmt.Fprintf(os.Stderr, "flagparser fail: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -40,7 +40,7 @@ var (
|
|||||||
// TODO: this is only in use in testing, should be moved to test domain and/or replaced by asm.FlagParser
|
// TODO: this is only in use in testing, should be moved to test domain and/or replaced by asm.FlagParser
|
||||||
// FlagManager handles centralized flag management
|
// FlagManager handles centralized flag management
|
||||||
type FlagManager struct {
|
type FlagManager struct {
|
||||||
parser *asm.FlagParser
|
*asm.FlagParser
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFlagManager creates a new FlagManager instance
|
// NewFlagManager creates a new FlagManager instance
|
||||||
@ -52,13 +52,17 @@ func NewFlagManager(csvPath string) (*FlagManager, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &FlagManager{
|
return &FlagManager{
|
||||||
parser: parser,
|
FlagParser: parser,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fm *FlagManager) SetDebug() {
|
||||||
|
fm.FlagParser = fm.FlagParser.WithDebug()
|
||||||
|
}
|
||||||
|
|
||||||
// GetFlag retrieves a flag value by its label
|
// GetFlag retrieves a flag value by its label
|
||||||
func (fm *FlagManager) GetFlag(label string) (uint32, error) {
|
func (fm *FlagManager) GetFlag(label string) (uint32, error) {
|
||||||
return fm.parser.GetFlag(label)
|
return fm.FlagParser.GetFlag(label)
|
||||||
}
|
}
|
||||||
|
|
||||||
type MenuHandlers struct {
|
type MenuHandlers struct {
|
||||||
@ -67,7 +71,7 @@ type MenuHandlers struct {
|
|||||||
ca cache.Memory
|
ca cache.Memory
|
||||||
userdataStore store.DataStore
|
userdataStore store.DataStore
|
||||||
adminstore *store.AdminStore
|
adminstore *store.AdminStore
|
||||||
flagManager *asm.FlagParser
|
flagManager *FlagManager
|
||||||
accountService remote.AccountService
|
accountService remote.AccountService
|
||||||
prefixDb storedb.PrefixDb
|
prefixDb storedb.PrefixDb
|
||||||
profile *profile.Profile
|
profile *profile.Profile
|
||||||
@ -75,7 +79,7 @@ type MenuHandlers struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewHandlers creates a new instance of the Handlers struct with the provided dependencies.
|
// NewHandlers creates a new instance of the Handlers struct with the provided dependencies.
|
||||||
func NewMenuHandlers(appFlags *asm.FlagParser, userdataStore db.Db, adminstore *store.AdminStore, accountService remote.AccountService, replaceSeparatorFunc func(string) string) (*MenuHandlers, error) {
|
func NewMenuHandlers(appFlags *FlagManager, userdataStore db.Db, adminstore *store.AdminStore, accountService remote.AccountService, replaceSeparatorFunc func(string) string) (*MenuHandlers, error) {
|
||||||
if userdataStore == nil {
|
if userdataStore == nil {
|
||||||
return nil, fmt.Errorf("cannot create handler with nil userdata store")
|
return nil, fmt.Errorf("cannot create handler with nil userdata store")
|
||||||
}
|
}
|
||||||
|
@ -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.parser, store, nil, &accountService, mockReplaceSeparator)
|
handlers, err := NewMenuHandlers(fm, store, nil, &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.parser, nil, nil, &accountService, mockReplaceSeparator)
|
handlers, err := NewMenuHandlers(fm, nil, nil, &accountService, mockReplaceSeparator)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected an error, got none")
|
t.Fatal("expected an error, got none")
|
||||||
}
|
}
|
||||||
@ -161,7 +161,7 @@ func TestInit(t *testing.T) {
|
|||||||
setup: func() (*MenuHandlers, context.Context) {
|
setup: func() (*MenuHandlers, context.Context) {
|
||||||
pe := persist.NewPersister(testStore).WithSession(sessionId).WithContent(st, ca)
|
pe := persist.NewPersister(testStore).WithSession(sessionId).WithContent(st, ca)
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
adminstore: adminstore,
|
adminstore: adminstore,
|
||||||
pe: pe,
|
pe: pe,
|
||||||
}
|
}
|
||||||
@ -177,7 +177,7 @@ func TestInit(t *testing.T) {
|
|||||||
setup: func() (*MenuHandlers, context.Context) {
|
setup: func() (*MenuHandlers, context.Context) {
|
||||||
pe := persist.NewPersister(testStore).WithSession("0712345678").WithContent(st, ca)
|
pe := persist.NewPersister(testStore).WithSession("0712345678").WithContent(st, ca)
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
adminstore: adminstore,
|
adminstore: adminstore,
|
||||||
pe: pe,
|
pe: pe,
|
||||||
}
|
}
|
||||||
@ -193,7 +193,7 @@ func TestInit(t *testing.T) {
|
|||||||
setup: func() (*MenuHandlers, context.Context) {
|
setup: func() (*MenuHandlers, context.Context) {
|
||||||
pe := persist.NewPersister(testStore).WithSession(sessionId).WithContent(st, ca)
|
pe := persist.NewPersister(testStore).WithSession(sessionId).WithContent(st, ca)
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
adminstore: adminstore,
|
adminstore: adminstore,
|
||||||
pe: pe,
|
pe: pe,
|
||||||
}
|
}
|
||||||
@ -256,7 +256,7 @@ func TestCreateAccount(t *testing.T) {
|
|||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
accountService: mockAccountService,
|
accountService: mockAccountService,
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
}
|
}
|
||||||
|
|
||||||
mockAccountService.On("CreateAccount").Return(tt.serverResponse, nil)
|
mockAccountService.On("CreateAccount").Return(tt.serverResponse, nil)
|
||||||
@ -320,7 +320,7 @@ func TestSaveFirstname(t *testing.T) {
|
|||||||
// Create the MenuHandlers instance with the mock store
|
// Create the MenuHandlers instance with the mock store
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
st: mockState,
|
st: mockState,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -365,7 +365,7 @@ func TestSaveFamilyname(t *testing.T) {
|
|||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
st: mockState,
|
st: mockState,
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the method
|
// Call the method
|
||||||
@ -408,7 +408,7 @@ func TestSaveYoB(t *testing.T) {
|
|||||||
// Create the MenuHandlers instance with the mock store
|
// Create the MenuHandlers instance with the mock store
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
st: mockState,
|
st: mockState,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -452,7 +452,7 @@ func TestSaveLocation(t *testing.T) {
|
|||||||
// Create the MenuHandlers instance with the mock store
|
// Create the MenuHandlers instance with the mock store
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
st: mockState,
|
st: mockState,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -496,7 +496,7 @@ func TestSaveOfferings(t *testing.T) {
|
|||||||
// Create the MenuHandlers instance with the mock store
|
// Create the MenuHandlers instance with the mock store
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
st: mockState,
|
st: mockState,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -564,7 +564,7 @@ func TestSaveGender(t *testing.T) {
|
|||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
st: mockState,
|
st: mockState,
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedResult := resource.Result{}
|
expectedResult := resource.Result{}
|
||||||
@ -595,11 +595,11 @@ func TestSaveTemporaryPin(t *testing.T) {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
flag_incorrect_pin, _ := fm.parser.GetFlag("flag_incorrect_pin")
|
flag_incorrect_pin, _ := fm.GetFlag("flag_incorrect_pin")
|
||||||
|
|
||||||
// Create the MenuHandlers instance with the mock flag manager
|
// Create the MenuHandlers instance with the mock flag manager
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -812,7 +812,7 @@ func TestSetLanguage(t *testing.T) {
|
|||||||
|
|
||||||
// Create the MenuHandlers instance with the mock flag manager
|
// Create the MenuHandlers instance with the mock flag manager
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
st: mockState,
|
st: mockState,
|
||||||
}
|
}
|
||||||
@ -846,7 +846,7 @@ func TestResetAllowUpdate(t *testing.T) {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
flag_allow_update, _ := fm.parser.GetFlag("flag_allow_update")
|
flag_allow_update, _ := fm.GetFlag("flag_allow_update")
|
||||||
|
|
||||||
// Define test cases
|
// Define test cases
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
@ -867,7 +867,7 @@ func TestResetAllowUpdate(t *testing.T) {
|
|||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
// Create the MenuHandlers instance with the mock flag manager
|
// Create the MenuHandlers instance with the mock flag manager
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the method
|
// Call the method
|
||||||
@ -888,7 +888,7 @@ func TestResetAccountAuthorized(t *testing.T) {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
flag_account_authorized, _ := fm.parser.GetFlag("flag_account_authorized")
|
flag_account_authorized, _ := fm.GetFlag("flag_account_authorized")
|
||||||
|
|
||||||
// Define test cases
|
// Define test cases
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
@ -909,7 +909,7 @@ func TestResetAccountAuthorized(t *testing.T) {
|
|||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
// Create the MenuHandlers instance with the mock flag manager
|
// Create the MenuHandlers instance with the mock flag manager
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the method
|
// Call the method
|
||||||
@ -933,8 +933,8 @@ func TestIncorrectPinReset(t *testing.T) {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
flag_incorrect_pin, _ := fm.parser.GetFlag("flag_incorrect_pin")
|
flag_incorrect_pin, _ := fm.GetFlag("flag_incorrect_pin")
|
||||||
flag_account_blocked, _ := fm.parser.GetFlag("flag_account_blocked")
|
flag_account_blocked, _ := fm.GetFlag("flag_account_blocked")
|
||||||
|
|
||||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||||
|
|
||||||
@ -992,7 +992,7 @@ func TestIncorrectPinReset(t *testing.T) {
|
|||||||
|
|
||||||
// Create the MenuHandlers instance with the mock flag manager
|
// Create the MenuHandlers instance with the mock flag manager
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1014,7 +1014,7 @@ func TestResetIncorrectYob(t *testing.T) {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
flag_incorrect_date_format, _ := fm.parser.GetFlag("flag_incorrect_date_format")
|
flag_incorrect_date_format, _ := fm.GetFlag("flag_incorrect_date_format")
|
||||||
|
|
||||||
// Define test cases
|
// Define test cases
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
@ -1035,7 +1035,7 @@ func TestResetIncorrectYob(t *testing.T) {
|
|||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
// Create the MenuHandlers instance with the mock flag manager
|
// Create the MenuHandlers instance with the mock flag manager
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the method
|
// Call the method
|
||||||
@ -1073,7 +1073,7 @@ func TestAuthorize(t *testing.T) {
|
|||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
accountService: mockAccountService,
|
accountService: mockAccountService,
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
st: mockState,
|
st: mockState,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1141,12 +1141,12 @@ func TestVerifyYob(t *testing.T) {
|
|||||||
// Create required mocks
|
// Create required mocks
|
||||||
mockAccountService := new(mocks.MockAccountService)
|
mockAccountService := new(mocks.MockAccountService)
|
||||||
mockState := state.NewState(16)
|
mockState := state.NewState(16)
|
||||||
flag_incorrect_date_format, _ := fm.parser.GetFlag("flag_incorrect_date_format")
|
flag_incorrect_date_format, _ := fm.GetFlag("flag_incorrect_date_format")
|
||||||
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
||||||
|
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
accountService: mockAccountService,
|
accountService: mockAccountService,
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
st: mockState,
|
st: mockState,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1206,14 +1206,14 @@ func TestVerifyCreatePin(t *testing.T) {
|
|||||||
mockAccountService := new(mocks.MockAccountService)
|
mockAccountService := new(mocks.MockAccountService)
|
||||||
mockState := state.NewState(16)
|
mockState := state.NewState(16)
|
||||||
|
|
||||||
flag_valid_pin, _ := fm.parser.GetFlag("flag_valid_pin")
|
flag_valid_pin, _ := fm.GetFlag("flag_valid_pin")
|
||||||
flag_pin_mismatch, _ := fm.parser.GetFlag("flag_pin_mismatch")
|
flag_pin_mismatch, _ := fm.GetFlag("flag_pin_mismatch")
|
||||||
flag_pin_set, _ := fm.parser.GetFlag("flag_pin_set")
|
flag_pin_set, _ := fm.GetFlag("flag_pin_set")
|
||||||
|
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
accountService: mockAccountService,
|
accountService: mockAccountService,
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
st: mockState,
|
st: mockState,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1307,7 +1307,7 @@ func TestCheckAccountStatus(t *testing.T) {
|
|||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
accountService: mockAccountService,
|
accountService: mockAccountService,
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = store.WriteEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY, []byte(tt.publicKey))
|
err = store.WriteEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY, []byte(tt.publicKey))
|
||||||
@ -1347,7 +1347,7 @@ func TestTransactionReset(t *testing.T) {
|
|||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
accountService: mockAccountService,
|
accountService: mockAccountService,
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@ -1387,14 +1387,14 @@ func TestResetTransactionAmount(t *testing.T) {
|
|||||||
t.Logf(err.Error())
|
t.Logf(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
flag_invalid_amount, _ := fm.parser.GetFlag("flag_invalid_amount")
|
flag_invalid_amount, _ := fm.GetFlag("flag_invalid_amount")
|
||||||
|
|
||||||
mockAccountService := new(mocks.MockAccountService)
|
mockAccountService := new(mocks.MockAccountService)
|
||||||
|
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
accountService: mockAccountService,
|
accountService: mockAccountService,
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
@ -1431,14 +1431,14 @@ func TestInitiateTransaction(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Logf(err.Error())
|
t.Logf(err.Error())
|
||||||
}
|
}
|
||||||
account_authorized_flag, _ := fm.parser.GetFlag("flag_account_authorized")
|
account_authorized_flag, _ := fm.GetFlag("flag_account_authorized")
|
||||||
|
|
||||||
mockAccountService := new(mocks.MockAccountService)
|
mockAccountService := new(mocks.MockAccountService)
|
||||||
|
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
accountService: mockAccountService,
|
accountService: mockAccountService,
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
@ -1524,7 +1524,7 @@ func TestQuit(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Logf(err.Error())
|
t.Logf(err.Error())
|
||||||
}
|
}
|
||||||
flag_account_authorized, _ := fm.parser.GetFlag("flag_account_authorized")
|
flag_account_authorized, _ := fm.GetFlag("flag_account_authorized")
|
||||||
|
|
||||||
mockAccountService := new(mocks.MockAccountService)
|
mockAccountService := new(mocks.MockAccountService)
|
||||||
|
|
||||||
@ -1534,7 +1534,7 @@ func TestQuit(t *testing.T) {
|
|||||||
|
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
accountService: mockAccountService,
|
accountService: mockAccountService,
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@ -1577,14 +1577,14 @@ func TestValidateAmount(t *testing.T) {
|
|||||||
ctx, store := InitializeTestStore(t)
|
ctx, store := InitializeTestStore(t)
|
||||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||||
|
|
||||||
flag_invalid_amount, _ := fm.parser.GetFlag("flag_invalid_amount")
|
flag_invalid_amount, _ := fm.GetFlag("flag_invalid_amount")
|
||||||
|
|
||||||
mockAccountService := new(mocks.MockAccountService)
|
mockAccountService := new(mocks.MockAccountService)
|
||||||
|
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
accountService: mockAccountService,
|
accountService: mockAccountService,
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@ -1651,8 +1651,8 @@ func TestValidateRecipient(t *testing.T) {
|
|||||||
ctx, store := InitializeTestStore(t)
|
ctx, store := InitializeTestStore(t)
|
||||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||||
|
|
||||||
flag_invalid_recipient, _ := fm.parser.GetFlag("flag_invalid_recipient")
|
flag_invalid_recipient, _ := fm.GetFlag("flag_invalid_recipient")
|
||||||
flag_invalid_recipient_with_invite, _ := fm.parser.GetFlag("flag_invalid_recipient_with_invite")
|
flag_invalid_recipient_with_invite, _ := fm.GetFlag("flag_invalid_recipient_with_invite")
|
||||||
|
|
||||||
// Define test cases
|
// Define test cases
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
@ -1704,7 +1704,7 @@ func TestValidateRecipient(t *testing.T) {
|
|||||||
mockAccountService := new(mocks.MockAccountService)
|
mockAccountService := new(mocks.MockAccountService)
|
||||||
// Create the MenuHandlers instance
|
// Create the MenuHandlers instance
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
accountService: mockAccountService,
|
accountService: mockAccountService,
|
||||||
}
|
}
|
||||||
@ -1867,10 +1867,10 @@ func TestVerifyNewPin(t *testing.T) {
|
|||||||
|
|
||||||
fm, _ := NewFlagManager(flagsPath)
|
fm, _ := NewFlagManager(flagsPath)
|
||||||
|
|
||||||
flag_valid_pin, _ := fm.parser.GetFlag("flag_valid_pin")
|
flag_valid_pin, _ := fm.GetFlag("flag_valid_pin")
|
||||||
mockAccountService := new(mocks.MockAccountService)
|
mockAccountService := new(mocks.MockAccountService)
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
accountService: mockAccountService,
|
accountService: mockAccountService,
|
||||||
}
|
}
|
||||||
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
||||||
@ -1913,11 +1913,11 @@ func TestConfirmPin(t *testing.T) {
|
|||||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||||
|
|
||||||
fm, _ := NewFlagManager(flagsPath)
|
fm, _ := NewFlagManager(flagsPath)
|
||||||
flag_pin_mismatch, _ := fm.parser.GetFlag("flag_pin_mismatch")
|
flag_pin_mismatch, _ := fm.GetFlag("flag_pin_mismatch")
|
||||||
mockAccountService := new(mocks.MockAccountService)
|
mockAccountService := new(mocks.MockAccountService)
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
accountService: mockAccountService,
|
accountService: mockAccountService,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2047,7 +2047,7 @@ func TestSetDefaultVoucher(t *testing.T) {
|
|||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
accountService: mockAccountService,
|
accountService: mockAccountService,
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := store.WriteEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY, []byte(publicKey))
|
err := store.WriteEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY, []byte(publicKey))
|
||||||
@ -2155,7 +2155,7 @@ func TestViewVoucher(t *testing.T) {
|
|||||||
|
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
prefixDb: spdb,
|
prefixDb: spdb,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2228,7 +2228,7 @@ func TestGetVoucherDetails(t *testing.T) {
|
|||||||
|
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
flagManager: fm.parser,
|
flagManager: fm,
|
||||||
accountService: mockAccountService,
|
accountService: mockAccountService,
|
||||||
}
|
}
|
||||||
err = store.WriteEntry(ctx, sessionId, storedb.DATA_ACTIVE_ADDRESS, []byte(tokA_AAddress))
|
err = store.WriteEntry(ctx, sessionId, storedb.DATA_ACTIVE_ADDRESS, []byte(tokA_AAddress))
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.defalsify.org/vise.git/asm"
|
|
||||||
"git.defalsify.org/vise.git/db"
|
"git.defalsify.org/vise.git/db"
|
||||||
"git.defalsify.org/vise.git/engine"
|
"git.defalsify.org/vise.git/engine"
|
||||||
"git.defalsify.org/vise.git/persist"
|
"git.defalsify.org/vise.git/persist"
|
||||||
@ -19,17 +18,8 @@ type HandlerService interface {
|
|||||||
GetHandler() (*application.MenuHandlers, error)
|
GetHandler() (*application.MenuHandlers, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getParser(fp string, debug bool) (*asm.FlagParser, error) {
|
|
||||||
flagParser := asm.NewFlagParser().WithDebug()
|
|
||||||
_, err := flagParser.Load(fp)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return flagParser, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type LocalHandlerService struct {
|
type LocalHandlerService struct {
|
||||||
Parser *asm.FlagParser
|
Parser *application.FlagManager
|
||||||
DbRs *resource.DbResource
|
DbRs *resource.DbResource
|
||||||
Pe *persist.Persister
|
Pe *persist.Persister
|
||||||
UserdataStore *db.Db
|
UserdataStore *db.Db
|
||||||
@ -39,10 +29,13 @@ type LocalHandlerService struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewLocalHandlerService(ctx context.Context, fp string, debug bool, dbResource *resource.DbResource, cfg engine.Config, rs resource.Resource) (*LocalHandlerService, error) {
|
func NewLocalHandlerService(ctx context.Context, fp string, debug bool, dbResource *resource.DbResource, cfg engine.Config, rs resource.Resource) (*LocalHandlerService, error) {
|
||||||
parser, err := getParser(fp, debug)
|
parser, err := application.NewFlagManager(fp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if debug {
|
||||||
|
parser.SetDebug()
|
||||||
|
}
|
||||||
adminstore, err := store.NewAdminStore(ctx, "admin_numbers")
|
adminstore, err := store.NewAdminStore(ctx, "admin_numbers")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -4,9 +4,9 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.defalsify.org/vise.git/asm"
|
|
||||||
"git.defalsify.org/vise.git/logging"
|
"git.defalsify.org/vise.git/logging"
|
||||||
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
||||||
|
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/application"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -16,13 +16,13 @@ var (
|
|||||||
type Cmd struct {
|
type Cmd struct {
|
||||||
sessionId string
|
sessionId string
|
||||||
conn storage.ConnData
|
conn storage.ConnData
|
||||||
flagParser *asm.FlagParser
|
flagParser *application.FlagManager
|
||||||
cmd int
|
cmd int
|
||||||
enable bool
|
enable bool
|
||||||
exec func(ctx context.Context, ss storage.StorageService) error
|
exec func(ctx context.Context, ss storage.StorageService) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCmd(conn storage.ConnData, sessionId string, flagParser *asm.FlagParser) *Cmd {
|
func NewCmd(conn storage.ConnData, sessionId string, flagParser *application.FlagManager) *Cmd {
|
||||||
return &Cmd{
|
return &Cmd{
|
||||||
conn: conn,
|
conn: conn,
|
||||||
sessionId: sessionId,
|
sessionId: sessionId,
|
||||||
|
Loading…
Reference in New Issue
Block a user