From fd586d09c3f80668cb8588f4b03b3d466ffaa300 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 2 Dec 2024 20:35:04 +0300 Subject: [PATCH 01/24] add required profile edit flags --- services/registration/pp.csv | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/services/registration/pp.csv b/services/registration/pp.csv index cd6a633..6c74b95 100644 --- a/services/registration/pp.csv +++ b/services/registration/pp.csv @@ -21,3 +21,9 @@ flag,flag_admin_privilege,27,this is set when a user has admin privileges. flag,flag_unregistered_number,28,this is set when an unregistered phonenumber tries to perform an action flag,flag_no_transfers,29,this is set when a user does not have any transactions flag,flag_incorrect_statement,30,this is set when the selected statement is invalid +flag,flag_firstname_set,31,this is set when the first name of the profile is set +flag,flag_familyname_set,32,this is set when the family name of the profile is set +flag,flag_yob_set,33,this is set when the yob of the profile is set +flag,flag_gender_set,34,this is set when the gender of the profile is set +flag,flag_location_set,35,this is set when the location of the profile is set +flag,flag_offerings_set,36,this is set when the offerings of the profile is set From 3e0bbe5ffea209de8a9414ad466c7d62a4e1e8fb Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 2 Dec 2024 20:35:56 +0300 Subject: [PATCH 02/24] add handler to update profile items --- internal/handlers/handlerservice.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/handlers/handlerservice.go b/internal/handlers/handlerservice.go index c77e82c..13ca70a 100644 --- a/internal/handlers/handlerservice.go +++ b/internal/handlers/handlerservice.go @@ -121,6 +121,7 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountServiceIn ls.DbRs.AddLocalFunc("check_transactions", ussdHandlers.CheckTransactions) ls.DbRs.AddLocalFunc("get_transactions", ussdHandlers.GetTransactionsList) ls.DbRs.AddLocalFunc("view_statement", ussdHandlers.ViewTransactionStatement) + ls.DbRs.AddLocalFunc("update_all_profile_items", ussdHandlers.UpdateAllProfileItems) return ussdHandlers, nil } From 48e1b02e0e7ef1ec758a7ab1a3c08c34351d587a Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 2 Dec 2024 20:50:21 +0300 Subject: [PATCH 03/24] allow all item profile edit --- services/registration/edit_family_name.vis | 7 ++++--- services/registration/edit_first_name.vis | 6 +++--- services/registration/edit_location.vis | 5 +++-- services/registration/edit_offerings.vis | 5 +++-- services/registration/edit_profile.vis | 2 +- services/registration/edit_yob.vis | 6 ++++-- services/registration/profile_update_success.vis | 2 ++ services/registration/set_female.vis | 5 +++-- services/registration/set_male.vis | 5 +++-- services/registration/set_unspecified.vis | 5 +++-- services/registration/update_profile_items.vis | 3 +++ 11 files changed, 32 insertions(+), 19 deletions(-) create mode 100644 services/registration/update_profile_items.vis diff --git a/services/registration/edit_family_name.vis b/services/registration/edit_family_name.vis index 1d71939..adcede1 100644 --- a/services/registration/edit_family_name.vis +++ b/services/registration/edit_family_name.vis @@ -1,10 +1,11 @@ -CATCH incorrect_pin flag_incorrect_pin 1 CATCH update_familyname flag_allow_update 1 LOAD get_current_profile_info 0 RELOAD get_current_profile_info +MAP get_current_profile_info MOUT back 0 +LOAD save_familyname 64 HALT -LOAD save_familyname 0 RELOAD save_familyname INCMP _ 0 -INCMP pin_entry * +CATCH pin_entry flag_familyname_set 1 +INCMP select_gender * diff --git a/services/registration/edit_first_name.vis b/services/registration/edit_first_name.vis index b8dab5a..d230945 100644 --- a/services/registration/edit_first_name.vis +++ b/services/registration/edit_first_name.vis @@ -1,11 +1,11 @@ -CATCH incorrect_pin flag_incorrect_pin 1 CATCH update_firstname flag_allow_update 1 LOAD get_current_profile_info 0 RELOAD get_current_profile_info MAP get_current_profile_info +LOAD save_firstname 128 MOUT back 0 HALT -LOAD save_firstname 0 RELOAD save_firstname INCMP _ 0 -INCMP pin_entry * +CATCH pin_entry flag_firstname_set 1 +INCMP edit_family_name * diff --git a/services/registration/edit_location.vis b/services/registration/edit_location.vis index eaf248a..c9bc12d 100644 --- a/services/registration/edit_location.vis +++ b/services/registration/edit_location.vis @@ -2,9 +2,10 @@ CATCH incorrect_pin flag_incorrect_pin 1 CATCH update_location flag_allow_update 1 LOAD get_current_profile_info 0 RELOAD get_current_profile_info +LOAD save_location 16 MOUT back 0 HALT -LOAD save_location 0 RELOAD save_location INCMP _ 0 -INCMP pin_entry * +CATCH pin_entry flag_location_set 1 +INCMP edit_offerings * diff --git a/services/registration/edit_offerings.vis b/services/registration/edit_offerings.vis index dad3193..f95c2ae 100644 --- a/services/registration/edit_offerings.vis +++ b/services/registration/edit_offerings.vis @@ -2,9 +2,10 @@ CATCH incorrect_pin flag_incorrect_pin 1 CATCH update_offerings flag_allow_update 1 LOAD get_current_profile_info 0 RELOAD get_current_profile_info -LOAD save_offerings 0 +LOAD save_offerings 8 MOUT back 0 HALT RELOAD save_offerings INCMP _ 0 -INCMP pin_entry * +CATCH pin_entry flag_offerings_set 1 +INCMP update_profile_items * diff --git a/services/registration/edit_profile.vis b/services/registration/edit_profile.vis index af20e0f..dff221b 100644 --- a/services/registration/edit_profile.vis +++ b/services/registration/edit_profile.vis @@ -11,7 +11,7 @@ MOUT edit_offerings 6 MOUT view 7 MOUT back 0 HALT -INCMP my_account 0 +INCMP ^ 0 INCMP edit_first_name 1 INCMP edit_family_name 2 INCMP select_gender 3 diff --git a/services/registration/edit_yob.vis b/services/registration/edit_yob.vis index 6a5abe0..d0fbcee 100644 --- a/services/registration/edit_yob.vis +++ b/services/registration/edit_yob.vis @@ -8,7 +8,9 @@ HALT LOAD verify_yob 6 RELOAD verify_yob CATCH incorrect_date_format flag_incorrect_date_format 1 -LOAD save_yob 0 +LOAD save_yob 32 RELOAD save_yob INCMP _ 0 -INCMP pin_entry * +CATCH pin_entry flag_yob_set 1 +INCMP edit_location * + diff --git a/services/registration/profile_update_success.vis b/services/registration/profile_update_success.vis index a035093..f670e6e 100644 --- a/services/registration/profile_update_success.vis +++ b/services/registration/profile_update_success.vis @@ -1,3 +1,5 @@ +LOAD update_all_profile_items 0 +RELOAD update_all_profile_items MOUT back 0 MOUT quit 9 HALT diff --git a/services/registration/set_female.vis b/services/registration/set_female.vis index e211ada..d1d38bd 100644 --- a/services/registration/set_female.vis +++ b/services/registration/set_female.vis @@ -1,4 +1,5 @@ -LOAD save_gender 0 +LOAD save_gender 32 CATCH incorrect_pin flag_incorrect_pin 1 CATCH update_gender flag_allow_update 1 -MOVE pin_entry +CATCH pin_entry flag_gender_set 1 +MOVE edit_yob diff --git a/services/registration/set_male.vis b/services/registration/set_male.vis index e211ada..e718dfc 100644 --- a/services/registration/set_male.vis +++ b/services/registration/set_male.vis @@ -1,4 +1,5 @@ -LOAD save_gender 0 +LOAD save_gender 16 CATCH incorrect_pin flag_incorrect_pin 1 CATCH update_gender flag_allow_update 1 -MOVE pin_entry +CATCH pin_entry flag_gender_set 1 +MOVE edit_yob diff --git a/services/registration/set_unspecified.vis b/services/registration/set_unspecified.vis index e211ada..e5cfca8 100644 --- a/services/registration/set_unspecified.vis +++ b/services/registration/set_unspecified.vis @@ -1,4 +1,5 @@ -LOAD save_gender 0 +LOAD save_gender 8 CATCH incorrect_pin flag_incorrect_pin 1 CATCH update_gender flag_allow_update 1 -MOVE pin_entry +CATCH pin_entry flag_gender_set 1 +MOVE edit_yob diff --git a/services/registration/update_profile_items.vis b/services/registration/update_profile_items.vis new file mode 100644 index 0000000..beda013 --- /dev/null +++ b/services/registration/update_profile_items.vis @@ -0,0 +1,3 @@ +CATCH incorrect_pin flag_incorrect_pin 1 +CATCH profile_update_success flag_allow_update 1 +MOVE pin_entry From 944fa89b3cffdf1ec4a19e0be842678d8d97e3bf Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Tue, 3 Dec 2024 11:19:38 +0300 Subject: [PATCH 04/24] add profile holder struct --- models/profile.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 models/profile.go diff --git a/models/profile.go b/models/profile.go new file mode 100644 index 0000000..bdc1f0d --- /dev/null +++ b/models/profile.go @@ -0,0 +1,14 @@ +package models + +type Profile struct { + ProfileItems []string + Max int +} + +func (p *Profile) InsertOrShift(index int, value string) { + if index < len(p.ProfileItems) { + p.ProfileItems = append(p.ProfileItems[:index], value) + } else { + p.ProfileItems = append(p.ProfileItems, value) + } +} From a72fb08dc835ea6fb36279ade3a3a1fcafebbeb0 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Tue, 3 Dec 2024 11:20:35 +0300 Subject: [PATCH 05/24] allow sequential profile edit --- services/registration/edit_family_name.vis | 2 +- services/registration/edit_first_name.vis | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/services/registration/edit_family_name.vis b/services/registration/edit_family_name.vis index adcede1..df35970 100644 --- a/services/registration/edit_family_name.vis +++ b/services/registration/edit_family_name.vis @@ -3,8 +3,8 @@ LOAD get_current_profile_info 0 RELOAD get_current_profile_info MAP get_current_profile_info MOUT back 0 -LOAD save_familyname 64 HALT +LOAD save_familyname 64 RELOAD save_familyname INCMP _ 0 CATCH pin_entry flag_familyname_set 1 diff --git a/services/registration/edit_first_name.vis b/services/registration/edit_first_name.vis index d230945..f6bfa26 100644 --- a/services/registration/edit_first_name.vis +++ b/services/registration/edit_first_name.vis @@ -2,10 +2,10 @@ CATCH update_firstname flag_allow_update 1 LOAD get_current_profile_info 0 RELOAD get_current_profile_info MAP get_current_profile_info -LOAD save_firstname 128 MOUT back 0 HALT -RELOAD save_firstname INCMP _ 0 +LOAD save_firstname 128 +RELOAD save_firstname CATCH pin_entry flag_firstname_set 1 INCMP edit_family_name * From 1c7c0af712851166a13e3a1f1e4fc98ea8612f1b Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Tue, 3 Dec 2024 14:36:48 +0300 Subject: [PATCH 06/24] catch next unset profile item --- services/registration/edit_family_name.vis | 5 +++++ services/registration/edit_first_name.vis | 6 ++++++ services/registration/edit_location.vis | 2 ++ services/registration/edit_offerings.vis | 1 + services/registration/edit_yob.vis | 4 +++- services/registration/set_female.vis | 4 ++++ services/registration/set_male.vis | 4 ++++ services/registration/set_unspecified.vis | 4 ++++ 8 files changed, 29 insertions(+), 1 deletion(-) diff --git a/services/registration/edit_family_name.vis b/services/registration/edit_family_name.vis index df35970..bc3c308 100644 --- a/services/registration/edit_family_name.vis +++ b/services/registration/edit_family_name.vis @@ -8,4 +8,9 @@ LOAD save_familyname 64 RELOAD save_familyname INCMP _ 0 CATCH pin_entry flag_familyname_set 1 +CATCH select_gender flag_gender_set 0 +CATCH edit_yob flag_yob_set 0 +CATCH edit_location flag_location_set 0 +CATCH edit_offerings flag_offerings_set 0 +CATCH pin_entry flag_familyname_set 0 INCMP select_gender * diff --git a/services/registration/edit_first_name.vis b/services/registration/edit_first_name.vis index f6bfa26..9940af3 100644 --- a/services/registration/edit_first_name.vis +++ b/services/registration/edit_first_name.vis @@ -8,4 +8,10 @@ INCMP _ 0 LOAD save_firstname 128 RELOAD save_firstname CATCH pin_entry flag_firstname_set 1 +CATCH edit_family_name flag_familyname_set 0 +CATCH edit_gender flag_gender_set 0 +CATCH edit_yob flag_yob_set 0 +CATCH edit_location flag_location_set 0 +CATCH edit_offerings flag_offerings_set 0 +CATCH pin_entry flag_firstname_set 0 INCMP edit_family_name * diff --git a/services/registration/edit_location.vis b/services/registration/edit_location.vis index c9bc12d..524df24 100644 --- a/services/registration/edit_location.vis +++ b/services/registration/edit_location.vis @@ -8,4 +8,6 @@ HALT RELOAD save_location INCMP _ 0 CATCH pin_entry flag_location_set 1 +CATCH edit_offerings flag_offerings_set 0 +CATCH pin_entry flag_location_set 0 INCMP edit_offerings * diff --git a/services/registration/edit_offerings.vis b/services/registration/edit_offerings.vis index f95c2ae..65e997e 100644 --- a/services/registration/edit_offerings.vis +++ b/services/registration/edit_offerings.vis @@ -8,4 +8,5 @@ HALT RELOAD save_offerings INCMP _ 0 CATCH pin_entry flag_offerings_set 1 +CATCH pin_entry flag_offerings_set 0 INCMP update_profile_items * diff --git a/services/registration/edit_yob.vis b/services/registration/edit_yob.vis index d0fbcee..787f4ea 100644 --- a/services/registration/edit_yob.vis +++ b/services/registration/edit_yob.vis @@ -12,5 +12,7 @@ LOAD save_yob 32 RELOAD save_yob INCMP _ 0 CATCH pin_entry flag_yob_set 1 +CATCH edit_location flag_location_set 0 +CATCH edit_offerings flag_offerings_set 0 +CATCH pin_entry flag_yob_set 0 INCMP edit_location * - diff --git a/services/registration/set_female.vis b/services/registration/set_female.vis index d1d38bd..5221702 100644 --- a/services/registration/set_female.vis +++ b/services/registration/set_female.vis @@ -2,4 +2,8 @@ LOAD save_gender 32 CATCH incorrect_pin flag_incorrect_pin 1 CATCH update_gender flag_allow_update 1 CATCH pin_entry flag_gender_set 1 +CATCH edit_yob flag_yob_set 0 +CATCH edit_location flag_location_set 0 +CATCH edit_offerings flag_offerings_set 0 +CATCH pin_entry flag_gender_set 0 MOVE edit_yob diff --git a/services/registration/set_male.vis b/services/registration/set_male.vis index e718dfc..c7d20d1 100644 --- a/services/registration/set_male.vis +++ b/services/registration/set_male.vis @@ -2,4 +2,8 @@ LOAD save_gender 16 CATCH incorrect_pin flag_incorrect_pin 1 CATCH update_gender flag_allow_update 1 CATCH pin_entry flag_gender_set 1 +CATCH edit_yob flag_yob_set 0 +CATCH edit_location flag_location_set 0 +CATCH edit_offerings flag_offerings_set 0 +CATCH pin_entry flag_gender_set 0 MOVE edit_yob diff --git a/services/registration/set_unspecified.vis b/services/registration/set_unspecified.vis index e5cfca8..0350500 100644 --- a/services/registration/set_unspecified.vis +++ b/services/registration/set_unspecified.vis @@ -2,4 +2,8 @@ LOAD save_gender 8 CATCH incorrect_pin flag_incorrect_pin 1 CATCH update_gender flag_allow_update 1 CATCH pin_entry flag_gender_set 1 +CATCH edit_yob flag_yob_set 0 +CATCH edit_location flag_location_set 0 +CATCH edit_offerings flag_offerings_set 0 +CATCH pin_entry flag_gender_set 0 MOVE edit_yob From 9e998f9a29bed4c4a7b88c629ad605606b01725a Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Tue, 3 Dec 2024 14:37:55 +0300 Subject: [PATCH 07/24] add a zero pad value to unfilled profile item --- models/profile.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/models/profile.go b/models/profile.go index bdc1f0d..d698318 100644 --- a/models/profile.go +++ b/models/profile.go @@ -9,6 +9,10 @@ func (p *Profile) InsertOrShift(index int, value string) { if index < len(p.ProfileItems) { p.ProfileItems = append(p.ProfileItems[:index], value) } else { - p.ProfileItems = append(p.ProfileItems, value) + for len(p.ProfileItems) < index { + p.ProfileItems = append(p.ProfileItems, "0") + } + p.ProfileItems = append(p.ProfileItems, "0") + p.ProfileItems[index] = value } } From e0ec15b27273cde8da9510c055d2e6d40bf8a87a Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Tue, 3 Dec 2024 14:40:57 +0300 Subject: [PATCH 08/24] allow sequential profile edit --- internal/handlers/ussd/menuhandler.go | 189 ++++++++++++++++++++++---- 1 file changed, 165 insertions(+), 24 deletions(-) diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index 8d3b928..cddb473 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -21,6 +21,7 @@ import ( "git.defalsify.org/vise.git/state" "git.grassecon.net/urdt/ussd/common" "git.grassecon.net/urdt/ussd/internal/utils" + "git.grassecon.net/urdt/ussd/models" "git.grassecon.net/urdt/ussd/remote" "gopkg.in/leonelquinteros/gotext.v1" @@ -78,6 +79,7 @@ type Handlers struct { flagManager *asm.FlagParser accountService remote.AccountServiceInterface prefixDb storage.PrefixDb + profile *models.Profile } func NewHandlers(appFlags *asm.FlagParser, userdataStore db.Db, adminstore *utils.AdminStore, accountService remote.AccountServiceInterface) (*Handlers, error) { @@ -96,6 +98,7 @@ func NewHandlers(appFlags *asm.FlagParser, userdataStore db.Db, adminstore *util adminstore: adminstore, accountService: accountService, prefixDb: prefixDb, + profile: &models.Profile{Max: 6}, } return h, nil } @@ -406,7 +409,10 @@ func (h *Handlers) SaveFirstname(ctx context.Context, sym string, input []byte) firstName := string(input) store := h.userdataStore flag_allow_update, _ := h.flagManager.GetFlag("flag_allow_update") + flag_firstname_set, _ := h.flagManager.GetFlag("flag_firstname_set") + allowUpdate := h.st.MatchFlag(flag_allow_update, true) + firstNameSet := h.st.MatchFlag(flag_firstname_set, true) if allowUpdate { temporaryFirstName, _ := store.ReadEntry(ctx, sessionId, common.DATA_TEMPORARY_VALUE) err = store.WriteEntry(ctx, sessionId, common.DATA_FIRST_NAME, []byte(temporaryFirstName)) @@ -414,11 +420,16 @@ func (h *Handlers) SaveFirstname(ctx context.Context, sym string, input []byte) logg.ErrorCtxf(ctx, "failed to write firstName entry with", "key", common.DATA_FIRST_NAME, "value", temporaryFirstName, "error", err) return res, err } + res.FlagSet = append(res.FlagSet, flag_firstname_set) } else { - err = store.WriteEntry(ctx, sessionId, common.DATA_TEMPORARY_VALUE, []byte(firstName)) - if err != nil { - logg.ErrorCtxf(ctx, "failed to write temporaryFirstName entry with", "key", common.DATA_TEMPORARY_VALUE, "value", firstName, "error", err) - return res, err + if firstNameSet { + err = store.WriteEntry(ctx, sessionId, common.DATA_TEMPORARY_VALUE, []byte(firstName)) + if err != nil { + logg.ErrorCtxf(ctx, "failed to write temporaryFirstName entry with", "key", common.DATA_TEMPORARY_VALUE, "value", firstName, "error", err) + return res, err + } + } else { + h.profile.InsertOrShift(0, firstName) } } @@ -438,7 +449,9 @@ func (h *Handlers) SaveFamilyname(ctx context.Context, sym string, input []byte) familyName := string(input) flag_allow_update, _ := h.flagManager.GetFlag("flag_allow_update") + flag_familyname_set, _ := h.flagManager.GetFlag("flag_familyname_set") allowUpdate := h.st.MatchFlag(flag_allow_update, true) + familyNameSet := h.st.MatchFlag(flag_familyname_set, true) if allowUpdate { temporaryFamilyName, _ := store.ReadEntry(ctx, sessionId, common.DATA_TEMPORARY_VALUE) @@ -447,11 +460,16 @@ func (h *Handlers) SaveFamilyname(ctx context.Context, sym string, input []byte) logg.ErrorCtxf(ctx, "failed to write familyName entry with", "key", common.DATA_FAMILY_NAME, "value", temporaryFamilyName, "error", err) return res, err } + res.FlagSet = append(res.FlagSet, flag_familyname_set) } else { - err = store.WriteEntry(ctx, sessionId, common.DATA_TEMPORARY_VALUE, []byte(familyName)) - if err != nil { - logg.ErrorCtxf(ctx, "failed to write temporaryFamilyName entry with", "key", common.DATA_TEMPORARY_VALUE, "value", familyName, "error", err) - return res, err + if familyNameSet { + err = store.WriteEntry(ctx, sessionId, common.DATA_TEMPORARY_VALUE, []byte(familyName)) + if err != nil { + logg.ErrorCtxf(ctx, "failed to write temporaryFamilyName entry with", "key", common.DATA_TEMPORARY_VALUE, "value", familyName, "error", err) + return res, err + } + } else { + h.profile.InsertOrShift(1, familyName) } } @@ -469,7 +487,10 @@ func (h *Handlers) SaveYob(ctx context.Context, sym string, input []byte) (resou yob := string(input) store := h.userdataStore flag_allow_update, _ := h.flagManager.GetFlag("flag_allow_update") + flag_yob_set, _ := h.flagManager.GetFlag("flag_yob_set") + allowUpdate := h.st.MatchFlag(flag_allow_update, true) + yobSet := h.st.MatchFlag(flag_yob_set, true) if allowUpdate { temporaryYob, _ := store.ReadEntry(ctx, sessionId, common.DATA_TEMPORARY_VALUE) @@ -478,11 +499,16 @@ func (h *Handlers) SaveYob(ctx context.Context, sym string, input []byte) (resou logg.ErrorCtxf(ctx, "failed to write yob entry with", "key", common.DATA_TEMPORARY_VALUE, "value", temporaryYob, "error", err) return res, err } + res.FlagSet = append(res.FlagSet, flag_yob_set) } else { - err = store.WriteEntry(ctx, sessionId, common.DATA_TEMPORARY_VALUE, []byte(yob)) - if err != nil { - logg.ErrorCtxf(ctx, "failed to write temporaryYob entry with", "key", common.DATA_TEMPORARY_VALUE, "value", yob, "error", err) - return res, err + if yobSet { + err = store.WriteEntry(ctx, sessionId, common.DATA_TEMPORARY_VALUE, []byte(yob)) + if err != nil { + logg.ErrorCtxf(ctx, "failed to write temporaryYob entry with", "key", common.DATA_TEMPORARY_VALUE, "value", yob, "error", err) + return res, err + } + } else { + h.profile.InsertOrShift(3, yob) } } @@ -501,7 +527,9 @@ func (h *Handlers) SaveLocation(ctx context.Context, sym string, input []byte) ( store := h.userdataStore flag_allow_update, _ := h.flagManager.GetFlag("flag_allow_update") + flag_location_set, _ := h.flagManager.GetFlag("flag_location_set") allowUpdate := h.st.MatchFlag(flag_allow_update, true) + locationSet := h.st.MatchFlag(flag_location_set, true) if allowUpdate { temporaryLocation, _ := store.ReadEntry(ctx, sessionId, common.DATA_TEMPORARY_VALUE) @@ -511,10 +539,15 @@ func (h *Handlers) SaveLocation(ctx context.Context, sym string, input []byte) ( return res, err } } else { - err = store.WriteEntry(ctx, sessionId, common.DATA_TEMPORARY_VALUE, []byte(location)) - if err != nil { - logg.ErrorCtxf(ctx, "failed to write temporaryLocation entry with", "key", common.DATA_TEMPORARY_VALUE, "value", location, "error", err) - return res, err + if locationSet { + err = store.WriteEntry(ctx, sessionId, common.DATA_TEMPORARY_VALUE, []byte(location)) + if err != nil { + logg.ErrorCtxf(ctx, "failed to write temporaryLocation entry with", "key", common.DATA_TEMPORARY_VALUE, "value", location, "error", err) + return res, err + } + res.FlagSet = append(res.FlagSet, flag_location_set) + } else { + h.profile.InsertOrShift(4, location) } } @@ -533,7 +566,11 @@ func (h *Handlers) SaveGender(ctx context.Context, sym string, input []byte) (re gender := strings.Split(symbol, "_")[1] store := h.userdataStore flag_allow_update, _ := h.flagManager.GetFlag("flag_allow_update") + flag_gender_set, _ := h.flagManager.GetFlag("flag_gender_set") + allowUpdate := h.st.MatchFlag(flag_allow_update, true) + genderSet := h.st.MatchFlag(flag_gender_set, true) + fmt.Println("GenderSet:", genderSet) if allowUpdate { temporaryGender, _ := store.ReadEntry(ctx, sessionId, common.DATA_TEMPORARY_VALUE) @@ -542,11 +579,16 @@ func (h *Handlers) SaveGender(ctx context.Context, sym string, input []byte) (re logg.ErrorCtxf(ctx, "failed to write gender entry with", "key", common.DATA_GENDER, "value", gender, "error", err) return res, err } + res.FlagSet = append(res.FlagSet, flag_gender_set) } else { - err = store.WriteEntry(ctx, sessionId, common.DATA_TEMPORARY_VALUE, []byte(gender)) - if err != nil { - logg.ErrorCtxf(ctx, "failed to write temporaryGender entry with", "key", common.DATA_TEMPORARY_VALUE, "value", gender, "error", err) - return res, err + if genderSet { + err = store.WriteEntry(ctx, sessionId, common.DATA_TEMPORARY_VALUE, []byte(gender)) + if err != nil { + logg.ErrorCtxf(ctx, "failed to write temporaryGender entry with", "key", common.DATA_TEMPORARY_VALUE, "value", gender, "error", err) + return res, err + } + } else { + h.profile.InsertOrShift(2, gender) } } @@ -566,7 +608,10 @@ func (h *Handlers) SaveOfferings(ctx context.Context, sym string, input []byte) store := h.userdataStore flag_allow_update, _ := h.flagManager.GetFlag("flag_allow_update") + flag_offerings_set, _ := h.flagManager.GetFlag("flag_offerings_set") + allowUpdate := h.st.MatchFlag(flag_allow_update, true) + offeringsSet := h.st.MatchFlag(flag_offerings_set, true) if allowUpdate { temporaryOfferings, _ := store.ReadEntry(ctx, sessionId, common.DATA_TEMPORARY_VALUE) @@ -575,11 +620,16 @@ func (h *Handlers) SaveOfferings(ctx context.Context, sym string, input []byte) logg.ErrorCtxf(ctx, "failed to write offerings entry with", "key", common.DATA_TEMPORARY_VALUE, "value", offerings, "error", err) return res, err } + res.FlagSet = append(res.FlagSet, flag_offerings_set) } else { - err = store.WriteEntry(ctx, sessionId, common.DATA_TEMPORARY_VALUE, []byte(offerings)) - if err != nil { - logg.ErrorCtxf(ctx, "failed to write temporaryOfferings entry with", "key", common.DATA_TEMPORARY_VALUE, "value", offerings, "error", err) - return res, err + if offeringsSet { + err = store.WriteEntry(ctx, sessionId, common.DATA_TEMPORARY_VALUE, []byte(offerings)) + if err != nil { + logg.ErrorCtxf(ctx, "failed to write temporaryOfferings entry with", "key", common.DATA_TEMPORARY_VALUE, "value", offerings, "error", err) + return res, err + } + } else { + h.profile.InsertOrShift(5, offerings) } } @@ -1834,3 +1884,94 @@ func (h *Handlers) ViewTransactionStatement(ctx context.Context, sym string, inp return res, nil } + +func (h *Handlers) insertProfileItems(ctx context.Context, sessionId string, res *resource.Result) error { + var err error + store := h.userdataStore + profileFlagNames := []string{ + "flag_firstname_set", + "flag_familyname_set", + "flag_yob_set", + "flag_gender_set", + "flag_location_set", + "flag_offerings_set", + } + for index, profileItem := range h.profile.ProfileItems { + switch index { + case 0: + if profileItem != "0" { + err = store.WriteEntry(ctx, sessionId, common.DATA_FIRST_NAME, []byte(profileItem)) + if err != nil { + logg.ErrorCtxf(ctx, "failed to write profile first name entry with", "key", common.DATA_TEMPORARY_VALUE, "value", profileItem, "error", err) + return err + } + flag, _ := h.flagManager.GetFlag(profileFlagNames[index]) + res.FlagSet = append(res.FlagSet, flag) + } + case 1: + if profileItem != "0" { + err = store.WriteEntry(ctx, sessionId, common.DATA_FAMILY_NAME, []byte(profileItem)) + if err != nil { + logg.ErrorCtxf(ctx, "failed to write profile family name entry with", "key", common.DATA_TEMPORARY_VALUE, "value", profileItem, "error", err) + return err + } + flag, _ := h.flagManager.GetFlag(profileFlagNames[index]) + res.FlagSet = append(res.FlagSet, flag) + } + case 2: + if profileItem != "0" { + err = store.WriteEntry(ctx, sessionId, common.DATA_GENDER, []byte(profileItem)) + if err != nil { + logg.ErrorCtxf(ctx, "failed to write profile gender entry with", "key", common.DATA_TEMPORARY_VALUE, "value", profileItem, "error", err) + return err + } + flag, _ := h.flagManager.GetFlag(profileFlagNames[index]) + res.FlagSet = append(res.FlagSet, flag) + } + case 3: + if profileItem != "0" { + err = store.WriteEntry(ctx, sessionId, common.DATA_YOB, []byte(profileItem)) + if err != nil { + logg.ErrorCtxf(ctx, "failed to write profile yob entry with", "key", common.DATA_TEMPORARY_VALUE, "value", profileItem, "error", err) + return err + } + flag, _ := h.flagManager.GetFlag(profileFlagNames[index]) + res.FlagSet = append(res.FlagSet, flag) + } + case 4: + if profileItem != "0" { + err = store.WriteEntry(ctx, sessionId, common.DATA_LOCATION, []byte(profileItem)) + if err != nil { + logg.ErrorCtxf(ctx, "failed to write profile location entry with", "key", common.DATA_TEMPORARY_VALUE, "value", profileItem, "error", err) + return err + } + flag, _ := h.flagManager.GetFlag(profileFlagNames[index]) + res.FlagSet = append(res.FlagSet, flag) + } + case 5: + if profileItem != "0" { + err = store.WriteEntry(ctx, sessionId, common.DATA_OFFERINGS, []byte(profileItem)) + if err != nil { + logg.ErrorCtxf(ctx, "failed to write profile offerings entry with", "key", common.DATA_TEMPORARY_VALUE, "value", profileItem, "error", err) + return err + } + flag, _ := h.flagManager.GetFlag(profileFlagNames[index]) + res.FlagSet = append(res.FlagSet, flag) + } + } + } + return nil +} + +func (h *Handlers) UpdateAllProfileItems(ctx context.Context, sym string, input []byte) (resource.Result, error) { + var res resource.Result + sessionId, ok := ctx.Value("SessionId").(string) + if !ok { + return res, fmt.Errorf("missing session") + } + err := h.insertProfileItems(ctx, sessionId, &res) + if err != nil { + return res, err + } + return res, nil +} From a20ab793554509ab0bcc9292e140b87008f4e994 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Tue, 3 Dec 2024 17:38:20 +0300 Subject: [PATCH 09/24] explicit reload save gender --- services/registration/set_female.vis | 1 + services/registration/set_male.vis | 1 + services/registration/set_unspecified.vis | 1 + 3 files changed, 3 insertions(+) diff --git a/services/registration/set_female.vis b/services/registration/set_female.vis index 5221702..da92520 100644 --- a/services/registration/set_female.vis +++ b/services/registration/set_female.vis @@ -1,4 +1,5 @@ LOAD save_gender 32 +RELOAD save_gender CATCH incorrect_pin flag_incorrect_pin 1 CATCH update_gender flag_allow_update 1 CATCH pin_entry flag_gender_set 1 diff --git a/services/registration/set_male.vis b/services/registration/set_male.vis index c7d20d1..9a95937 100644 --- a/services/registration/set_male.vis +++ b/services/registration/set_male.vis @@ -1,4 +1,5 @@ LOAD save_gender 16 +RELOAD save_gender CATCH incorrect_pin flag_incorrect_pin 1 CATCH update_gender flag_allow_update 1 CATCH pin_entry flag_gender_set 1 diff --git a/services/registration/set_unspecified.vis b/services/registration/set_unspecified.vis index 0350500..824105c 100644 --- a/services/registration/set_unspecified.vis +++ b/services/registration/set_unspecified.vis @@ -1,4 +1,5 @@ LOAD save_gender 8 +RELOAD save_gender CATCH incorrect_pin flag_incorrect_pin 1 CATCH update_gender flag_allow_update 1 CATCH pin_entry flag_gender_set 1 From b420a9bba0dcbe210946e12daa6bbeeb607fe9a6 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Tue, 3 Dec 2024 17:41:06 +0300 Subject: [PATCH 10/24] set flag if profile data is set --- internal/handlers/ussd/menuhandler.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index cddb473..184e045 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -570,7 +570,6 @@ func (h *Handlers) SaveGender(ctx context.Context, sym string, input []byte) (re allowUpdate := h.st.MatchFlag(flag_allow_update, true) genderSet := h.st.MatchFlag(flag_gender_set, true) - fmt.Println("GenderSet:", genderSet) if allowUpdate { temporaryGender, _ := store.ReadEntry(ctx, sessionId, common.DATA_TEMPORARY_VALUE) @@ -1312,6 +1311,14 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input var res resource.Result var profileInfo []byte var err error + + flag_firstname_set, _ := h.flagManager.GetFlag("flag_firstname_set") + flag_familyname_set, _ := h.flagManager.GetFlag("flag_familyname_set") + flag_yob_set, _ := h.flagManager.GetFlag("flag_yob_set") + flag_gender_set, _ := h.flagManager.GetFlag("flag_gender_set") + flag_location_set, _ := h.flagManager.GetFlag("flag_location_set") + flag_offerings_set, _ := h.flagManager.GetFlag("flag_offerings_set") + sessionId, ok := ctx.Value("SessionId").(string) if !ok { return res, fmt.Errorf("missing session") @@ -1338,6 +1345,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input logg.ErrorCtxf(ctx, "Failed to read first name entry with", "key", "error", common.DATA_FIRST_NAME, err) return res, err } + res.FlagSet = append(res.FlagSet, flag_firstname_set) res.Content = string(profileInfo) case common.DATA_FAMILY_NAME: profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_FAMILY_NAME) @@ -1349,6 +1357,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input logg.ErrorCtxf(ctx, "Failed to read family name entry with", "key", "error", common.DATA_FAMILY_NAME, err) return res, err } + res.FlagSet = append(res.FlagSet, flag_familyname_set) res.Content = string(profileInfo) case common.DATA_GENDER: @@ -1361,6 +1370,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input logg.ErrorCtxf(ctx, "Failed to read gender entry with", "key", "error", common.DATA_GENDER, err) return res, err } + res.FlagSet = append(res.FlagSet, flag_gender_set) res.Content = string(profileInfo) case common.DATA_YOB: profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_YOB) @@ -1372,8 +1382,8 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input logg.ErrorCtxf(ctx, "Failed to read year of birth(yob) entry with", "key", "error", common.DATA_YOB, err) return res, err } + res.FlagSet = append(res.FlagSet, flag_yob_set) res.Content = string(profileInfo) - case common.DATA_LOCATION: profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_LOCATION) if err != nil { @@ -1384,6 +1394,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input logg.ErrorCtxf(ctx, "Failed to read location entry with", "key", "error", common.DATA_LOCATION, err) return res, err } + res.FlagSet = append(res.FlagSet, flag_location_set) res.Content = string(profileInfo) case common.DATA_OFFERINGS: profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_OFFERINGS) @@ -1395,6 +1406,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input logg.ErrorCtxf(ctx, "Failed to read offerings entry with", "key", "error", common.DATA_OFFERINGS, err) return res, err } + res.FlagSet = append(res.FlagSet, flag_offerings_set) res.Content = string(profileInfo) default: break From c0ed6fa9c87c4283b8f9c818931cb1b3761b5403 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Tue, 3 Dec 2024 21:43:24 +0300 Subject: [PATCH 11/24] catch incorrect pin entries --- services/registration/edit_family_name.vis | 1 + services/registration/edit_first_name.vis | 1 + 2 files changed, 2 insertions(+) diff --git a/services/registration/edit_family_name.vis b/services/registration/edit_family_name.vis index bc3c308..31249ce 100644 --- a/services/registration/edit_family_name.vis +++ b/services/registration/edit_family_name.vis @@ -1,3 +1,4 @@ +CATCH incorrect_pin flag_incorrect_pin 1 CATCH update_familyname flag_allow_update 1 LOAD get_current_profile_info 0 RELOAD get_current_profile_info diff --git a/services/registration/edit_first_name.vis b/services/registration/edit_first_name.vis index 9940af3..ad06c92 100644 --- a/services/registration/edit_first_name.vis +++ b/services/registration/edit_first_name.vis @@ -1,3 +1,4 @@ +CATCH incorrect_pin flag_incorrect_pin 1 CATCH update_firstname flag_allow_update 1 LOAD get_current_profile_info 0 RELOAD get_current_profile_info From c4282a870e30e6c31261f6f784da8375bded47a7 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 4 Dec 2024 08:19:20 +0300 Subject: [PATCH 12/24] add flag to catch back navigations --- services/registration/pp.csv | 1 + 1 file changed, 1 insertion(+) diff --git a/services/registration/pp.csv b/services/registration/pp.csv index 6c74b95..26a8833 100644 --- a/services/registration/pp.csv +++ b/services/registration/pp.csv @@ -27,3 +27,4 @@ flag,flag_yob_set,33,this is set when the yob of the profile is set flag,flag_gender_set,34,this is set when the gender of the profile is set flag,flag_location_set,35,this is set when the location of the profile is set flag,flag_offerings_set,36,this is set when the offerings of the profile is set +flag,flag_back_set,37,this is set when it is a back navigation From c5ebdbf85b7f2c7d536d9b7b1849160663915c23 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 4 Dec 2024 08:20:09 +0300 Subject: [PATCH 13/24] catch back navigations --- services/registration/edit_family_name.vis | 3 ++- services/registration/edit_first_name.vis | 4 ++-- services/registration/edit_location.vis | 2 ++ services/registration/edit_offerings.vis | 2 ++ services/registration/edit_profile.vis | 1 + services/registration/edit_yob.vis | 3 ++- 6 files changed, 11 insertions(+), 4 deletions(-) diff --git a/services/registration/edit_family_name.vis b/services/registration/edit_family_name.vis index 31249ce..590eab1 100644 --- a/services/registration/edit_family_name.vis +++ b/services/registration/edit_family_name.vis @@ -5,9 +5,10 @@ RELOAD get_current_profile_info MAP get_current_profile_info MOUT back 0 HALT +RELOAD set_back +CATCH _ flag_back_set 1 LOAD save_familyname 64 RELOAD save_familyname -INCMP _ 0 CATCH pin_entry flag_familyname_set 1 CATCH select_gender flag_gender_set 0 CATCH edit_yob flag_yob_set 0 diff --git a/services/registration/edit_first_name.vis b/services/registration/edit_first_name.vis index ad06c92..6848b9c 100644 --- a/services/registration/edit_first_name.vis +++ b/services/registration/edit_first_name.vis @@ -5,7 +5,8 @@ RELOAD get_current_profile_info MAP get_current_profile_info MOUT back 0 HALT -INCMP _ 0 +RELOAD set_back +CATCH _ flag_back_set 1 LOAD save_firstname 128 RELOAD save_firstname CATCH pin_entry flag_firstname_set 1 @@ -15,4 +16,3 @@ CATCH edit_yob flag_yob_set 0 CATCH edit_location flag_location_set 0 CATCH edit_offerings flag_offerings_set 0 CATCH pin_entry flag_firstname_set 0 -INCMP edit_family_name * diff --git a/services/registration/edit_location.vis b/services/registration/edit_location.vis index 524df24..e4fcd8b 100644 --- a/services/registration/edit_location.vis +++ b/services/registration/edit_location.vis @@ -5,6 +5,8 @@ RELOAD get_current_profile_info LOAD save_location 16 MOUT back 0 HALT +RELOAD set_back +CATCH _ flag_back_set 1 RELOAD save_location INCMP _ 0 CATCH pin_entry flag_location_set 1 diff --git a/services/registration/edit_offerings.vis b/services/registration/edit_offerings.vis index 65e997e..ddbc9e0 100644 --- a/services/registration/edit_offerings.vis +++ b/services/registration/edit_offerings.vis @@ -5,6 +5,8 @@ RELOAD get_current_profile_info LOAD save_offerings 8 MOUT back 0 HALT +RELOAD set_back +CATCH _ flag_back_set 1 RELOAD save_offerings INCMP _ 0 CATCH pin_entry flag_offerings_set 1 diff --git a/services/registration/edit_profile.vis b/services/registration/edit_profile.vis index dff221b..e5ee12b 100644 --- a/services/registration/edit_profile.vis +++ b/services/registration/edit_profile.vis @@ -11,6 +11,7 @@ MOUT edit_offerings 6 MOUT view 7 MOUT back 0 HALT +LOAD set_back 6 INCMP ^ 0 INCMP edit_first_name 1 INCMP edit_family_name 2 diff --git a/services/registration/edit_yob.vis b/services/registration/edit_yob.vis index 787f4ea..255bea5 100644 --- a/services/registration/edit_yob.vis +++ b/services/registration/edit_yob.vis @@ -5,12 +5,13 @@ RELOAD get_current_profile_info MAP get_current_profile_info MOUT back 0 HALT +RELOAD set_back +CATCH _ flag_back_set 1 LOAD verify_yob 6 RELOAD verify_yob CATCH incorrect_date_format flag_incorrect_date_format 1 LOAD save_yob 32 RELOAD save_yob -INCMP _ 0 CATCH pin_entry flag_yob_set 1 CATCH edit_location flag_location_set 0 CATCH edit_offerings flag_offerings_set 0 From 5c202741d6270c36f561ebc8fc49c8662206200b Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 4 Dec 2024 08:20:43 +0300 Subject: [PATCH 14/24] add handler for catching back navigations --- internal/handlers/handlerservice.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/handlers/handlerservice.go b/internal/handlers/handlerservice.go index 13ca70a..a14cf59 100644 --- a/internal/handlers/handlerservice.go +++ b/internal/handlers/handlerservice.go @@ -122,6 +122,7 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountServiceIn ls.DbRs.AddLocalFunc("get_transactions", ussdHandlers.GetTransactionsList) ls.DbRs.AddLocalFunc("view_statement", ussdHandlers.ViewTransactionStatement) ls.DbRs.AddLocalFunc("update_all_profile_items", ussdHandlers.UpdateAllProfileItems) + ls.DbRs.AddLocalFunc("set_back", ussdHandlers.SetBack) return ussdHandlers, nil } From ed632248c5369d0a1bf6084f4620bab18f9195c6 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 4 Dec 2024 08:30:07 +0300 Subject: [PATCH 15/24] add doc lines and check for back naviagtions --- internal/handlers/ussd/menuhandler.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index bd7ee7e..8fc6175 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -726,6 +726,18 @@ func (h *Handlers) ResetIncorrectPin(ctx context.Context, sym string, input []by return res, nil } +// Setback sets the flag_back_set flag when the navigation is back +func (h *Handlers) SetBack(ctx context.Context, sym string, input []byte) (resource.Result, error) { + var res resource.Result + //TODO: + //Add check if the navigation is lateral nav instead of checking the input. + if string(input) == "0" { + flag_back_set, _ := h.flagManager.GetFlag("flag_back_set") + res.FlagSet = append(res.FlagSet, flag_back_set) + } + return res, nil +} + // CheckAccountStatus queries the API using the TrackingId and sets flags // based on the account status func (h *Handlers) CheckAccountStatus(ctx context.Context, sym string, input []byte) (resource.Result, error) { @@ -1332,6 +1344,9 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input flag_gender_set, _ := h.flagManager.GetFlag("flag_gender_set") flag_location_set, _ := h.flagManager.GetFlag("flag_location_set") flag_offerings_set, _ := h.flagManager.GetFlag("flag_offerings_set") + flag_back_set, _ := h.flagManager.GetFlag("flag_back_set") + + res.FlagReset = append(res.FlagReset, flag_back_set) sessionId, ok := ctx.Value("SessionId").(string) if !ok { @@ -2017,6 +2032,7 @@ func (h *Handlers) insertProfileItems(ctx context.Context, sessionId string, res return nil } +// UpdateAllProfileItems is used to persist all the new profile information and setup the required profile flags func (h *Handlers) UpdateAllProfileItems(ctx context.Context, sym string, input []byte) (resource.Result, error) { var res resource.Result sessionId, ok := ctx.Value("SessionId").(string) From e7c4b5bca73cc38241869e69a8b7913cb7de44fb Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 4 Dec 2024 09:08:25 +0300 Subject: [PATCH 16/24] update tests --- internal/handlers/ussd/menuhandler_test.go | 54 +++++++++++++++++----- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/internal/handlers/ussd/menuhandler_test.go b/internal/handlers/ussd/menuhandler_test.go index d7cd855..a1e4f3d 100644 --- a/internal/handlers/ussd/menuhandler_test.go +++ b/internal/handlers/ussd/menuhandler_test.go @@ -179,11 +179,14 @@ func TestSaveFirstname(t *testing.T) { fm, _ := NewFlagManager(flagsPath) flag_allow_update, _ := fm.GetFlag("flag_allow_update") + flag_firstname_set, _ := fm.GetFlag("flag_firstname_set") // Set the flag in the State - mockState := state.NewState(16) + mockState := state.NewState(128) mockState.SetFlag(flag_allow_update) + expectedResult := resource.Result{} + // Define test data firstName := "John" @@ -191,6 +194,8 @@ func TestSaveFirstname(t *testing.T) { t.Fatal(err) } + expectedResult.FlagSet = []uint32{flag_firstname_set} + // Create the Handlers instance with the mock store h := &Handlers{ userdataStore: store, @@ -203,7 +208,7 @@ func TestSaveFirstname(t *testing.T) { // Assert results assert.NoError(t, err) - assert.Equal(t, resource.Result{}, res) + assert.Equal(t, expectedResult, res) // Verify that the DATA_FIRST_NAME entry has been updated with the temporary value storedFirstName, _ := store.ReadEntry(ctx, sessionId, common.DATA_FIRST_NAME) @@ -218,11 +223,16 @@ func TestSaveFamilyname(t *testing.T) { fm, _ := NewFlagManager(flagsPath) flag_allow_update, _ := fm.GetFlag("flag_allow_update") + flag_firstname_set, _ := fm.GetFlag("flag_familyname_set") // Set the flag in the State - mockState := state.NewState(16) + mockState := state.NewState(128) mockState.SetFlag(flag_allow_update) + expectedResult := resource.Result{} + + expectedResult.FlagSet = []uint32{flag_firstname_set} + // Define test data familyName := "Doeee" @@ -242,7 +252,7 @@ func TestSaveFamilyname(t *testing.T) { // Assert results assert.NoError(t, err) - assert.Equal(t, resource.Result{}, res) + assert.Equal(t, expectedResult, res) // Verify that the DATA_FAMILY_NAME entry has been updated with the temporary value storedFamilyName, _ := store.ReadEntry(ctx, sessionId, common.DATA_FAMILY_NAME) @@ -257,11 +267,14 @@ func TestSaveYoB(t *testing.T) { fm, _ := NewFlagManager(flagsPath) flag_allow_update, _ := fm.GetFlag("flag_allow_update") + flag_yob_set, _ := fm.GetFlag("flag_yob_set") // Set the flag in the State - mockState := state.NewState(16) + mockState := state.NewState(108) mockState.SetFlag(flag_allow_update) + expectedResult := resource.Result{} + // Define test data yob := "1980" @@ -269,6 +282,8 @@ func TestSaveYoB(t *testing.T) { t.Fatal(err) } + expectedResult.FlagSet = []uint32{flag_yob_set} + // Create the Handlers instance with the mock store h := &Handlers{ userdataStore: store, @@ -281,7 +296,7 @@ func TestSaveYoB(t *testing.T) { // Assert results assert.NoError(t, err) - assert.Equal(t, resource.Result{}, res) + assert.Equal(t, expectedResult, res) // Verify that the DATA_YOB entry has been updated with the temporary value storedYob, _ := store.ReadEntry(ctx, sessionId, common.DATA_YOB) @@ -296,11 +311,14 @@ func TestSaveLocation(t *testing.T) { fm, _ := NewFlagManager(flagsPath) flag_allow_update, _ := fm.GetFlag("flag_allow_update") + flag_location_set, _ := fm.GetFlag("flag_location_set") // Set the flag in the State - mockState := state.NewState(16) + mockState := state.NewState(108) mockState.SetFlag(flag_allow_update) + expectedResult := resource.Result{} + // Define test data location := "Kilifi" @@ -308,6 +326,8 @@ func TestSaveLocation(t *testing.T) { t.Fatal(err) } + expectedResult.FlagSet = []uint32{flag_location_set} + // Create the Handlers instance with the mock store h := &Handlers{ userdataStore: store, @@ -320,7 +340,7 @@ func TestSaveLocation(t *testing.T) { // Assert results assert.NoError(t, err) - assert.Equal(t, resource.Result{}, res) + assert.Equal(t, expectedResult, res) // Verify that the DATA_LOCATION entry has been updated with the temporary value storedLocation, _ := store.ReadEntry(ctx, sessionId, common.DATA_LOCATION) @@ -335,11 +355,14 @@ func TestSaveOfferings(t *testing.T) { fm, _ := NewFlagManager(flagsPath) flag_allow_update, _ := fm.GetFlag("flag_allow_update") + flag_offerings_set, _ := fm.GetFlag("flag_offerings_set") // Set the flag in the State - mockState := state.NewState(16) + mockState := state.NewState(108) mockState.SetFlag(flag_allow_update) + expectedResult := resource.Result{} + // Define test data offerings := "Bananas" @@ -347,6 +370,8 @@ func TestSaveOfferings(t *testing.T) { t.Fatal(err) } + expectedResult.FlagSet = []uint32{flag_offerings_set} + // Create the Handlers instance with the mock store h := &Handlers{ userdataStore: store, @@ -359,7 +384,7 @@ func TestSaveOfferings(t *testing.T) { // Assert results assert.NoError(t, err) - assert.Equal(t, resource.Result{}, res) + assert.Equal(t, expectedResult, res) // Verify that the DATA_OFFERINGS entry has been updated with the temporary value storedOfferings, _ := store.ReadEntry(ctx, sessionId, common.DATA_OFFERINGS) @@ -374,9 +399,10 @@ func TestSaveGender(t *testing.T) { fm, _ := NewFlagManager(flagsPath) flag_allow_update, _ := fm.GetFlag("flag_allow_update") + flag_gender_set, _ := fm.GetFlag("flag_gender_set") // Set the flag in the State - mockState := state.NewState(16) + mockState := state.NewState(108) mockState.SetFlag(flag_allow_update) // Define test cases @@ -420,12 +446,16 @@ func TestSaveGender(t *testing.T) { flagManager: fm.parser, } + expectedResult := resource.Result{} + // Call the method res, err := h.SaveGender(ctx, "save_gender", tt.input) + expectedResult.FlagSet = []uint32{flag_gender_set} + // Assert results assert.NoError(t, err) - assert.Equal(t, resource.Result{}, res) + assert.Equal(t, expectedResult, res) // Verify that the DATA_GENDER entry has been updated with the temporary value storedGender, _ := store.ReadEntry(ctx, sessionId, common.DATA_GENDER) From 8efed966a053fa8b1cd32af9806f550653b1ae12 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 4 Dec 2024 09:08:47 +0300 Subject: [PATCH 17/24] set flag when location is set --- internal/handlers/ussd/menuhandler.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index 8fc6175..19f9f97 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -543,6 +543,7 @@ func (h *Handlers) SaveLocation(ctx context.Context, sym string, input []byte) ( logg.ErrorCtxf(ctx, "failed to write location entry with", "key", common.DATA_LOCATION, "value", temporaryLocation, "error", err) return res, err } + res.FlagSet = append(res.FlagSet, flag_location_set) } else { if locationSet { err = store.WriteEntry(ctx, sessionId, common.DATA_TEMPORARY_VALUE, []byte(location)) From a84c3e0852d35861776a28889c567041a6c56d8d Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 4 Dec 2024 09:46:16 +0300 Subject: [PATCH 18/24] update menu traversal test data --- menutraversal_test/group_test.json | 50 +++++++++++++----------------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/menutraversal_test/group_test.json b/menutraversal_test/group_test.json index 7985b22..c382816 100644 --- a/menutraversal_test/group_test.json +++ b/menutraversal_test/group_test.json @@ -187,6 +187,26 @@ }, { "input": "foo", + "expectedContent": "Enter family name:\n0:Back" + }, + { + "input": "bar", + "expectedContent": "Select gender: \n1:Male\n2:Female\n3:Unspecified\n0:Back" + }, + { + "input": "1", + "expectedContent": "Enter your year of birth\n0:Back" + }, + { + "input": "1940", + "expectedContent": "Enter your location:\n0:Back" + }, + { + "input": "Kilifi", + "expectedContent": "Enter the services or goods you offer: \n0:Back" + }, + { + "input": "Bananas", "expectedContent": "Please enter your PIN:" }, { @@ -197,10 +217,6 @@ "input": "0", "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" }, - { - "input": "0", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, { "input": "0", "expectedContent": "{balance}\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" @@ -238,10 +254,6 @@ "input": "0", "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" }, - { - "input": "0", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, { "input": "0", "expectedContent": "{balance}\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" @@ -280,10 +292,6 @@ "input": "0", "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" }, - { - "input": "0", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, { "input": "0", "expectedContent": "{balance}\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" @@ -321,10 +329,6 @@ "input": "0", "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" }, - { - "input": "0", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, { "input": "0", "expectedContent": "{balance}\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" @@ -362,10 +366,6 @@ "input": "0", "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" }, - { - "input": "0", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, { "input": "0", "expectedContent": "{balance}\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" @@ -403,10 +403,6 @@ "input": "0", "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" }, - { - "input": "0", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, { "input": "0", "expectedContent": "{balance}\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" @@ -434,16 +430,12 @@ }, { "input": "1234", - "expectedContent": "My profile:\nName: foo bar\nGender: male\nAge: 79\nLocation: Kilifi\nYou provide: Bananas\n\n0:Back" + "expectedContent": "My profile:\nName: foo bar\nGender: male\nAge: 84\nLocation: Kilifi\nYou provide: Bananas\n\n0:Back" }, { "input": "0", "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" }, - { - "input": "0", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, { "input": "0", "expectedContent": "{balance}\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" From 321f038c7ce4492d05bd35572e68d669b7c05a9b Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 5 Dec 2024 10:52:45 +0300 Subject: [PATCH 19/24] iterate over a map for the set profile items --- internal/handlers/ussd/menuhandler.go | 78 +++++++-------------------- 1 file changed, 18 insertions(+), 60 deletions(-) diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index 19f9f97..fef4d98 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -1966,68 +1966,26 @@ func (h *Handlers) insertProfileItems(ctx context.Context, sessionId string, res "flag_location_set", "flag_offerings_set", } + profileDataKeys := map[int]common.DataTyp{ + 0: common.DATA_FIRST_NAME, + 1: common.DATA_FAMILY_NAME, + 2: common.DATA_GENDER, + 3: common.DATA_YOB, + 4: common.DATA_LOCATION, + 5: common.DATA_OFFERINGS, + } for index, profileItem := range h.profile.ProfileItems { - switch index { - case 0: - if profileItem != "0" { - err = store.WriteEntry(ctx, sessionId, common.DATA_FIRST_NAME, []byte(profileItem)) - if err != nil { - logg.ErrorCtxf(ctx, "failed to write profile first name entry with", "key", common.DATA_TEMPORARY_VALUE, "value", profileItem, "error", err) - return err - } - flag, _ := h.flagManager.GetFlag(profileFlagNames[index]) - res.FlagSet = append(res.FlagSet, flag) - } - case 1: - if profileItem != "0" { - err = store.WriteEntry(ctx, sessionId, common.DATA_FAMILY_NAME, []byte(profileItem)) - if err != nil { - logg.ErrorCtxf(ctx, "failed to write profile family name entry with", "key", common.DATA_TEMPORARY_VALUE, "value", profileItem, "error", err) - return err - } - flag, _ := h.flagManager.GetFlag(profileFlagNames[index]) - res.FlagSet = append(res.FlagSet, flag) - } - case 2: - if profileItem != "0" { - err = store.WriteEntry(ctx, sessionId, common.DATA_GENDER, []byte(profileItem)) - if err != nil { - logg.ErrorCtxf(ctx, "failed to write profile gender entry with", "key", common.DATA_TEMPORARY_VALUE, "value", profileItem, "error", err) - return err - } - flag, _ := h.flagManager.GetFlag(profileFlagNames[index]) - res.FlagSet = append(res.FlagSet, flag) - } - case 3: - if profileItem != "0" { - err = store.WriteEntry(ctx, sessionId, common.DATA_YOB, []byte(profileItem)) - if err != nil { - logg.ErrorCtxf(ctx, "failed to write profile yob entry with", "key", common.DATA_TEMPORARY_VALUE, "value", profileItem, "error", err) - return err - } - flag, _ := h.flagManager.GetFlag(profileFlagNames[index]) - res.FlagSet = append(res.FlagSet, flag) - } - case 4: - if profileItem != "0" { - err = store.WriteEntry(ctx, sessionId, common.DATA_LOCATION, []byte(profileItem)) - if err != nil { - logg.ErrorCtxf(ctx, "failed to write profile location entry with", "key", common.DATA_TEMPORARY_VALUE, "value", profileItem, "error", err) - return err - } - flag, _ := h.flagManager.GetFlag(profileFlagNames[index]) - res.FlagSet = append(res.FlagSet, flag) - } - case 5: - if profileItem != "0" { - err = store.WriteEntry(ctx, sessionId, common.DATA_OFFERINGS, []byte(profileItem)) - if err != nil { - logg.ErrorCtxf(ctx, "failed to write profile offerings entry with", "key", common.DATA_TEMPORARY_VALUE, "value", profileItem, "error", err) - return err - } - flag, _ := h.flagManager.GetFlag(profileFlagNames[index]) - res.FlagSet = append(res.FlagSet, flag) + // Ensure the profileItem is not "0"(is set) + if profileItem != "0" { + err = store.WriteEntry(ctx, sessionId, profileDataKeys[index], []byte(profileItem)) + if err != nil { + logg.ErrorCtxf(ctx, "failed to write profile entry with", "key", profileDataKeys[index], "value", profileItem, "error", err) + return err } + + // Get the flag for the current index + flag, _ := h.flagManager.GetFlag(profileFlagNames[index]) + res.FlagSet = append(res.FlagSet, flag) } } return nil From 3e7f90733eef244d93dc122217cb1787c4ce7e49 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 5 Dec 2024 12:22:29 +0300 Subject: [PATCH 20/24] update test names --- menutraversal_test/group_test.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/menutraversal_test/group_test.json b/menutraversal_test/group_test.json index c382816..8f43ff5 100644 --- a/menutraversal_test/group_test.json +++ b/menutraversal_test/group_test.json @@ -167,7 +167,7 @@ ] }, { - "name": "menu_my_account_edit_firstname", + "name": "menu_my_account_edit_all_account_details_starting_from_firstname", "steps": [ { "input": "", @@ -224,7 +224,7 @@ ] }, { - "name": "menu_my_account_edit_familyname", + "name": "menu_my_account_edit_familyname_when_all_account__details_have_been_set", "steps": [ { "input": "", @@ -262,7 +262,7 @@ ] }, { - "name": "menu_my_account_edit_gender", + "name": "menu_my_account_edit_gender_when_all_account__details_have_been_set", "steps": [ { "input": "", @@ -299,7 +299,7 @@ ] }, { - "name": "menu_my_account_edit_yob", + "name": "menu_my_account_edit_yob_when_all_account__details_have_been_set", "steps": [ { "input": "", @@ -336,7 +336,7 @@ ] }, { - "name": "menu_my_account_edit_location", + "name": "menu_my_account_edit_location_when_all_account_details_have_been_set", "steps": [ { "input": "", @@ -373,7 +373,7 @@ ] }, { - "name": "menu_my_account_edit_offerings", + "name": "menu_my_account_edit_offerings_when_all_account__details_have_been_set", "steps": [ { "input": "", From 22f96363ba61352cc23868f5f0d26b75915e0971 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 5 Dec 2024 14:04:56 +0300 Subject: [PATCH 21/24] add test files --- .../profile_edit_start_familyname.json | 68 +++++++++++++++++++ .../profile_edit_start_firstname.json | 61 +++++++++++++++++ .../profile_edit_start_gender.json | 55 +++++++++++++++ .../profile_edit_start_location.json | 46 +++++++++++++ .../profile_edit_start_offerings.json | 42 ++++++++++++ .../profile_edit_start_yob.json | 50 ++++++++++++++ 6 files changed, 322 insertions(+) create mode 100644 menutraversal_test/profile_edit_start_familyname.json create mode 100644 menutraversal_test/profile_edit_start_firstname.json create mode 100644 menutraversal_test/profile_edit_start_gender.json create mode 100644 menutraversal_test/profile_edit_start_location.json create mode 100644 menutraversal_test/profile_edit_start_offerings.json create mode 100644 menutraversal_test/profile_edit_start_yob.json diff --git a/menutraversal_test/profile_edit_start_familyname.json b/menutraversal_test/profile_edit_start_familyname.json new file mode 100644 index 0000000..98325b0 --- /dev/null +++ b/menutraversal_test/profile_edit_start_familyname.json @@ -0,0 +1,68 @@ +{ + "groups": [ + { + "name": "menu_my_account_edit_all_account_details_starting_from_family_name", + "steps": [ + { + "input": "", + "expectedContent": "{balance}\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "1", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "2", + "expectedContent": "Enter family name:\n0:Back" + }, + { + "input": "bar", + "expectedContent": "Select gender: \n1:Male\n2:Female\n3:Unspecified\n0:Back" + }, + { + "input": "1", + "expectedContent": "Enter your year of birth\n0:Back" + }, + { + "input": "1940", + "expectedContent": "Enter your location:\n0:Back" + }, + { + "input": "Kilifi", + "expectedContent": "Enter the services or goods you offer: \n0:Back" + }, + { + "input": "Bananas", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Profile updated successfully\n\n0:Back\n9:Quit" + }, + { + "input": "0", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "0", + "expectedContent": "{balance}\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + } + ] + } + ] +} + + + + + + + + + + + \ No newline at end of file diff --git a/menutraversal_test/profile_edit_start_firstname.json b/menutraversal_test/profile_edit_start_firstname.json new file mode 100644 index 0000000..0f6be8b --- /dev/null +++ b/menutraversal_test/profile_edit_start_firstname.json @@ -0,0 +1,61 @@ +{ + "groups": [ + { + "name": "menu_my_account_edit_all_account_details_starting_from_firstname", + "steps": [ + { + "input": "", + "expectedContent": "{balance}\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "1", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "1", + "expectedContent": "Enter your first names:\n0:Back" + }, + { + "input": "foo", + "expectedContent": "Enter family name:\n0:Back" + }, + { + "input": "bar", + "expectedContent": "Select gender: \n1:Male\n2:Female\n3:Unspecified\n0:Back" + }, + { + "input": "1", + "expectedContent": "Enter your year of birth\n0:Back" + }, + { + "input": "1940", + "expectedContent": "Enter your location:\n0:Back" + }, + { + "input": "Kilifi", + "expectedContent": "Enter the services or goods you offer: \n0:Back" + }, + { + "input": "Bananas", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Profile updated successfully\n\n0:Back\n9:Quit" + }, + { + "input": "0", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "0", + "expectedContent": "{balance}\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + } + ] + } + ] +} diff --git a/menutraversal_test/profile_edit_start_gender.json b/menutraversal_test/profile_edit_start_gender.json new file mode 100644 index 0000000..afca12a --- /dev/null +++ b/menutraversal_test/profile_edit_start_gender.json @@ -0,0 +1,55 @@ +{ + "groups": [ + { + "name": "menu_my_account_edit_all_account_details_starting_from_gender", + "steps": [ + { + "input": "", + "expectedContent": "{balance}\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "1", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "3", + "expectedContent": "Select gender: \n1:Male\n2:Female\n3:Unspecified\n0:Back" + }, + { + "input": "1", + "expectedContent": "Enter your year of birth\n0:Back" + }, + { + "input": "1940", + "expectedContent": "Enter your location:\n0:Back" + }, + { + "input": "Kilifi", + "expectedContent": "Enter the services or goods you offer: \n0:Back" + }, + { + "input": "Bananas", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Profile updated successfully\n\n0:Back\n9:Quit" + }, + { + "input": "0", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "0", + "expectedContent": "{balance}\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + } + ] + } + ] +} + + \ No newline at end of file diff --git a/menutraversal_test/profile_edit_start_location.json b/menutraversal_test/profile_edit_start_location.json new file mode 100644 index 0000000..8852911 --- /dev/null +++ b/menutraversal_test/profile_edit_start_location.json @@ -0,0 +1,46 @@ +{ + "groups": [ + { + "name": "menu_my_account_edit_all_account_details_starting_from_location", + "steps": [ + { + "input": "", + "expectedContent": "{balance}\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "1", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "5", + "expectedContent": "Enter your location:\n0:Back" + }, + { + "input": "Kilifi", + "expectedContent": "Enter the services or goods you offer: \n0:Back" + }, + { + "input": "Bananas", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Profile updated successfully\n\n0:Back\n9:Quit" + }, + { + "input": "0", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "0", + "expectedContent": "{balance}\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + } + ] + } + ] +} + \ No newline at end of file diff --git a/menutraversal_test/profile_edit_start_offerings.json b/menutraversal_test/profile_edit_start_offerings.json new file mode 100644 index 0000000..6aa40f6 --- /dev/null +++ b/menutraversal_test/profile_edit_start_offerings.json @@ -0,0 +1,42 @@ +{ + "groups": [ + { + "name": "menu_my_account_edit_all_account_details_starting_from_offerings", + "steps": [ + { + "input": "", + "expectedContent": "{balance}\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "1", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "6", + "expectedContent": "Enter the services or goods you offer: \n0:Back" + }, + { + "input": "Bananas", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Profile updated successfully\n\n0:Back\n9:Quit" + }, + { + "input": "0", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "0", + "expectedContent": "{balance}\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + } + ] + } + ] +} + \ No newline at end of file diff --git a/menutraversal_test/profile_edit_start_yob.json b/menutraversal_test/profile_edit_start_yob.json new file mode 100644 index 0000000..45227f7 --- /dev/null +++ b/menutraversal_test/profile_edit_start_yob.json @@ -0,0 +1,50 @@ +{ + "groups": [ + { + "name": "menu_my_account_edit_all_account_details_starting_from_yob", + "steps": [ + { + "input": "", + "expectedContent": "{balance}\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "1", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "4", + "expectedContent": "Enter your year of birth\n0:Back" + }, + { + "input": "1940", + "expectedContent": "Enter your location:\n0:Back" + }, + { + "input": "Kilifi", + "expectedContent": "Enter the services or goods you offer: \n0:Back" + }, + { + "input": "Bananas", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Profile updated successfully\n\n0:Back\n9:Quit" + }, + { + "input": "0", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "0", + "expectedContent": "{balance}\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + } + ] + } + ] +} + \ No newline at end of file From 160ccbb220425e242016a3b7d675ca8fe26038e4 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 5 Dec 2024 14:05:32 +0300 Subject: [PATCH 22/24] read test file from test run arg --- menutraversal_test/menu_traversal_test.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/menutraversal_test/menu_traversal_test.go b/menutraversal_test/menu_traversal_test.go index d79b771..28d88db 100644 --- a/menutraversal_test/menu_traversal_test.go +++ b/menutraversal_test/menu_traversal_test.go @@ -3,6 +3,7 @@ package menutraversaltest import ( "bytes" "context" + "flag" "log" "math/rand" "os" @@ -15,14 +16,15 @@ import ( ) var ( - testData = driver.ReadData() - testStore = ".test_state" - groupTestFile = "group_test.json" - sessionID string - src = rand.NewSource(42) - g = rand.New(src) + testData = driver.ReadData() + testStore = ".test_state" + sessionID string + src = rand.NewSource(42) + g = rand.New(src) ) +var groupTestFile = flag.String("test-file", "group_test.json", "The test file to use for running the group tests") + func GenerateSessionId() string { uu := uuid.NewGenWithOptions(uuid.WithRandomReader(g)) v, err := uu.NewV4() @@ -337,7 +339,7 @@ func TestMainMenuSend(t *testing.T) { } func TestGroups(t *testing.T) { - groups, err := driver.LoadTestGroups(groupTestFile) + groups, err := driver.LoadTestGroups(*groupTestFile) if err != nil { log.Fatalf("Failed to load test groups: %v", err) } From 72a3681767572f225df983ba464d970e52a3386c Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 5 Dec 2024 16:03:08 +0300 Subject: [PATCH 23/24] add test data. --- .../profile_edit_when_adjacent_item_set.json | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 menutraversal_test/profile_edit_when_adjacent_item_set.json diff --git a/menutraversal_test/profile_edit_when_adjacent_item_set.json b/menutraversal_test/profile_edit_when_adjacent_item_set.json new file mode 100644 index 0000000..f8d7263 --- /dev/null +++ b/menutraversal_test/profile_edit_when_adjacent_item_set.json @@ -0,0 +1,70 @@ +{ + "groups": [ + { + "name": "menu_my_account_edit_familyname_when_adjacent_profile_information_set", + "steps": [ + { + "input": "", + "expectedContent": "{balance}\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "1", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "3", + "expectedContent": "Select gender: \n1:Male\n2:Female\n3:Unspecified\n0:Back" + }, + { + "input": "1", + "expectedContent": "Enter your year of birth\n0:Back" + }, + { + "input": "1940", + "expectedContent": "Enter your location:\n0:Back" + }, + { + "input": "Kilifi", + "expectedContent": "Enter the services or goods you offer: \n0:Back" + }, + { + "input": "Bananas", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Profile updated successfully\n\n0:Back\n9:Quit" + }, + { + "input": "0", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "2", + "expectedContent": "Enter family name:\n0:Back" + }, + { + "input": "foo2", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Profile updated successfully\n\n0:Back\n9:Quit" + }, + { + "input": "0", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "0", + "expectedContent": "{balance}\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + } + ] + } + ] +} + \ No newline at end of file From 9cbbdff993026f33e05d0eaab7de32dc6a6c7392 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 5 Dec 2024 18:25:51 +0300 Subject: [PATCH 24/24] chore: use profileDataKeys as an array --- internal/handlers/ussd/menuhandler.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index fef4d98..4a1774e 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -1966,13 +1966,13 @@ func (h *Handlers) insertProfileItems(ctx context.Context, sessionId string, res "flag_location_set", "flag_offerings_set", } - profileDataKeys := map[int]common.DataTyp{ - 0: common.DATA_FIRST_NAME, - 1: common.DATA_FAMILY_NAME, - 2: common.DATA_GENDER, - 3: common.DATA_YOB, - 4: common.DATA_LOCATION, - 5: common.DATA_OFFERINGS, + profileDataKeys := []common.DataTyp{ + common.DATA_FIRST_NAME, + common.DATA_FAMILY_NAME, + common.DATA_GENDER, + common.DATA_YOB, + common.DATA_LOCATION, + common.DATA_OFFERINGS, } for index, profileItem := range h.profile.ProfileItems { // Ensure the profileItem is not "0"(is set)