Compare commits
23 Commits
tests-upda
...
wip-menu-s
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
06dc822232
|
||
|
|
371779d74c
|
||
|
|
e8798e1ab2
|
||
|
|
3a14dafb98
|
||
|
|
a7e38727f1
|
||
|
|
3a96c2851c
|
||
|
|
772d33ca29
|
||
|
|
59a072a340
|
||
|
|
05749b493a
|
||
|
|
aec2f3db29
|
||
|
|
0284bc5ef9
|
||
|
|
b54f3f32b5
|
||
|
|
df260c2288
|
||
|
|
ffd091c9a9
|
||
|
|
a20e275db3
|
||
|
|
33f8733106
|
||
|
|
250341a8bd
|
||
|
|
f5ed1ce120
|
||
|
|
5898f8e87a
|
||
|
|
aa18d41c81
|
||
|
|
c75ca1b30b
|
||
|
|
37c62f3d01
|
||
|
|
8feee318b7
|
2
.gitignore
vendored
2
.gitignore
vendored
@@ -4,5 +4,3 @@ go.work*
|
|||||||
**/*/*.bin
|
**/*/*.bin
|
||||||
**/*/.state/
|
**/*/.state/
|
||||||
cmd/.state/
|
cmd/.state/
|
||||||
id_*
|
|
||||||
*.gdbm
|
|
||||||
|
|||||||
@@ -69,11 +69,13 @@ func main() {
|
|||||||
var resourceDir string
|
var resourceDir string
|
||||||
var size uint
|
var size uint
|
||||||
var engineDebug bool
|
var engineDebug bool
|
||||||
|
var stateDebug bool
|
||||||
var host string
|
var host string
|
||||||
var port uint
|
var port uint
|
||||||
flag.StringVar(&dbDir, "dbdir", ".state", "database dir to read from")
|
flag.StringVar(&dbDir, "dbdir", ".state", "database dir to read from")
|
||||||
flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir")
|
flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir")
|
||||||
flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
|
flag.BoolVar(&engineDebug, "engine-debug", false, "use engine debug output")
|
||||||
|
flag.BoolVar(&stateDebug, "state-debug", false, "use engine debug output")
|
||||||
flag.UintVar(&size, "s", 160, "max size of output")
|
flag.UintVar(&size, "s", 160, "max size of output")
|
||||||
flag.StringVar(&host, "h", "127.0.0.1", "http host")
|
flag.StringVar(&host, "h", "127.0.0.1", "http host")
|
||||||
flag.UintVar(&port, "p", 7123, "http port")
|
flag.UintVar(&port, "p", 7123, "http port")
|
||||||
@@ -89,7 +91,9 @@ func main() {
|
|||||||
OutputSize: uint32(size),
|
OutputSize: uint32(size),
|
||||||
FlagCount: uint32(16),
|
FlagCount: uint32(16),
|
||||||
}
|
}
|
||||||
|
if stateDebug {
|
||||||
|
cfg.StateDebug = true
|
||||||
|
}
|
||||||
if engineDebug {
|
if engineDebug {
|
||||||
cfg.EngineDebug = true
|
cfg.EngineDebug = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,12 +41,14 @@ func main() {
|
|||||||
var resourceDir string
|
var resourceDir string
|
||||||
var size uint
|
var size uint
|
||||||
var engineDebug bool
|
var engineDebug bool
|
||||||
|
var stateDebug bool
|
||||||
var host string
|
var host string
|
||||||
var port uint
|
var port uint
|
||||||
flag.StringVar(&sessionId, "session-id", "075xx2123", "session id")
|
flag.StringVar(&sessionId, "session-id", "075xx2123", "session id")
|
||||||
flag.StringVar(&dbDir, "dbdir", ".state", "database dir to read from")
|
flag.StringVar(&dbDir, "dbdir", ".state", "database dir to read from")
|
||||||
flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir")
|
flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir")
|
||||||
flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
|
flag.BoolVar(&engineDebug, "engine-debug", false, "use engine debug output")
|
||||||
|
flag.BoolVar(&stateDebug, "state-debug", false, "use engine debug output")
|
||||||
flag.UintVar(&size, "s", 160, "max size of output")
|
flag.UintVar(&size, "s", 160, "max size of output")
|
||||||
flag.StringVar(&host, "h", "127.0.0.1", "http host")
|
flag.StringVar(&host, "h", "127.0.0.1", "http host")
|
||||||
flag.UintVar(&port, "p", 7123, "http port")
|
flag.UintVar(&port, "p", 7123, "http port")
|
||||||
@@ -62,7 +64,9 @@ func main() {
|
|||||||
OutputSize: uint32(size),
|
OutputSize: uint32(size),
|
||||||
FlagCount: uint32(16),
|
FlagCount: uint32(16),
|
||||||
}
|
}
|
||||||
|
if stateDebug {
|
||||||
|
cfg.StateDebug = true
|
||||||
|
}
|
||||||
if engineDebug {
|
if engineDebug {
|
||||||
cfg.EngineDebug = true
|
cfg.EngineDebug = true
|
||||||
}
|
}
|
||||||
@@ -134,26 +138,22 @@ func main() {
|
|||||||
for true {
|
for true {
|
||||||
rqs, err = sh.Process(rqs)
|
rqs, err = sh.Process(rqs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logg.ErrorCtxf(ctx, "error in process: %v", "err", err)
|
|
||||||
fmt.Errorf("error in process: %v", err)
|
fmt.Errorf("error in process: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
rqs, err = sh.Output(rqs)
|
rqs, err = sh.Output(rqs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logg.ErrorCtxf(ctx, "error in output: %v", "err", err)
|
|
||||||
fmt.Errorf("error in output: %v", err)
|
fmt.Errorf("error in output: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
rqs, err = sh.Reset(rqs)
|
rqs, err = sh.Reset(rqs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logg.ErrorCtxf(ctx, "error in reset: %v", "err", err)
|
|
||||||
fmt.Errorf("error in reset: %v", err)
|
fmt.Errorf("error in reset: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
_, err = fmt.Scanln(&rqs.Input)
|
_, err = fmt.Scanln(&rqs.Input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logg.ErrorCtxf(ctx, "error in input", "err", err)
|
|
||||||
fmt.Errorf("error in input: %v", err)
|
fmt.Errorf("error in input: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,11 +30,13 @@ func main() {
|
|||||||
var resourceDir string
|
var resourceDir string
|
||||||
var size uint
|
var size uint
|
||||||
var engineDebug bool
|
var engineDebug bool
|
||||||
|
var stateDebug bool
|
||||||
var host string
|
var host string
|
||||||
var port uint
|
var port uint
|
||||||
flag.StringVar(&dbDir, "dbdir", ".state", "database dir to read from")
|
flag.StringVar(&dbDir, "dbdir", ".state", "database dir to read from")
|
||||||
flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir")
|
flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir")
|
||||||
flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
|
flag.BoolVar(&engineDebug, "engine-debug", false, "use engine debug output")
|
||||||
|
flag.BoolVar(&stateDebug, "state-debug", false, "use engine debug output")
|
||||||
flag.UintVar(&size, "s", 160, "max size of output")
|
flag.UintVar(&size, "s", 160, "max size of output")
|
||||||
flag.StringVar(&host, "h", "127.0.0.1", "http host")
|
flag.StringVar(&host, "h", "127.0.0.1", "http host")
|
||||||
flag.UintVar(&port, "p", 7123, "http port")
|
flag.UintVar(&port, "p", 7123, "http port")
|
||||||
@@ -50,7 +52,9 @@ func main() {
|
|||||||
OutputSize: uint32(size),
|
OutputSize: uint32(size),
|
||||||
FlagCount: uint32(16),
|
FlagCount: uint32(16),
|
||||||
}
|
}
|
||||||
|
if stateDebug {
|
||||||
|
cfg.StateDebug = true
|
||||||
|
}
|
||||||
if engineDebug {
|
if engineDebug {
|
||||||
cfg.EngineDebug = true
|
cfg.EngineDebug = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,10 +23,10 @@ func main() {
|
|||||||
var dbDir string
|
var dbDir string
|
||||||
var size uint
|
var size uint
|
||||||
var sessionId string
|
var sessionId string
|
||||||
var engineDebug bool
|
var debug bool
|
||||||
flag.StringVar(&sessionId, "session-id", "075xx2123", "session id")
|
flag.StringVar(&sessionId, "session-id", "075xx2123", "session id")
|
||||||
flag.StringVar(&dbDir, "dbdir", ".state", "database dir to read from")
|
flag.StringVar(&dbDir, "dbdir", ".state", "database dir to read from")
|
||||||
flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
|
flag.BoolVar(&debug, "d", false, "use engine debug output")
|
||||||
flag.UintVar(&size, "s", 160, "max size of output")
|
flag.UintVar(&size, "s", 160, "max size of output")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ func main() {
|
|||||||
|
|
||||||
en := lhs.GetEngine()
|
en := lhs.GetEngine()
|
||||||
en = en.WithFirst(hl.Init)
|
en = en.WithFirst(hl.Init)
|
||||||
if engineDebug {
|
if debug {
|
||||||
en = en.WithDebug(nil)
|
en = en.WithDebug(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
5
go.mod
5
go.mod
@@ -3,12 +3,15 @@ module git.grassecon.net/urdt/ussd
|
|||||||
go 1.22.6
|
go 1.22.6
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.defalsify.org/vise.git v0.1.0-rc.3.0.20240923162317-c20d557a3dbb
|
git.defalsify.org/vise.git v0.1.0-rc.3.0.20240922152136-7ea16f9137b4
|
||||||
github.com/alecthomas/assert/v2 v2.2.2
|
github.com/alecthomas/assert/v2 v2.2.2
|
||||||
github.com/peteole/testdata-loader v0.3.0
|
github.com/peteole/testdata-loader v0.3.0
|
||||||
|
golang.org/x/crypto v0.17.0
|
||||||
gopkg.in/leonelquinteros/gotext.v1 v1.3.1
|
gopkg.in/leonelquinteros/gotext.v1 v1.3.1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
require golang.org/x/sys v0.15.0 // indirect
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/alecthomas/participle/v2 v2.0.0 // indirect
|
github.com/alecthomas/participle/v2 v2.0.0 // indirect
|
||||||
github.com/alecthomas/repr v0.2.0 // indirect
|
github.com/alecthomas/repr v0.2.0 // indirect
|
||||||
|
|||||||
10
go.sum
10
go.sum
@@ -1,5 +1,5 @@
|
|||||||
git.defalsify.org/vise.git v0.1.0-rc.3.0.20240923162317-c20d557a3dbb h1:6P4kxihcwMjDKzvUFC6t2zGNb7MDW+l/ACGlSAN1N8Y=
|
git.defalsify.org/vise.git v0.1.0-rc.3.0.20240922152136-7ea16f9137b4 h1:IMVUK9OkZ/QtYZPHgTZ+XUs5VQ4eIewIaTyVSCF/nAY=
|
||||||
git.defalsify.org/vise.git v0.1.0-rc.3.0.20240923162317-c20d557a3dbb/go.mod h1:JDguWmcoWBdsnpw7PUjVZAEpdC/ubBmjdUBy3tjP63M=
|
git.defalsify.org/vise.git v0.1.0-rc.3.0.20240922152136-7ea16f9137b4/go.mod h1:JDguWmcoWBdsnpw7PUjVZAEpdC/ubBmjdUBy3tjP63M=
|
||||||
github.com/alecthomas/assert/v2 v2.2.2 h1:Z/iVC0xZfWTaFNE6bA3z07T86hd45Xe2eLt6WVy2bbk=
|
github.com/alecthomas/assert/v2 v2.2.2 h1:Z/iVC0xZfWTaFNE6bA3z07T86hd45Xe2eLt6WVy2bbk=
|
||||||
github.com/alecthomas/assert/v2 v2.2.2/go.mod h1:pXcQ2Asjp247dahGEmsZ6ru0UVwnkhktn7S0bBDLxvQ=
|
github.com/alecthomas/assert/v2 v2.2.2/go.mod h1:pXcQ2Asjp247dahGEmsZ6ru0UVwnkhktn7S0bBDLxvQ=
|
||||||
github.com/alecthomas/participle/v2 v2.0.0 h1:Fgrq+MbuSsJwIkw3fEj9h75vDP0Er5JzepJ0/HNHv0g=
|
github.com/alecthomas/participle/v2 v2.0.0 h1:Fgrq+MbuSsJwIkw3fEj9h75vDP0Er5JzepJ0/HNHv0g=
|
||||||
@@ -28,6 +28,12 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
|
|||||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
|
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
|
||||||
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
|
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
|
||||||
|
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
|
||||||
|
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
|
||||||
|
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
|
||||||
|
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
|
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
|
||||||
|
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/leonelquinteros/gotext.v1 v1.3.1 h1:8d9/fdTG0kn/B7NNGV1BsEyvektXFAbkMsTZS2sFSCc=
|
gopkg.in/leonelquinteros/gotext.v1 v1.3.1 h1:8d9/fdTG0kn/B7NNGV1BsEyvektXFAbkMsTZS2sFSCc=
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ func(f *BaseSessionHandler) Process(rqs RequestSession) (RequestSession, error)
|
|||||||
var err error
|
var err error
|
||||||
var ok bool
|
var ok bool
|
||||||
|
|
||||||
logg.InfoCtxf(rqs.Ctx, "new request", "data", rqs)
|
logg.InfoCtxf(rqs.Ctx, "new request", rqs)
|
||||||
|
|
||||||
rqs.Storage, err = f.provider.Get(rqs.Config.SessionId)
|
rqs.Storage, err = f.provider.Get(rqs.Config.SessionId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ func (ls *LocalHandlerService) GetHandler() (*ussd.Handlers, error) {
|
|||||||
ls.DbRs.AddLocalFunc("get_profile_info", ussdHandlers.GetProfileInfo)
|
ls.DbRs.AddLocalFunc("get_profile_info", ussdHandlers.GetProfileInfo)
|
||||||
ls.DbRs.AddLocalFunc("verify_yob", ussdHandlers.VerifyYob)
|
ls.DbRs.AddLocalFunc("verify_yob", ussdHandlers.VerifyYob)
|
||||||
ls.DbRs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob)
|
ls.DbRs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob)
|
||||||
|
ls.DbRs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit)
|
||||||
ls.DbRs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction)
|
ls.DbRs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction)
|
||||||
ls.DbRs.AddLocalFunc("save_temporary_pin", ussdHandlers.SaveTemporaryPin)
|
ls.DbRs.AddLocalFunc("save_temporary_pin", ussdHandlers.SaveTemporaryPin)
|
||||||
ls.DbRs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin)
|
ls.DbRs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin)
|
||||||
|
|||||||
@@ -276,6 +276,17 @@ func (h *Handlers) ConfirmPinChange(ctx context.Context, sym string, input []byt
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetResetSingleEdit sets and resets flags to allow gradual editing of profile information.
|
||||||
|
func (h *Handlers) SetResetSingleEdit(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
|
var res resource.Result
|
||||||
|
flag_single_edit, err := h.flagManager.GetFlag("flag_single_edit")
|
||||||
|
if err != nil {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
res.FlagReset = append(res.FlagReset, flag_single_edit)
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
// VerifyPin checks whether the confirmation PIN is similar to the account PIN
|
// VerifyPin checks whether the confirmation PIN is similar to the account PIN
|
||||||
// If similar, it sets the USERFLAG_PIN_SET flag allowing the user
|
// If similar, it sets the USERFLAG_PIN_SET flag allowing the user
|
||||||
// to access the main menu
|
// to access the main menu
|
||||||
@@ -290,8 +301,6 @@ func (h *Handlers) VerifyPin(ctx context.Context, sym string, input []byte) (res
|
|||||||
if !ok {
|
if !ok {
|
||||||
return res, fmt.Errorf("missing session")
|
return res, fmt.Errorf("missing session")
|
||||||
}
|
}
|
||||||
|
|
||||||
//AccountPin, _ := utils.ReadEntry(ctx, h.userdataStore, sessionId, utils.DATA_ACCOUNT_PIN)
|
|
||||||
store := h.userdataStore
|
store := h.userdataStore
|
||||||
AccountPin, err := store.ReadEntry(ctx, sessionId, utils.DATA_ACCOUNT_PIN)
|
AccountPin, err := store.ReadEntry(ctx, sessionId, utils.DATA_ACCOUNT_PIN)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -327,6 +336,13 @@ func (h *Handlers) SaveFirstname(ctx context.Context, sym string, input []byte)
|
|||||||
if !ok {
|
if !ok {
|
||||||
return res, fmt.Errorf("missing session")
|
return res, fmt.Errorf("missing session")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flag_allow_update, _ := h.flagManager.GetFlag("flag_allow_update")
|
||||||
|
flag_single_edit, _ := h.flagManager.GetFlag("flag_single_edit")
|
||||||
|
|
||||||
|
res.FlagReset = append(res.FlagReset, flag_allow_update)
|
||||||
|
res.FlagSet = append(res.FlagSet, flag_single_edit)
|
||||||
|
|
||||||
if len(input) > 0 {
|
if len(input) > 0 {
|
||||||
firstName := string(input)
|
firstName := string(input)
|
||||||
store := h.userdataStore
|
store := h.userdataStore
|
||||||
@@ -347,7 +363,6 @@ func (h *Handlers) SaveFamilyname(ctx context.Context, sym string, input []byte)
|
|||||||
if !ok {
|
if !ok {
|
||||||
return res, fmt.Errorf("missing session")
|
return res, fmt.Errorf("missing session")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(input) > 0 {
|
if len(input) > 0 {
|
||||||
familyName := string(input)
|
familyName := string(input)
|
||||||
store := h.userdataStore
|
store := h.userdataStore
|
||||||
@@ -370,7 +385,6 @@ func (h *Handlers) SaveYob(ctx context.Context, sym string, input []byte) (resou
|
|||||||
if !ok {
|
if !ok {
|
||||||
return res, fmt.Errorf("missing session")
|
return res, fmt.Errorf("missing session")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(input) == 4 {
|
if len(input) == 4 {
|
||||||
yob := string(input)
|
yob := string(input)
|
||||||
store := h.userdataStore
|
store := h.userdataStore
|
||||||
@@ -391,7 +405,6 @@ func (h *Handlers) SaveLocation(ctx context.Context, sym string, input []byte) (
|
|||||||
if !ok {
|
if !ok {
|
||||||
return res, fmt.Errorf("missing session")
|
return res, fmt.Errorf("missing session")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(input) > 0 {
|
if len(input) > 0 {
|
||||||
location := string(input)
|
location := string(input)
|
||||||
store := h.userdataStore
|
store := h.userdataStore
|
||||||
@@ -406,19 +419,41 @@ func (h *Handlers) SaveLocation(ctx context.Context, sym string, input []byte) (
|
|||||||
|
|
||||||
// SaveGender updates the gender in the gdbm with the provided input.
|
// SaveGender updates the gender in the gdbm with the provided input.
|
||||||
func (h *Handlers) SaveGender(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (h *Handlers) SaveGender(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
symbol, _ := h.st.Where()
|
|
||||||
var res resource.Result
|
var res resource.Result
|
||||||
var err error
|
var err error
|
||||||
sessionId, ok := ctx.Value("SessionId").(string)
|
sessionId, ok := ctx.Value("SessionId").(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return res, fmt.Errorf("missing session")
|
return res, fmt.Errorf("missing session")
|
||||||
}
|
}
|
||||||
|
code := codeFromCtx(ctx)
|
||||||
|
if len(input) > 0 {
|
||||||
|
gender := string(input)
|
||||||
|
switch gender {
|
||||||
|
case "1":
|
||||||
|
if code == "swa" {
|
||||||
|
gender = "Mwanaume"
|
||||||
|
} else {
|
||||||
|
gender = "Male"
|
||||||
|
}
|
||||||
|
case "2":
|
||||||
|
if code == "swa" {
|
||||||
|
gender = "Mwanamke"
|
||||||
|
} else {
|
||||||
|
gender = "Female"
|
||||||
|
}
|
||||||
|
case "3":
|
||||||
|
if code == "swa" {
|
||||||
|
gender = "Haijabainishwa"
|
||||||
|
} else {
|
||||||
|
gender = "Unspecified"
|
||||||
|
}
|
||||||
|
|
||||||
gender := strings.Split(symbol, "_")[1]
|
}
|
||||||
store := h.userdataStore
|
store := h.userdataStore
|
||||||
err = store.WriteEntry(ctx, sessionId, utils.DATA_GENDER, []byte(gender))
|
err = store.WriteEntry(ctx, sessionId, utils.DATA_GENDER, []byte(gender))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, nil
|
return res, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
@@ -948,13 +983,20 @@ func (h *Handlers) InitiateTransaction(ctx context.Context, sym string, input []
|
|||||||
// GetProfileInfo retrieves and formats the profile information of a user from a Gdbm backed storage.
|
// GetProfileInfo retrieves and formats the profile information of a user from a Gdbm backed storage.
|
||||||
func (h *Handlers) GetProfileInfo(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (h *Handlers) GetProfileInfo(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
var res resource.Result
|
var res resource.Result
|
||||||
|
var defaultValue string
|
||||||
sessionId, ok := ctx.Value("SessionId").(string)
|
sessionId, ok := ctx.Value("SessionId").(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return res, fmt.Errorf("missing session")
|
return res, fmt.Errorf("missing session")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
code := h.st.Language.Code
|
||||||
|
|
||||||
// Default value when an entry is not found
|
// Default value when an entry is not found
|
||||||
defaultValue := "Not Provided"
|
if code == "swa" {
|
||||||
|
defaultValue = "Haipo"
|
||||||
|
} else {
|
||||||
|
defaultValue = "Not Provided"
|
||||||
|
}
|
||||||
|
|
||||||
// Helper function to handle nil byte slices and convert them to string
|
// Helper function to handle nil byte slices and convert them to string
|
||||||
getEntryOrDefault := func(entry []byte, err error) string {
|
getEntryOrDefault := func(entry []byte, err error) string {
|
||||||
@@ -991,12 +1033,22 @@ func (h *Handlers) GetProfileInfo(ctx context.Context, sym string, input []byte)
|
|||||||
return res, fmt.Errorf("invalid year of birth: %v", err)
|
return res, fmt.Errorf("invalid year of birth: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
switch code {
|
||||||
// Format the result
|
case "eng":
|
||||||
res.Content = fmt.Sprintf(
|
res.Content = fmt.Sprintf(
|
||||||
"Name: %s\nGender: %s\nAge: %s\nLocation: %s\nYou provide: %s\n",
|
"Name: %s\nGender: %s\nAge: %s\nLocation: %s\nYou provide: %s\n",
|
||||||
name, gender, age, location, offerings,
|
name, gender, age, location, offerings,
|
||||||
)
|
)
|
||||||
|
case "swa":
|
||||||
|
res.Content = fmt.Sprintf(
|
||||||
|
"Jina: %s\nJinsia: %s\nUmri: %s\nEneo: %s\nUnauza: %s\n",
|
||||||
|
name, gender, age, location, offerings,
|
||||||
|
)
|
||||||
|
default:
|
||||||
|
res.Content = fmt.Sprintf(
|
||||||
|
"Name: %s\nGender: %s\nAge: %s\nLocation: %s\nYou provide: %s\n",
|
||||||
|
name, gender, age, location, offerings,
|
||||||
|
)
|
||||||
|
}
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,26 +96,12 @@ func TestCreateAccount(t *testing.T) {
|
|||||||
mockDataStore.AssertExpectations(t)
|
mockDataStore.AssertExpectations(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWithPersister(t *testing.T) {
|
|
||||||
// Test case: Setting a persister
|
|
||||||
h := &Handlers{}
|
|
||||||
p := &persist.Persister{}
|
|
||||||
|
|
||||||
result := h.WithPersister(p)
|
|
||||||
|
|
||||||
assert.Equal(t, p, h.pe, "The persister should be set correctly.")
|
|
||||||
assert.Equal(t, h, result, "The returned handler should be the same instance.")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestWithPersister_PanicWhenAlreadySet(t *testing.T) {
|
|
||||||
// Test case: Panic on multiple calls
|
|
||||||
h := &Handlers{pe: &persist.Persister{}}
|
|
||||||
require.Panics(t, func() {
|
|
||||||
h.WithPersister(&persist.Persister{})
|
|
||||||
}, "Should panic when trying to set a persister again.")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSaveFirstname(t *testing.T) {
|
func TestSaveFirstname(t *testing.T) {
|
||||||
|
|
||||||
|
fm, err := NewFlagManager(flagsPath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
// Create a new instance of MockMyDataStore
|
// Create a new instance of MockMyDataStore
|
||||||
mockStore := new(mocks.MockUserDataStore)
|
mockStore := new(mocks.MockUserDataStore)
|
||||||
|
|
||||||
@@ -124,12 +110,16 @@ func TestSaveFirstname(t *testing.T) {
|
|||||||
firstName := "John"
|
firstName := "John"
|
||||||
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
||||||
|
|
||||||
|
flag_allow_update, _ := fm.parser.GetFlag("flag_allow_update")
|
||||||
|
flag_single_edit, _ := fm.parser.GetFlag("flag_single_edit")
|
||||||
|
|
||||||
// Set up the expected behavior of the mock
|
// Set up the expected behavior of the mock
|
||||||
mockStore.On("WriteEntry", ctx, sessionId, utils.DATA_FIRST_NAME, []byte(firstName)).Return(nil)
|
mockStore.On("WriteEntry", ctx, sessionId, utils.DATA_FIRST_NAME, []byte(firstName)).Return(nil)
|
||||||
|
|
||||||
// Create the Handlers instance with the mock store
|
// Create the Handlers instance with the mock store
|
||||||
h := &Handlers{
|
h := &Handlers{
|
||||||
userdataStore: mockStore,
|
userdataStore: mockStore,
|
||||||
|
flagManager: fm.parser,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the method
|
// Call the method
|
||||||
@@ -137,7 +127,10 @@ func TestSaveFirstname(t *testing.T) {
|
|||||||
|
|
||||||
// Assert results
|
// Assert results
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, resource.Result{}, res)
|
assert.Equal(t, resource.Result{
|
||||||
|
FlagSet: []uint32{flag_single_edit},
|
||||||
|
FlagReset: []uint32{flag_allow_update},
|
||||||
|
}, res)
|
||||||
|
|
||||||
// Assert all expectations were met
|
// Assert all expectations were met
|
||||||
mockStore.AssertExpectations(t)
|
mockStore.AssertExpectations(t)
|
||||||
@@ -316,7 +309,6 @@ func TestSaveOfferings(t *testing.T) {
|
|||||||
func TestSaveGender(t *testing.T) {
|
func TestSaveGender(t *testing.T) {
|
||||||
// Create a new instance of MockMyDataStore
|
// Create a new instance of MockMyDataStore
|
||||||
mockStore := new(mocks.MockUserDataStore)
|
mockStore := new(mocks.MockUserDataStore)
|
||||||
mockState := state.NewState(16)
|
|
||||||
|
|
||||||
// Define the session ID and context
|
// Define the session ID and context
|
||||||
sessionId := "session123"
|
sessionId := "session123"
|
||||||
@@ -324,32 +316,34 @@ func TestSaveGender(t *testing.T) {
|
|||||||
|
|
||||||
// Define test cases
|
// Define test cases
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
input []byte
|
input []byte
|
||||||
expectedGender string
|
expectedGender string
|
||||||
expectCall bool
|
expectCall bool
|
||||||
executingSymbol string
|
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Valid Male Input",
|
name: "Valid Male Input",
|
||||||
input: []byte("1"),
|
input: []byte("1"),
|
||||||
expectedGender: "male",
|
expectedGender: "Male",
|
||||||
executingSymbol: "set_male",
|
expectCall: true,
|
||||||
expectCall: true,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Valid Female Input",
|
name: "Valid Female Input",
|
||||||
input: []byte("2"),
|
input: []byte("2"),
|
||||||
expectedGender: "female",
|
expectedGender: "Female",
|
||||||
executingSymbol: "set_female",
|
expectCall: true,
|
||||||
expectCall: true,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Valid Unspecified Input",
|
name: "Valid Unspecified Input",
|
||||||
input: []byte("3"),
|
input: []byte("3"),
|
||||||
executingSymbol: "set_unspecified",
|
expectedGender: "Unspecified",
|
||||||
expectedGender: "unspecified",
|
expectCall: true,
|
||||||
expectCall: true,
|
},
|
||||||
|
{
|
||||||
|
name: "Empty Input",
|
||||||
|
input: []byte(""),
|
||||||
|
expectedGender: "",
|
||||||
|
expectCall: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -362,11 +356,10 @@ func TestSaveGender(t *testing.T) {
|
|||||||
} else {
|
} else {
|
||||||
mockStore.On("WriteEntry", ctx, sessionId, utils.DATA_GENDER, []byte(tt.expectedGender)).Return(nil)
|
mockStore.On("WriteEntry", ctx, sessionId, utils.DATA_GENDER, []byte(tt.expectedGender)).Return(nil)
|
||||||
}
|
}
|
||||||
mockState.ExecPath = append(mockState.ExecPath, tt.executingSymbol)
|
|
||||||
// Create the Handlers instance with the mock store
|
// Create the Handlers instance with the mock store
|
||||||
h := &Handlers{
|
h := &Handlers{
|
||||||
userdataStore: mockStore,
|
userdataStore: mockStore,
|
||||||
st: mockState,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the method
|
// Call the method
|
||||||
@@ -562,10 +555,12 @@ func TestSetLanguage(t *testing.T) {
|
|||||||
name string
|
name string
|
||||||
execPath []string
|
execPath []string
|
||||||
expectedResult resource.Result
|
expectedResult resource.Result
|
||||||
|
symbol string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Set Default Language (English)",
|
name: "Set Default Language (English)",
|
||||||
execPath: []string{"set_eng"},
|
execPath: []string{"set_eng"},
|
||||||
|
symbol: "set_eng",
|
||||||
expectedResult: resource.Result{
|
expectedResult: resource.Result{
|
||||||
FlagSet: []uint32{state.FLAG_LANG, 8},
|
FlagSet: []uint32{state.FLAG_LANG, 8},
|
||||||
Content: "eng",
|
Content: "eng",
|
||||||
@@ -573,6 +568,7 @@ func TestSetLanguage(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Set Swahili Language",
|
name: "Set Swahili Language",
|
||||||
|
symbol: "set_swa",
|
||||||
execPath: []string{"set_swa"},
|
execPath: []string{"set_swa"},
|
||||||
expectedResult: resource.Result{
|
expectedResult: resource.Result{
|
||||||
FlagSet: []uint32{state.FLAG_LANG, 8},
|
FlagSet: []uint32{state.FLAG_LANG, 8},
|
||||||
@@ -594,7 +590,7 @@ func TestSetLanguage(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Call the method
|
// Call the method
|
||||||
res, err := h.SetLanguage(context.Background(), "set_language", nil)
|
res, err := h.SetLanguage(context.Background(), tt.symbol, nil)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
@@ -606,6 +602,76 @@ func TestSetLanguage(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSetResetSingleEdit(t *testing.T) {
|
||||||
|
fm, err := NewFlagManager(flagsPath)
|
||||||
|
|
||||||
|
//flag_allow_update, _ := fm.parser.GetFlag("flag_allow_update")
|
||||||
|
flag_single_edit, _ := fm.parser.GetFlag("flag_single_edit")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
// Define test cases
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
input []byte
|
||||||
|
expectedResult resource.Result
|
||||||
|
}{
|
||||||
|
// {
|
||||||
|
// name: "Set single Edit",
|
||||||
|
// input: []byte("2"),
|
||||||
|
// expectedResult: resource.Result{
|
||||||
|
// FlagSet: []uint32{flag_single_edit},
|
||||||
|
// FlagReset: []uint32{flag_allow_update},
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// name: "Set single Edit",
|
||||||
|
// input: []byte("3"),
|
||||||
|
// expectedResult: resource.Result{
|
||||||
|
// FlagSet: []uint32{flag_single_edit},
|
||||||
|
// FlagReset: []uint32{flag_allow_update},
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// name: "Set single edit",
|
||||||
|
// input: []byte("4"),
|
||||||
|
// expectedResult: resource.Result{
|
||||||
|
// FlagReset: []uint32{flag_allow_update},
|
||||||
|
// FlagSet: []uint32{flag_single_edit},
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
{
|
||||||
|
name: "No single edit set",
|
||||||
|
input: []byte("1"),
|
||||||
|
expectedResult: resource.Result{
|
||||||
|
FlagReset: []uint32{flag_single_edit},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|
||||||
|
// Create the Handlers instance with the mock flag manager
|
||||||
|
h := &Handlers{
|
||||||
|
flagManager: fm.parser,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call the method
|
||||||
|
res, err := h.SetResetSingleEdit(context.Background(), "set_reset_single_edit", tt.input)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
// Assert that the Result FlagSet has the required flags after language switch
|
||||||
|
assert.Equal(t, res, tt.expectedResult, "Flags should match reset edit")
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestResetAllowUpdate(t *testing.T) {
|
func TestResetAllowUpdate(t *testing.T) {
|
||||||
fm, err := NewFlagManager(flagsPath)
|
fm, err := NewFlagManager(flagsPath)
|
||||||
|
|
||||||
@@ -1045,18 +1111,26 @@ func TestCheckAccountStatus(t *testing.T) {
|
|||||||
FlagReset: []uint32{flag_account_pending},
|
FlagReset: []uint32{flag_account_pending},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Test when account status is not a success",
|
||||||
|
input: []byte("TrackingId12"),
|
||||||
|
status: "REVERTED",
|
||||||
|
expectedResult: resource.Result{
|
||||||
|
FlagSet: []uint32{flag_account_success},
|
||||||
|
FlagReset: []uint32{flag_account_pending},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
typ := utils.DATA_TRACKING_ID
|
typ := utils.DATA_TRACKING_ID
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
mockCreateAccountService.On("CheckAccountStatus", string(tt.input)).Return(tt.status, nil)
|
||||||
|
|
||||||
|
mockDataStore.On("WriteEntry", ctx, sessionId, utils.DATA_ACCOUNT_STATUS, []byte(tt.status)).Return(nil).Maybe()
|
||||||
// Define expected interactions with the mock
|
// Define expected interactions with the mock
|
||||||
mockDataStore.On("ReadEntry", ctx, sessionId, typ).Return(tt.input, nil)
|
mockDataStore.On("ReadEntry", ctx, sessionId, typ).Return(tt.input, nil)
|
||||||
|
|
||||||
mockCreateAccountService.On("CheckAccountStatus", string(tt.input)).Return(tt.status, nil)
|
|
||||||
mockDataStore.On("WriteEntry", ctx, sessionId, utils.DATA_ACCOUNT_STATUS, []byte(tt.status)).Return(nil)
|
|
||||||
|
|
||||||
// Call the method under test
|
// Call the method under test
|
||||||
res, _ := h.CheckAccountStatus(ctx, "check_status", tt.input)
|
res, _ := h.CheckAccountStatus(ctx, "check_status", tt.input)
|
||||||
|
|
||||||
@@ -1574,7 +1648,6 @@ func TestCheckBalance(t *testing.T) {
|
|||||||
h := &Handlers{
|
h := &Handlers{
|
||||||
userdataStore: mockDataStore,
|
userdataStore: mockDataStore,
|
||||||
accountService: mockCreateAccountService,
|
accountService: mockCreateAccountService,
|
||||||
//flagManager: fm.parser,
|
|
||||||
}
|
}
|
||||||
//mock call operations
|
//mock call operations
|
||||||
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_PUBLIC_KEY).Return([]byte(publicKey), nil)
|
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_PUBLIC_KEY).Return([]byte(publicKey), nil)
|
||||||
@@ -1592,23 +1665,51 @@ func TestGetProfile(t *testing.T) {
|
|||||||
|
|
||||||
mockDataStore := new(mocks.MockUserDataStore)
|
mockDataStore := new(mocks.MockUserDataStore)
|
||||||
mockCreateAccountService := new(mocks.MockAccountService)
|
mockCreateAccountService := new(mocks.MockAccountService)
|
||||||
|
mockState := state.NewState(16)
|
||||||
|
|
||||||
h := &Handlers{
|
h := &Handlers{
|
||||||
userdataStore: mockDataStore,
|
userdataStore: mockDataStore,
|
||||||
accountService: mockCreateAccountService,
|
accountService: mockCreateAccountService,
|
||||||
|
st: mockState,
|
||||||
}
|
}
|
||||||
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
keys []utils.DataTyp
|
languageCode string
|
||||||
profileInfo []string
|
keys []utils.DataTyp
|
||||||
result resource.Result
|
profileInfo []string
|
||||||
|
result resource.Result
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Test with full profile information",
|
name: "Test with full profile information in eng",
|
||||||
keys: []utils.DataTyp{utils.DATA_FAMILY_NAME, utils.DATA_FIRST_NAME, utils.DATA_GENDER, utils.DATA_OFFERINGS, utils.DATA_LOCATION, utils.DATA_YOB},
|
keys: []utils.DataTyp{utils.DATA_FAMILY_NAME, utils.DATA_FIRST_NAME, utils.DATA_GENDER, utils.DATA_OFFERINGS, utils.DATA_LOCATION, utils.DATA_YOB},
|
||||||
profileInfo: []string{"Doee", "John", "Male", "Bananas", "Kilifi", "1976"},
|
profileInfo: []string{"Doee", "John", "Male", "Bananas", "Kilifi", "1976"},
|
||||||
|
languageCode: "eng",
|
||||||
|
result: resource.Result{
|
||||||
|
Content: fmt.Sprintf(
|
||||||
|
"Name: %s\nGender: %s\nAge: %s\nLocation: %s\nYou provide: %s\n",
|
||||||
|
"John Doee", "Male", "48", "Kilifi", "Bananas",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Test with with profile information in swa ",
|
||||||
|
keys: []utils.DataTyp{utils.DATA_FAMILY_NAME, utils.DATA_FIRST_NAME, utils.DATA_GENDER, utils.DATA_OFFERINGS, utils.DATA_LOCATION, utils.DATA_YOB},
|
||||||
|
profileInfo: []string{"Doee", "John", "Jinsia", "Bananas", "Kilifi", "1976"},
|
||||||
|
languageCode: "swa",
|
||||||
|
result: resource.Result{
|
||||||
|
Content: fmt.Sprintf(
|
||||||
|
"Jina: %s\nJinsia: %s\nUmri: %s\nEneo: %s\nUnauza: %s\n",
|
||||||
|
"John Doee", "Male", "48", "Kilifi", "Bananas",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Test with with profile information with language that is not yet supported",
|
||||||
|
keys: []utils.DataTyp{utils.DATA_FAMILY_NAME, utils.DATA_FIRST_NAME, utils.DATA_GENDER, utils.DATA_OFFERINGS, utils.DATA_LOCATION, utils.DATA_YOB},
|
||||||
|
profileInfo: []string{"Doee", "John", "Jinsia", "Bananas", "Kilifi", "1976"},
|
||||||
|
languageCode: "nor",
|
||||||
result: resource.Result{
|
result: resource.Result{
|
||||||
Content: fmt.Sprintf(
|
Content: fmt.Sprintf(
|
||||||
"Name: %s\nGender: %s\nAge: %s\nLocation: %s\nYou provide: %s\n",
|
"Name: %s\nGender: %s\nAge: %s\nLocation: %s\nYou provide: %s\n",
|
||||||
@@ -1622,6 +1723,13 @@ func TestGetProfile(t *testing.T) {
|
|||||||
for index, key := range tt.keys {
|
for index, key := range tt.keys {
|
||||||
mockDataStore.On("ReadEntry", ctx, sessionId, key).Return([]byte(tt.profileInfo[index]), nil)
|
mockDataStore.On("ReadEntry", ctx, sessionId, key).Return([]byte(tt.profileInfo[index]), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err := mockState.SetLanguage(tt.languageCode)
|
||||||
|
if err != nil {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
h.st = mockState
|
||||||
|
|
||||||
res, _ := h.GetProfileInfo(ctx, "get_profile_info", []byte(""))
|
res, _ := h.GetProfileInfo(ctx, "get_profile_info", []byte(""))
|
||||||
|
|
||||||
// Assert that expectations were met
|
// Assert that expectations were met
|
||||||
@@ -1729,6 +1837,25 @@ func TestSaveTemporaryPIn(t *testing.T) {
|
|||||||
mockStore.AssertExpectations(t)
|
mockStore.AssertExpectations(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWithPersister(t *testing.T) {
|
||||||
|
// Test case: Setting a persister
|
||||||
|
h := &Handlers{}
|
||||||
|
p := &persist.Persister{}
|
||||||
|
|
||||||
|
result := h.WithPersister(p)
|
||||||
|
|
||||||
|
assert.Equal(t, p, h.pe, "The persister should be set correctly.")
|
||||||
|
assert.Equal(t, h, result, "The returned handler should be the same instance.")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWithPersister_PanicWhenAlreadySet(t *testing.T) {
|
||||||
|
// Test case: Panic on multiple calls
|
||||||
|
h := &Handlers{pe: &persist.Persister{}}
|
||||||
|
require.Panics(t, func() {
|
||||||
|
h.WithPersister(&persist.Persister{})
|
||||||
|
}, "Should panic when trying to set a persister again.")
|
||||||
|
}
|
||||||
|
|
||||||
func TestConfirmPin(t *testing.T) {
|
func TestConfirmPin(t *testing.T) {
|
||||||
sessionId := "session123"
|
sessionId := "session123"
|
||||||
|
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
Something went wrong.Please try again
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
HALT
|
|
||||||
@@ -9,5 +9,4 @@ CATCH invalid_amount flag_invalid_amount 1
|
|||||||
INCMP _ 0
|
INCMP _ 0
|
||||||
LOAD get_recipient 12
|
LOAD get_recipient 12
|
||||||
LOAD get_sender 64
|
LOAD get_sender 64
|
||||||
LOAD get_amount 12
|
|
||||||
INCMP transaction_pin *
|
INCMP transaction_pin *
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
Edit family name
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
Weka jina la familia
|
|
||||||
@@ -2,19 +2,19 @@ LOAD reset_account_authorized 16
|
|||||||
LOAD reset_allow_update 0
|
LOAD reset_allow_update 0
|
||||||
RELOAD reset_allow_update
|
RELOAD reset_allow_update
|
||||||
MOUT edit_name 1
|
MOUT edit_name 1
|
||||||
MOUT edit_familyname 2
|
MOUT edit_gender 2
|
||||||
MOUT edit_gender 3
|
MOUT edit_yob 3
|
||||||
MOUT edit_yob 4
|
MOUT edit_location 4
|
||||||
MOUT edit_location 5
|
MOUT edit_offerings 5
|
||||||
MOUT edit_offerings 6
|
MOUT view 6
|
||||||
MOUT view 7
|
|
||||||
MOUT back 0
|
MOUT back 0
|
||||||
HALT
|
HALT
|
||||||
INCMP my_account 0
|
INCMP _ 0
|
||||||
|
LOAD set_reset_single_edit 0
|
||||||
|
RELOAD set_reset_single_edit
|
||||||
INCMP enter_name 1
|
INCMP enter_name 1
|
||||||
INCMP enter_familyname 2
|
INCMP select_gender 2
|
||||||
INCMP select_gender 3
|
INCMP enter_yob 3
|
||||||
INCMP enter_yob 4
|
INCMP enter_location 4
|
||||||
INCMP enter_location 5
|
INCMP enter_offerings 5
|
||||||
INCMP enter_offerings 6
|
INCMP view_profile 6
|
||||||
INCMP view_profile 7
|
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
CATCH incorrect_pin flag_incorrect_pin 1
|
LOAD save_firstname 0
|
||||||
CATCH profile_update_success flag_allow_update 1
|
|
||||||
LOAD save_familyname 0
|
|
||||||
RELOAD save_familyname
|
|
||||||
MOUT back 0
|
MOUT back 0
|
||||||
HALT
|
HALT
|
||||||
RELOAD save_familyname
|
|
||||||
INCMP _ 0
|
INCMP _ 0
|
||||||
INCMP pin_entry *
|
INCMP select_gender *
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
Weka jina la familia
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
CATCH incorrect_pin flag_incorrect_pin 1
|
CATCH incorrect_date_format flag_incorrect_date_format 1
|
||||||
CATCH profile_update_success flag_allow_update 1
|
LOAD save_yob 0
|
||||||
LOAD save_location 0
|
CATCH update_success flag_allow_update 1
|
||||||
MOUT back 0
|
MOUT back 0
|
||||||
HALT
|
HALT
|
||||||
RELOAD save_location
|
|
||||||
INCMP _ 0
|
INCMP _ 0
|
||||||
INCMP pin_entry *
|
LOAD save_location 0
|
||||||
|
CATCH pin_entry flag_single_edit 0
|
||||||
|
INCMP enter_offerings *
|
||||||
|
|||||||
@@ -1,12 +1,4 @@
|
|||||||
CATCH incorrect_pin flag_incorrect_pin 1
|
|
||||||
CATCH profile_update_success flag_allow_update 1
|
|
||||||
LOAD save_firstname 0
|
|
||||||
RELOAD save_firstname
|
|
||||||
MOUT back 0
|
MOUT back 0
|
||||||
HALT
|
HALT
|
||||||
RELOAD save_firstname
|
|
||||||
INCMP _ 0
|
INCMP _ 0
|
||||||
INCMP pin_entry *
|
INCMP enter_familyname *
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
|
LOAD save_location 0
|
||||||
CATCH incorrect_pin flag_incorrect_pin 1
|
CATCH incorrect_pin flag_incorrect_pin 1
|
||||||
CATCH profile_update_success flag_allow_update 1
|
CATCH update_success flag_allow_update 1
|
||||||
LOAD save_offerings 0
|
|
||||||
MOUT back 0
|
MOUT back 0
|
||||||
HALT
|
HALT
|
||||||
RELOAD save_offerings
|
LOAD save_offerings 0
|
||||||
INCMP _ 0
|
INCMP _ 0
|
||||||
INCMP pin_entry *
|
INCMP pin_entry *
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
CATCH incorrect_pin flag_incorrect_pin 1
|
LOAD save_gender 0
|
||||||
CATCH profile_update_success flag_allow_update 1
|
CATCH update_success flag_allow_update 1
|
||||||
LOAD save_yob 0
|
|
||||||
MOUT back 0
|
MOUT back 0
|
||||||
HALT
|
HALT
|
||||||
LOAD verify_yob 0
|
|
||||||
CATCH incorrect_date_format flag_incorrect_date_format 1
|
|
||||||
RELOAD save_yob
|
|
||||||
INCMP _ 0
|
INCMP _ 0
|
||||||
INCMP pin_entry *
|
LOAD verify_yob 8
|
||||||
|
LOAD save_yob 0
|
||||||
|
CATCH pin_entry flag_single_edit 0
|
||||||
|
INCMP enter_location *
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ MOUT pin_options 5
|
|||||||
MOUT my_address 6
|
MOUT my_address 6
|
||||||
MOUT back 0
|
MOUT back 0
|
||||||
HALT
|
HALT
|
||||||
INCMP main 0
|
INCMP _ 0
|
||||||
INCMP edit_profile 1
|
INCMP edit_profile 1
|
||||||
INCMP change_language 2
|
INCMP change_language 2
|
||||||
INCMP balances 3
|
INCMP balances 3
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
Profile updated successfully
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
MOUT back 0
|
|
||||||
MOUT quit 9
|
|
||||||
HALT
|
|
||||||
INCMP edit_profile 0
|
|
||||||
INCMP quit 9
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
Ombi la Kuweka wasifu limefanikiwa
|
|
||||||
@@ -1,15 +1,13 @@
|
|||||||
CATCH incorrect_pin flag_incorrect_pin 1
|
LOAD save_familyname 0
|
||||||
CATCH profile_update_success flag_allow_update 1
|
CATCH update_success flag_allow_update 1
|
||||||
MOUT male 1
|
MOUT male 1
|
||||||
MOUT female 2
|
MOUT female 2
|
||||||
MOUT unspecified 3
|
MOUT unspecified 3
|
||||||
MOUT back 0
|
MOUT back 0
|
||||||
HALT
|
HALT
|
||||||
|
LOAD save_gender 0
|
||||||
|
CATCH pin_entry flag_single_edit 0
|
||||||
INCMP _ 0
|
INCMP _ 0
|
||||||
INCMP set_male 1
|
INCMP enter_yob 1
|
||||||
INCMP set_female 2
|
INCMP enter_yob 2
|
||||||
INCMP set_unspecified 3
|
INCMP enter_yob 3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
LOAD save_gender 0
|
|
||||||
CATCH incorrect_pin flag_incorrect_pin 1
|
|
||||||
CATCH profile_update_success flag_allow_update 1
|
|
||||||
MOVE pin_entry
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
LOAD save_gender 0
|
|
||||||
CATCH incorrect_pin flag_incorrect_pin 1
|
|
||||||
CATCH profile_update_success flag_allow_update 1
|
|
||||||
MOVE pin_entry
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
LOAD save_gender 0
|
|
||||||
CATCH incorrect_pin flag_incorrect_pin 1
|
|
||||||
CATCH profile_update_success flag_allow_update 1
|
|
||||||
MOVE pin_entry
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
LOAD reset_incorrect 6
|
LOAD reset_incorrect 6
|
||||||
CATCH incorrect_pin flag_incorrect_pin 1
|
CATCH incorrect_pin flag_incorrect_pin 1
|
||||||
CATCH _ flag_account_authorized 0
|
CATCH _ flag_account_authorized 0
|
||||||
RELOAD get_amount
|
LOAD get_amount 10
|
||||||
MAP get_amount
|
MAP get_amount
|
||||||
RELOAD get_recipient
|
RELOAD get_recipient
|
||||||
MAP get_recipient
|
MAP get_recipient
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
{{.get_recipient}} will receive {{.get_amount}} from {{.get_sender}}
|
{{.get_recipient}} will receive {{.validate_amount}} from {{.get_sender}}
|
||||||
Please enter your PIN to confirm:
|
Please enter your PIN to confirm:
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
RELOAD get_amount
|
MAP validate_amount
|
||||||
MAP get_amount
|
|
||||||
RELOAD get_recipient
|
RELOAD get_recipient
|
||||||
MAP get_recipient
|
MAP get_recipient
|
||||||
RELOAD get_sender
|
RELOAD get_sender
|
||||||
MAP get_sender
|
MAP get_sender
|
||||||
MOUT back 0
|
MOUT back 0
|
||||||
MOUT quit 9
|
MOUT quit 9
|
||||||
LOAD authorize_account 6
|
|
||||||
HALT
|
HALT
|
||||||
|
LOAD authorize_account 6
|
||||||
RELOAD authorize_account
|
RELOAD authorize_account
|
||||||
CATCH incorrect_pin flag_incorrect_pin 1
|
CATCH incorrect_pin flag_incorrect_pin 1
|
||||||
INCMP _ 0
|
INCMP _ 0
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
{{.get_recipient}} atapokea {{.get_amount}} kutoka kwa {{.get_sender}}
|
{{.get_recipient}} atapokea {{.validate_amount}} kutoka kwa {{.get_sender}}
|
||||||
Tafadhali weka PIN yako kudhibitisha:
|
Tafadhali weka PIN yako kudhibitisha:
|
||||||
@@ -1 +1 @@
|
|||||||
Akaunti imeupdatiwa
|
Ombi lako la kuweka wasifu limefanikiwa
|
||||||
|
|||||||
1
services/registration/view_menu_swa
Normal file
1
services/registration/view_menu_swa
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Angalia Wasifu
|
||||||
Reference in New Issue
Block a user