Compare commits
32 Commits
test-cover
...
fix-double
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
272a7ac05f
|
||
|
|
39c0d31995
|
||
|
|
18acb53ead
|
||
|
|
43d91f84f6
|
||
|
0791eb1f11
|
|||
|
|
8ebd2bbbfa
|
||
|
|
06c534cbb1
|
||
|
|
b8d53f82bb
|
||
|
|
71c01e00cd
|
||
|
|
419716a2b4
|
||
|
|
54b2088842
|
||
|
|
b2208359d6 | ||
|
|
0828b1eb10 | ||
|
|
c22f9edeca | ||
|
|
c81b17994a
|
||
|
|
64b42b92ec
|
||
|
|
493f64157b
|
||
|
|
f6c9d54a65
|
||
|
|
74c82de472
|
||
|
|
ddb8c6e748
|
||
|
|
87ebd0029b
|
||
|
|
b941cf2562
|
||
|
|
1c8bda5ded
|
||
|
|
30cb800450
|
||
|
|
680a1e9681
|
||
|
|
b327b569fb
|
||
|
|
445ca0d0ff
|
||
|
|
e681c9cfca
|
||
|
|
d504571014
|
||
|
|
3b16e25ebd
|
||
|
|
5f37856927
|
||
|
|
e564f1328b
|
@@ -21,7 +21,7 @@ RUN make VISE_PATH=/build/go-vise -B
|
|||||||
WORKDIR /build/sarafu-vise
|
WORKDIR /build/sarafu-vise
|
||||||
RUN echo "Building on $BUILDPLATFORM, building for $TARGETPLATFORM"
|
RUN echo "Building on $BUILDPLATFORM, building for $TARGETPLATFORM"
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
RUN go build -tags logtrace,online -o sarafu-at -ldflags="-X main.build=${BUILD} -s -w" cmd/africastalking/main.go
|
RUN go build -tags logwarn,online -o sarafu-at -ldflags="-X main.build=${BUILD} -s -w" cmd/africastalking/main.go
|
||||||
|
|
||||||
FROM debian:bookworm-slim
|
FROM debian:bookworm-slim
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"unicode"
|
||||||
|
|
||||||
"gopkg.in/leonelquinteros/gotext.v1"
|
"gopkg.in/leonelquinteros/gotext.v1"
|
||||||
|
|
||||||
@@ -193,8 +194,9 @@ func (h *MenuHandlers) createAccountNoExist(ctx context.Context, sessionId strin
|
|||||||
publicKey := r.PublicKey
|
publicKey := r.PublicKey
|
||||||
|
|
||||||
data := map[storedb.DataTyp]string{
|
data := map[storedb.DataTyp]string{
|
||||||
storedb.DATA_TRACKING_ID: trackingId,
|
storedb.DATA_TRACKING_ID: trackingId,
|
||||||
storedb.DATA_PUBLIC_KEY: publicKey,
|
storedb.DATA_PUBLIC_KEY: publicKey,
|
||||||
|
storedb.DATA_ACCOUNT_ALIAS: "",
|
||||||
}
|
}
|
||||||
store := h.userdataStore
|
store := h.userdataStore
|
||||||
for key, value := range data {
|
for key, value := range data {
|
||||||
@@ -241,6 +243,28 @@ func (h *MenuHandlers) CreateAccount(ctx context.Context, sym string, input []by
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *MenuHandlers) CheckAccountCreated(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
|
var res resource.Result
|
||||||
|
flag_account_created, _ := h.flagManager.GetFlag("flag_account_created")
|
||||||
|
|
||||||
|
store := h.userdataStore
|
||||||
|
|
||||||
|
sessionId, ok := ctx.Value("SessionId").(string)
|
||||||
|
if !ok {
|
||||||
|
return res, fmt.Errorf("missing session")
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := store.ReadEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY)
|
||||||
|
if err != nil {
|
||||||
|
if !db.IsNotFound(err) {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
res.FlagSet = append(res.FlagSet, flag_account_created)
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
// ResetValidPin resets the flag_valid_pin flag.
|
// ResetValidPin resets the flag_valid_pin flag.
|
||||||
func (h *MenuHandlers) ResetValidPin(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (h *MenuHandlers) ResetValidPin(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
var res resource.Result
|
var res resource.Result
|
||||||
@@ -1120,7 +1144,12 @@ func (h *MenuHandlers) GetCurrentProfileInfo(ctx context.Context, sym string, in
|
|||||||
logg.ErrorCtxf(ctx, "Failed to read account alias entry with", "key", "error", storedb.DATA_ACCOUNT_ALIAS, err)
|
logg.ErrorCtxf(ctx, "Failed to read account alias entry with", "key", "error", storedb.DATA_ACCOUNT_ALIAS, err)
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
res.Content = string(profileInfo)
|
alias := string(profileInfo)
|
||||||
|
if alias == "" {
|
||||||
|
res.Content = defaultValue
|
||||||
|
} else {
|
||||||
|
res.Content = alias
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -1164,8 +1193,10 @@ func (h *MenuHandlers) GetProfileInfo(ctx context.Context, sym string, input []b
|
|||||||
offerings := getEntryOrDefault(store.ReadEntry(ctx, sessionId, storedb.DATA_OFFERINGS))
|
offerings := getEntryOrDefault(store.ReadEntry(ctx, sessionId, storedb.DATA_OFFERINGS))
|
||||||
alias := getEntryOrDefault(store.ReadEntry(ctx, sessionId, storedb.DATA_ACCOUNT_ALIAS))
|
alias := getEntryOrDefault(store.ReadEntry(ctx, sessionId, storedb.DATA_ACCOUNT_ALIAS))
|
||||||
|
|
||||||
if alias != defaultValue {
|
if alias != defaultValue && alias != "" {
|
||||||
alias = strings.Split(alias, ".")[0]
|
alias = strings.Split(alias, ".")[0]
|
||||||
|
} else {
|
||||||
|
alias = defaultValue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct the full name
|
// Construct the full name
|
||||||
@@ -1246,20 +1277,10 @@ func (h *MenuHandlers) UpdateAllProfileItems(ctx context.Context, sym string, in
|
|||||||
if !ok {
|
if !ok {
|
||||||
return res, fmt.Errorf("missing session")
|
return res, fmt.Errorf("missing session")
|
||||||
}
|
}
|
||||||
flag_alias_set, _ := h.flagManager.GetFlag("flag_alias_set")
|
|
||||||
aliasSet := h.st.MatchFlag(flag_alias_set, true)
|
|
||||||
|
|
||||||
err := h.insertProfileItems(ctx, sessionId, &res)
|
err := h.insertProfileItems(ctx, sessionId, &res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
//Only request an alias if it has not been set yet:
|
|
||||||
if !aliasSet {
|
|
||||||
err = h.constructAccountAlias(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1460,7 +1481,7 @@ func loadUserContent(ctx context.Context, activeSym string, balance string, alia
|
|||||||
if alias != "" {
|
if alias != "" {
|
||||||
content = l.Get("%s balance: %s\n", alias, balStr)
|
content = l.Get("%s balance: %s\n", alias, balStr)
|
||||||
} else {
|
} else {
|
||||||
content = l.Get("balance: %s\n", balStr)
|
content = l.Get("Balance: %s\n", balStr)
|
||||||
}
|
}
|
||||||
return content, nil
|
return content, nil
|
||||||
}
|
}
|
||||||
@@ -1468,7 +1489,6 @@ func loadUserContent(ctx context.Context, activeSym string, balance string, alia
|
|||||||
// CheckBalance retrieves the balance of the active voucher and sets
|
// CheckBalance retrieves the balance of the active voucher and sets
|
||||||
// the balance as the result content.
|
// the balance as the result content.
|
||||||
func (h *MenuHandlers) CheckBalance(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (h *MenuHandlers) CheckBalance(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
res resource.Result
|
res resource.Result
|
||||||
err error
|
err error
|
||||||
@@ -1483,19 +1503,10 @@ func (h *MenuHandlers) CheckBalance(ctx context.Context, sym string, input []byt
|
|||||||
|
|
||||||
store := h.userdataStore
|
store := h.userdataStore
|
||||||
|
|
||||||
accAlias, err := store.ReadEntry(ctx, sessionId, storedb.DATA_ACCOUNT_ALIAS)
|
|
||||||
if err != nil {
|
|
||||||
if !db.IsNotFound(err) {
|
|
||||||
logg.ErrorCtxf(ctx, "failed to read account alias entry with", "key", storedb.DATA_ACCOUNT_ALIAS, "error", err)
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
alias = strings.Split(string(accAlias), ".")[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
// get the active sym and active balance
|
// get the active sym and active balance
|
||||||
activeSym, err := store.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_SYM)
|
activeSym, err := store.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_SYM)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logg.InfoCtxf(ctx, "could not find the activeSym in checkBalance:", "err", err)
|
||||||
if !db.IsNotFound(err) {
|
if !db.IsNotFound(err) {
|
||||||
logg.ErrorCtxf(ctx, "failed to read activeSym entry with", "key", storedb.DATA_ACTIVE_SYM, "error", err)
|
logg.ErrorCtxf(ctx, "failed to read activeSym entry with", "key", storedb.DATA_ACTIVE_SYM, "error", err)
|
||||||
return res, err
|
return res, err
|
||||||
@@ -1508,7 +1519,16 @@ func (h *MenuHandlers) CheckBalance(ctx context.Context, sym string, input []byt
|
|||||||
logg.ErrorCtxf(ctx, "failed to read activeBal entry with", "key", storedb.DATA_ACTIVE_BAL, "error", err)
|
logg.ErrorCtxf(ctx, "failed to read activeBal entry with", "key", storedb.DATA_ACTIVE_BAL, "error", err)
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
accAlias, err := store.ReadEntry(ctx, sessionId, storedb.DATA_ACCOUNT_ALIAS)
|
||||||
|
if err != nil {
|
||||||
|
if !db.IsNotFound(err) {
|
||||||
|
logg.ErrorCtxf(ctx, "failed to read account alias entry with", "key", storedb.DATA_ACCOUNT_ALIAS, "error", err)
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
alias = strings.Split(string(accAlias), ".")[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
content, err = loadUserContent(ctx, string(activeSym), string(activeBal), alias)
|
content, err = loadUserContent(ctx, string(activeSym), string(activeBal), alias)
|
||||||
@@ -1930,7 +1950,6 @@ func (h *MenuHandlers) InitiateTransaction(ctx context.Context, sym string, inpu
|
|||||||
// and sets the first as the default voucher, if no active voucher is set.
|
// and sets the first as the default voucher, if no active voucher is set.
|
||||||
func (h *MenuHandlers) SetDefaultVoucher(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (h *MenuHandlers) SetDefaultVoucher(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
var res resource.Result
|
var res resource.Result
|
||||||
var err error
|
|
||||||
userStore := h.userdataStore
|
userStore := h.userdataStore
|
||||||
|
|
||||||
sessionId, ok := ctx.Value("SessionId").(string)
|
sessionId, ok := ctx.Value("SessionId").(string)
|
||||||
@@ -1941,8 +1960,7 @@ func (h *MenuHandlers) SetDefaultVoucher(ctx context.Context, sym string, input
|
|||||||
flag_no_active_voucher, _ := h.flagManager.GetFlag("flag_no_active_voucher")
|
flag_no_active_voucher, _ := h.flagManager.GetFlag("flag_no_active_voucher")
|
||||||
|
|
||||||
// check if the user has an active sym
|
// check if the user has an active sym
|
||||||
_, err = userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_SYM)
|
_, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_SYM)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if db.IsNotFound(err) {
|
if db.IsNotFound(err) {
|
||||||
publicKey, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY)
|
publicKey, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY)
|
||||||
@@ -2034,6 +2052,8 @@ func (h *MenuHandlers) CheckVouchers(ctx context.Context, sym string, input []by
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logg.InfoCtxf(ctx, "fetched user vouchers", "public_key", string(publicKey), "vouchers", vouchersResp)
|
||||||
|
|
||||||
// check the current active sym and update the data
|
// check the current active sym and update the data
|
||||||
activeSym, _ := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_SYM)
|
activeSym, _ := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_SYM)
|
||||||
if activeSym != nil {
|
if activeSym != nil {
|
||||||
@@ -2066,6 +2086,11 @@ func (h *MenuHandlers) CheckVouchers(ctx context.Context, sym string, input []by
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
activeBal, _ := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_BAL)
|
||||||
|
activeAddr, _ := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_ADDRESS)
|
||||||
|
|
||||||
|
logg.InfoCtxf(ctx, "The active data in CheckVouchers:", "activeSym", string(activeSym), string(activeBal), string(activeAddr))
|
||||||
|
|
||||||
data := store.ProcessVouchers(vouchersResp)
|
data := store.ProcessVouchers(vouchersResp)
|
||||||
|
|
||||||
// Store all voucher data
|
// Store all voucher data
|
||||||
@@ -2076,9 +2101,12 @@ func (h *MenuHandlers) CheckVouchers(ctx context.Context, sym string, input []by
|
|||||||
storedb.DATA_VOUCHER_ADDRESSES: data.Addresses,
|
storedb.DATA_VOUCHER_ADDRESSES: data.Addresses,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write data entries
|
||||||
for key, value := range dataMap {
|
for key, value := range dataMap {
|
||||||
if err := h.prefixDb.Put(ctx, []byte(storedb.ToBytes(key)), []byte(value)); err != nil {
|
logg.InfoCtxf(ctx, "Writing data entry for sessionId: %s", sessionId, "key", key, "value", value)
|
||||||
return res, nil
|
if err := userStore.WriteEntry(ctx, sessionId, key, []byte(value)); err != nil {
|
||||||
|
logg.ErrorCtxf(ctx, "Failed to write data entry for sessionId: %s", sessionId, "key", key, "error", err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2088,16 +2116,25 @@ func (h *MenuHandlers) CheckVouchers(ctx context.Context, sym string, input []by
|
|||||||
// GetVoucherList fetches the list of vouchers and formats them.
|
// GetVoucherList fetches the list of vouchers and formats them.
|
||||||
func (h *MenuHandlers) GetVoucherList(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (h *MenuHandlers) GetVoucherList(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
var res resource.Result
|
var res resource.Result
|
||||||
|
sessionId, ok := ctx.Value("SessionId").(string)
|
||||||
|
if !ok {
|
||||||
|
return res, fmt.Errorf("missing session")
|
||||||
|
}
|
||||||
|
|
||||||
|
userStore := h.userdataStore
|
||||||
|
|
||||||
// Read vouchers from the store
|
// Read vouchers from the store
|
||||||
voucherData, err := h.prefixDb.Get(ctx, storedb.ToBytes(storedb.DATA_VOUCHER_SYMBOLS))
|
voucherData, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_VOUCHER_SYMBOLS)
|
||||||
|
logg.InfoCtxf(ctx, "reading GetVoucherList entries for sessionId: %s", sessionId, "key", storedb.DATA_VOUCHER_SYMBOLS, "voucherData", voucherData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logg.ErrorCtxf(ctx, "Failed to read the voucherData from prefixDb", "error", err)
|
logg.ErrorCtxf(ctx, "failed to read voucherData entires with", "key", storedb.DATA_VOUCHER_SYMBOLS, "error", err)
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
formattedData := h.ReplaceSeparatorFunc(string(voucherData))
|
formattedData := h.ReplaceSeparatorFunc(string(voucherData))
|
||||||
|
|
||||||
|
logg.InfoCtxf(ctx, "final output for sessionId: %s", sessionId, "key", storedb.DATA_VOUCHER_SYMBOLS, "formattedData", formattedData)
|
||||||
|
|
||||||
res.Content = string(formattedData)
|
res.Content = string(formattedData)
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
@@ -2124,7 +2161,7 @@ func (h *MenuHandlers) ViewVoucher(ctx context.Context, sym string, input []byte
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata, err := store.GetVoucherData(ctx, h.prefixDb, inputStr)
|
metadata, err := store.GetVoucherData(ctx, h.userdataStore, sessionId, inputStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, fmt.Errorf("failed to retrieve voucher data: %v", err)
|
return res, fmt.Errorf("failed to retrieve voucher data: %v", err)
|
||||||
}
|
}
|
||||||
@@ -2484,15 +2521,17 @@ func (h *MenuHandlers) RequestCustomAlias(ctx context.Context, sym string, input
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
aliasResult, err := h.accountService.RequestAlias(ctx, string(pubKey), string(input))
|
sanitizedInput := sanitizeAliasHint(string(input))
|
||||||
|
aliasResult, err := h.accountService.RequestAlias(ctx, string(pubKey), sanitizedInput)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logg.ErrorCtxf(ctx, "failed to retrieve alias", "alias", string(aliasHint), "error_alias_request", err)
|
logg.ErrorCtxf(ctx, "failed to retrieve alias", "alias", string(aliasHint), "error_alias_request", err)
|
||||||
return res, fmt.Errorf("Failed to retrieve alias: %s", err.Error())
|
return res, fmt.Errorf("Failed to retrieve alias: %s", err.Error())
|
||||||
}
|
}
|
||||||
alias := aliasResult.Alias
|
alias := aliasResult.Alias
|
||||||
|
logg.InfoCtxf(ctx, "Suggested alias ", "alias", alias)
|
||||||
|
|
||||||
//Store the returned alias,wait for user to confirm it as new account alias
|
//Store the returned alias,wait for user to confirm it as new account alias
|
||||||
err = store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(alias))
|
err = store.WriteEntry(ctx, sessionId, storedb.DATA_SUGGESTED_ALIAS, []byte(alias))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logg.ErrorCtxf(ctx, "failed to write account alias", "key", storedb.DATA_TEMPORARY_VALUE, "value", alias, "error", err)
|
logg.ErrorCtxf(ctx, "failed to write account alias", "key", storedb.DATA_TEMPORARY_VALUE, "value", alias, "error", err)
|
||||||
return res, err
|
return res, err
|
||||||
@@ -2501,6 +2540,17 @@ func (h *MenuHandlers) RequestCustomAlias(ctx context.Context, sym string, input
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sanitizeAliasHint(input string) string {
|
||||||
|
for i, r := range input {
|
||||||
|
// Check if the character is a special character (non-alphanumeric)
|
||||||
|
if !unicode.IsLetter(r) && !unicode.IsNumber(r) {
|
||||||
|
return input[:i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If no special character is found, return the whole input
|
||||||
|
return input
|
||||||
|
}
|
||||||
|
|
||||||
// GetSuggestedAlias loads and displays the suggested alias name from the temporary value
|
// GetSuggestedAlias loads and displays the suggested alias name from the temporary value
|
||||||
func (h *MenuHandlers) GetSuggestedAlias(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (h *MenuHandlers) GetSuggestedAlias(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
var res resource.Result
|
var res resource.Result
|
||||||
@@ -2510,7 +2560,7 @@ func (h *MenuHandlers) GetSuggestedAlias(ctx context.Context, sym string, input
|
|||||||
if !ok {
|
if !ok {
|
||||||
return res, fmt.Errorf("missing session")
|
return res, fmt.Errorf("missing session")
|
||||||
}
|
}
|
||||||
suggestedAlias, err := store.ReadEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE)
|
suggestedAlias, err := store.ReadEntry(ctx, sessionId, storedb.DATA_SUGGESTED_ALIAS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
@@ -2518,7 +2568,7 @@ func (h *MenuHandlers) GetSuggestedAlias(ctx context.Context, sym string, input
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConfirmNewAlias reads the suggested alias from the temporary value and confirms it as the new account alias.
|
// ConfirmNewAlias reads the suggested alias from the [DATA_SUGGECTED_ALIAS] key and confirms it as the new account alias.
|
||||||
func (h *MenuHandlers) ConfirmNewAlias(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (h *MenuHandlers) ConfirmNewAlias(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
var res resource.Result
|
var res resource.Result
|
||||||
store := h.userdataStore
|
store := h.userdataStore
|
||||||
@@ -2529,10 +2579,11 @@ func (h *MenuHandlers) ConfirmNewAlias(ctx context.Context, sym string, input []
|
|||||||
if !ok {
|
if !ok {
|
||||||
return res, fmt.Errorf("missing session")
|
return res, fmt.Errorf("missing session")
|
||||||
}
|
}
|
||||||
newAlias, err := store.ReadEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE)
|
newAlias, err := store.ReadEntry(ctx, sessionId, storedb.DATA_SUGGESTED_ALIAS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
logg.InfoCtxf(ctx, "Confirming new alias", "alias", string(newAlias))
|
||||||
err = store.WriteEntry(ctx, sessionId, storedb.DATA_ACCOUNT_ALIAS, []byte(string(newAlias)))
|
err = store.WriteEntry(ctx, sessionId, storedb.DATA_ACCOUNT_ALIAS, []byte(string(newAlias)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logg.ErrorCtxf(ctx, "failed to clear DATA_ACCOUNT_ALIAS_VALUE entry with", "key", storedb.DATA_ACCOUNT_ALIAS, "value", "empty", "error", err)
|
logg.ErrorCtxf(ctx, "failed to clear DATA_ACCOUNT_ALIAS_VALUE entry with", "key", storedb.DATA_ACCOUNT_ALIAS, "value", "empty", "error", err)
|
||||||
|
|||||||
@@ -275,80 +275,36 @@ func TestSaveFirstname(t *testing.T) {
|
|||||||
|
|
||||||
// Set the flag in the State
|
// Set the flag in the State
|
||||||
mockState := state.NewState(128)
|
mockState := state.NewState(128)
|
||||||
|
mockState.SetFlag(flag_allow_update)
|
||||||
|
|
||||||
|
expectedResult := resource.Result{}
|
||||||
|
|
||||||
|
// Define test data
|
||||||
|
firstName := "John"
|
||||||
|
|
||||||
|
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(firstName)); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedResult.FlagSet = []uint32{flag_firstname_set}
|
||||||
|
|
||||||
|
// Create the MenuHandlers instance with the mock store
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
flagManager: fm,
|
flagManager: fm,
|
||||||
st: mockState,
|
st: mockState,
|
||||||
profile: &profile.Profile{Max: 6},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := []struct {
|
// Call the method
|
||||||
name string
|
res, err := h.SaveFirstname(ctx, "save_firstname", []byte(firstName))
|
||||||
setupfunc func()
|
|
||||||
saveItem string
|
|
||||||
expectedSavedItem string
|
|
||||||
expectedResult resource.Result
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "test when `flag_allow_update` flag is set",
|
|
||||||
saveItem: "John",
|
|
||||||
setupfunc: func() {
|
|
||||||
//setup the required flags
|
|
||||||
mockState.SetFlag(flag_allow_update)
|
|
||||||
},
|
|
||||||
expectedSavedItem: "John",
|
|
||||||
expectedResult: resource.Result{
|
|
||||||
FlagSet: []uint32{flag_firstname_set},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "test when `flag_allow_update flag` is not set but `flag_firstname_set` set ",
|
|
||||||
setupfunc: func() {
|
|
||||||
//setup the required flags
|
|
||||||
mockState.ResetFlag(flag_allow_update)
|
|
||||||
mockState.SetFlag(flag_firstname_set)
|
|
||||||
},
|
|
||||||
saveItem: "John",
|
|
||||||
expectedSavedItem: "John",
|
|
||||||
expectedResult: resource.Result{},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "test when both `flag_allow_update flag` `flag_firstname_set` are not set ",
|
|
||||||
setupfunc: func() {
|
|
||||||
//setup the required flags
|
|
||||||
mockState.ResetFlag(flag_allow_update)
|
|
||||||
mockState.ResetFlag(flag_firstname_set)
|
|
||||||
},
|
|
||||||
saveItem: "John",
|
|
||||||
expectedSavedItem: "John",
|
|
||||||
expectedResult: resource.Result{},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
// Assert results
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
assert.NoError(t, err)
|
||||||
tt.setupfunc()
|
assert.Equal(t, expectedResult, res)
|
||||||
|
|
||||||
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(tt.saveItem)); err != nil {
|
// Verify that the DATA_FIRST_NAME entry has been updated with the temporary value
|
||||||
t.Fatal(err)
|
storedFirstName, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_FIRST_NAME)
|
||||||
}
|
assert.Equal(t, firstName, string(storedFirstName))
|
||||||
// Call the method
|
|
||||||
res, err := h.SaveFirstname(ctx, "save_firstname", []byte(tt.saveItem))
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Failed to save firstname with error %v", err)
|
|
||||||
}
|
|
||||||
// Assert results
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, tt.expectedResult, res)
|
|
||||||
|
|
||||||
// Verify that the DATA_FIRST_NAME entry has been updated with the temporary value
|
|
||||||
storedFirstName, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_FIRST_NAME)
|
|
||||||
assert.Equal(t, tt.expectedSavedItem, string(storedFirstName))
|
|
||||||
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSaveFamilyname(t *testing.T) {
|
func TestSaveFamilyname(t *testing.T) {
|
||||||
@@ -359,84 +315,40 @@ func TestSaveFamilyname(t *testing.T) {
|
|||||||
fm, _ := NewFlagManager(flagsPath)
|
fm, _ := NewFlagManager(flagsPath)
|
||||||
|
|
||||||
flag_allow_update, _ := fm.GetFlag("flag_allow_update")
|
flag_allow_update, _ := fm.GetFlag("flag_allow_update")
|
||||||
flag_familyname_set, _ := fm.GetFlag("flag_familyname_set")
|
flag_firstname_set, _ := fm.GetFlag("flag_familyname_set")
|
||||||
|
|
||||||
// Set the flag in the State
|
// Set the flag in the State
|
||||||
mockState := state.NewState(128)
|
mockState := state.NewState(128)
|
||||||
|
mockState.SetFlag(flag_allow_update)
|
||||||
|
|
||||||
|
expectedResult := resource.Result{}
|
||||||
|
|
||||||
|
expectedResult.FlagSet = []uint32{flag_firstname_set}
|
||||||
|
|
||||||
|
// Define test data
|
||||||
|
familyName := "Doeee"
|
||||||
|
|
||||||
|
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(familyName)); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the MenuHandlers instance with the mock store
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
flagManager: fm,
|
|
||||||
st: mockState,
|
st: mockState,
|
||||||
profile: &profile.Profile{Max: 6},
|
flagManager: fm,
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := []struct {
|
// Call the method
|
||||||
name string
|
res, err := h.SaveFamilyname(ctx, "save_familyname", []byte(familyName))
|
||||||
setupfunc func()
|
|
||||||
saveItem string
|
|
||||||
expectedSavedItem string
|
|
||||||
expectedResult resource.Result
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "test when `flag_allow_update` flag is set",
|
|
||||||
saveItem: "Doe",
|
|
||||||
setupfunc: func() {
|
|
||||||
//setup the required flags
|
|
||||||
mockState.SetFlag(flag_allow_update)
|
|
||||||
},
|
|
||||||
expectedSavedItem: "Doe",
|
|
||||||
expectedResult: resource.Result{
|
|
||||||
FlagSet: []uint32{flag_familyname_set},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "test when `flag_allow_update flag` is not set but `flag_familyname_set` set ",
|
|
||||||
setupfunc: func() {
|
|
||||||
//setup the required flags
|
|
||||||
mockState.ResetFlag(flag_allow_update)
|
|
||||||
mockState.SetFlag(flag_familyname_set)
|
|
||||||
},
|
|
||||||
saveItem: "Doe",
|
|
||||||
expectedSavedItem: "Doe",
|
|
||||||
expectedResult: resource.Result{},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "test when both `flag_allow_update flag` `flag_familyname_set` are not set ",
|
|
||||||
setupfunc: func() {
|
|
||||||
//setup the required flags
|
|
||||||
mockState.ResetFlag(flag_allow_update)
|
|
||||||
mockState.ResetFlag(flag_familyname_set)
|
|
||||||
},
|
|
||||||
saveItem: "Doe",
|
|
||||||
expectedSavedItem: "Doe",
|
|
||||||
expectedResult: resource.Result{},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
// Assert results
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
assert.NoError(t, err)
|
||||||
tt.setupfunc()
|
assert.Equal(t, expectedResult, res)
|
||||||
|
|
||||||
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(tt.saveItem)); err != nil {
|
// Verify that the DATA_FAMILY_NAME entry has been updated with the temporary value
|
||||||
t.Fatal(err)
|
storedFamilyName, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_FAMILY_NAME)
|
||||||
}
|
assert.Equal(t, familyName, string(storedFamilyName))
|
||||||
// Call the method
|
|
||||||
res, err := h.SaveFamilyname(ctx, "save_yob", []byte(tt.saveItem))
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Failed to save family name with error %v", err)
|
|
||||||
}
|
|
||||||
// Assert results
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, tt.expectedResult, res)
|
|
||||||
|
|
||||||
// Verify that the DATA_FAMILY_NAME entry has been updated with the temporary value
|
|
||||||
storedFamilyname, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_FAMILY_NAME)
|
|
||||||
assert.Equal(t, tt.expectedSavedItem, string(storedFamilyname))
|
|
||||||
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSaveYoB(t *testing.T) {
|
func TestSaveYoB(t *testing.T) {
|
||||||
@@ -453,83 +365,37 @@ func TestSaveYoB(t *testing.T) {
|
|||||||
mockState := state.NewState(108)
|
mockState := state.NewState(108)
|
||||||
mockState.SetFlag(flag_allow_update)
|
mockState.SetFlag(flag_allow_update)
|
||||||
|
|
||||||
|
expectedResult := resource.Result{}
|
||||||
|
|
||||||
|
// Define test data
|
||||||
|
yob := "1980"
|
||||||
|
|
||||||
|
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(yob)); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedResult.FlagSet = []uint32{flag_yob_set}
|
||||||
|
|
||||||
// Create the MenuHandlers instance with the mock store
|
// Create the MenuHandlers instance with the mock store
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
flagManager: fm,
|
flagManager: fm,
|
||||||
st: mockState,
|
st: mockState,
|
||||||
profile: &profile.Profile{Max: 6},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := []struct {
|
// Call the method
|
||||||
name string
|
res, err := h.SaveYob(ctx, "save_yob", []byte(yob))
|
||||||
setupfunc func()
|
|
||||||
saveItem string
|
|
||||||
expectedSavedItem string
|
|
||||||
expectedResult resource.Result
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "test when `flag_allow_update` flag is set",
|
|
||||||
saveItem: "1980",
|
|
||||||
setupfunc: func() {
|
|
||||||
//setup the required flags
|
|
||||||
mockState.SetFlag(flag_allow_update)
|
|
||||||
},
|
|
||||||
expectedSavedItem: "1980",
|
|
||||||
expectedResult: resource.Result{
|
|
||||||
FlagSet: []uint32{flag_yob_set},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "test when `flag_allow_update flag` is not set but `flag_yob_set` set ",
|
|
||||||
setupfunc: func() {
|
|
||||||
//setup the required flags
|
|
||||||
mockState.ResetFlag(flag_allow_update)
|
|
||||||
mockState.SetFlag(flag_yob_set)
|
|
||||||
},
|
|
||||||
saveItem: "1980",
|
|
||||||
expectedSavedItem: "1980",
|
|
||||||
expectedResult: resource.Result{},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "test when both `flag_allow_update flag` `flag_yob_set` are not set ",
|
|
||||||
setupfunc: func() {
|
|
||||||
//setup the required flags
|
|
||||||
mockState.ResetFlag(flag_allow_update)
|
|
||||||
mockState.ResetFlag(flag_yob_set)
|
|
||||||
},
|
|
||||||
saveItem: "1980",
|
|
||||||
expectedSavedItem: "1980",
|
|
||||||
expectedResult: resource.Result{},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
// Assert results
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
assert.NoError(t, err)
|
||||||
tt.setupfunc()
|
assert.Equal(t, expectedResult, res)
|
||||||
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(tt.saveItem)); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
// Call the method
|
|
||||||
res, err := h.SaveYob(ctx, "save_yob", []byte(tt.saveItem))
|
|
||||||
|
|
||||||
if err != nil {
|
// Verify that the DATA_YOB entry has been updated with the temporary value
|
||||||
t.Fatalf("Failed to save location with error %v", err)
|
storedYob, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_YOB)
|
||||||
}
|
assert.Equal(t, yob, string(storedYob))
|
||||||
// Assert results
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, tt.expectedResult, res)
|
|
||||||
|
|
||||||
// Verify that the DATA_YOB entry has been updated with the temporary value
|
|
||||||
storedYob, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_YOB)
|
|
||||||
assert.Equal(t, tt.expectedSavedItem, string(storedYob))
|
|
||||||
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSaveLocation(t *testing.T) {
|
func TestSaveLocation(t *testing.T) {
|
||||||
|
|
||||||
sessionId := "session123"
|
sessionId := "session123"
|
||||||
ctx, store := InitializeTestStore(t)
|
ctx, store := InitializeTestStore(t)
|
||||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||||
@@ -541,80 +407,36 @@ func TestSaveLocation(t *testing.T) {
|
|||||||
|
|
||||||
// Set the flag in the State
|
// Set the flag in the State
|
||||||
mockState := state.NewState(108)
|
mockState := state.NewState(108)
|
||||||
|
mockState.SetFlag(flag_allow_update)
|
||||||
|
|
||||||
|
expectedResult := resource.Result{}
|
||||||
|
|
||||||
|
// Define test data
|
||||||
|
location := "Kilifi"
|
||||||
|
|
||||||
|
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(location)); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedResult.FlagSet = []uint32{flag_location_set}
|
||||||
|
|
||||||
// Create the MenuHandlers instance with the mock store
|
// Create the MenuHandlers instance with the mock store
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
flagManager: fm,
|
flagManager: fm,
|
||||||
profile: &profile.Profile{Max: 6},
|
|
||||||
st: mockState,
|
st: mockState,
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := []struct {
|
// Call the method
|
||||||
name string
|
res, err := h.SaveLocation(ctx, "save_location", []byte(location))
|
||||||
setupfunc func()
|
|
||||||
saveItem string
|
|
||||||
expectedSavedItem string
|
|
||||||
expectedResult resource.Result
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "test when `flag_allow_update` flag is set",
|
|
||||||
saveItem: "Kilifi",
|
|
||||||
setupfunc: func() {
|
|
||||||
//setup the required flags
|
|
||||||
mockState.SetFlag(flag_allow_update)
|
|
||||||
},
|
|
||||||
expectedSavedItem: "Kilifi",
|
|
||||||
expectedResult: resource.Result{
|
|
||||||
FlagSet: []uint32{flag_location_set},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "test when `flag_allow_update flag` is not set but `flag_location_set` set ",
|
|
||||||
setupfunc: func() {
|
|
||||||
//setup the required flags
|
|
||||||
mockState.ResetFlag(flag_allow_update)
|
|
||||||
mockState.SetFlag(flag_location_set)
|
|
||||||
},
|
|
||||||
saveItem: "Kilifi",
|
|
||||||
expectedSavedItem: "Kilifi",
|
|
||||||
expectedResult: resource.Result{FlagSet: []uint32{flag_location_set}},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "test when both `flag_allow_update flag` `flag_location_set` are not set ",
|
|
||||||
setupfunc: func() {
|
|
||||||
//setup the required flags
|
|
||||||
mockState.ResetFlag(flag_allow_update)
|
|
||||||
mockState.ResetFlag(flag_location_set)
|
|
||||||
},
|
|
||||||
saveItem: "Kilifi",
|
|
||||||
expectedSavedItem: "Kilifi",
|
|
||||||
expectedResult: resource.Result{},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
// Assert results
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
assert.NoError(t, err)
|
||||||
tt.setupfunc()
|
assert.Equal(t, expectedResult, res)
|
||||||
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(tt.saveItem)); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
// Call the method
|
|
||||||
res, err := h.SaveLocation(ctx, "save_location", []byte(tt.saveItem))
|
|
||||||
|
|
||||||
if err != nil {
|
// Verify that the DATA_LOCATION entry has been updated with the temporary value
|
||||||
t.Fatalf("Failed to save location with error %v", err)
|
storedLocation, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_LOCATION)
|
||||||
}
|
assert.Equal(t, location, string(storedLocation))
|
||||||
// Assert results
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, tt.expectedResult, res)
|
|
||||||
|
|
||||||
// Verify that the DATA_LOCATION entry has been updated with the temporary value
|
|
||||||
storedLocation, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_LOCATION)
|
|
||||||
assert.Equal(t, tt.expectedSavedItem, string(storedLocation))
|
|
||||||
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSaveOfferings(t *testing.T) {
|
func TestSaveOfferings(t *testing.T) {
|
||||||
@@ -629,76 +451,36 @@ func TestSaveOfferings(t *testing.T) {
|
|||||||
|
|
||||||
// Set the flag in the State
|
// Set the flag in the State
|
||||||
mockState := state.NewState(108)
|
mockState := state.NewState(108)
|
||||||
|
mockState.SetFlag(flag_allow_update)
|
||||||
|
|
||||||
|
expectedResult := resource.Result{}
|
||||||
|
|
||||||
|
// Define test data
|
||||||
|
offerings := "Bananas"
|
||||||
|
|
||||||
|
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(offerings)); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedResult.FlagSet = []uint32{flag_offerings_set}
|
||||||
|
|
||||||
|
// Create the MenuHandlers instance with the mock store
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
flagManager: fm,
|
flagManager: fm,
|
||||||
st: mockState,
|
st: mockState,
|
||||||
profile: &profile.Profile{Max: 6},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := []struct {
|
// Call the method
|
||||||
name string
|
res, err := h.SaveOfferings(ctx, "save_offerings", []byte(offerings))
|
||||||
setupfunc func()
|
|
||||||
saveItem string
|
|
||||||
expectedSavedItem string
|
|
||||||
expectedResult resource.Result
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "test when `flag_allow_update` flag is set",
|
|
||||||
saveItem: "Bananas",
|
|
||||||
setupfunc: func() {
|
|
||||||
//setup the required flags
|
|
||||||
mockState.SetFlag(flag_allow_update)
|
|
||||||
},
|
|
||||||
expectedSavedItem: "Bananas",
|
|
||||||
expectedResult: resource.Result{
|
|
||||||
FlagSet: []uint32{flag_offerings_set},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "test when `flag_allow_update flag` is not set but `flag_offerings_set` set ",
|
|
||||||
setupfunc: func() {
|
|
||||||
//setup the required flags
|
|
||||||
mockState.ResetFlag(flag_allow_update)
|
|
||||||
mockState.SetFlag(flag_offerings_set)
|
|
||||||
},
|
|
||||||
saveItem: "Bananas",
|
|
||||||
expectedSavedItem: "Bananas",
|
|
||||||
expectedResult: resource.Result{},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "test when both `flag_allow_update flag` `flag_offerings_set` are not set ",
|
|
||||||
setupfunc: func() {
|
|
||||||
//setup the required flags
|
|
||||||
mockState.ResetFlag(flag_allow_update)
|
|
||||||
mockState.ResetFlag(flag_offerings_set)
|
|
||||||
},
|
|
||||||
saveItem: "Bananas",
|
|
||||||
expectedSavedItem: "Bananas",
|
|
||||||
expectedResult: resource.Result{},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
// Assert results
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
assert.NoError(t, err)
|
||||||
tt.setupfunc()
|
assert.Equal(t, expectedResult, res)
|
||||||
|
|
||||||
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(tt.saveItem)); err != nil {
|
// Verify that the DATA_OFFERINGS entry has been updated with the temporary value
|
||||||
t.Fatal(err)
|
storedOfferings, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_OFFERINGS)
|
||||||
}
|
assert.Equal(t, offerings, string(storedOfferings))
|
||||||
|
|
||||||
res, err := h.SaveOfferings(ctx, "save_offerings", []byte(tt.saveItem))
|
|
||||||
|
|
||||||
// Assert results
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, tt.expectedResult, res)
|
|
||||||
|
|
||||||
// Verify that the DATA_OFFERINGS entry has been updated with the temporary value
|
|
||||||
storedOfferings, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_OFFERINGS)
|
|
||||||
assert.Equal(t, tt.expectedSavedItem, string(storedOfferings))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSaveGender(t *testing.T) {
|
func TestSaveGender(t *testing.T) {
|
||||||
@@ -713,89 +495,63 @@ func TestSaveGender(t *testing.T) {
|
|||||||
|
|
||||||
// Set the flag in the State
|
// Set the flag in the State
|
||||||
mockState := state.NewState(108)
|
mockState := state.NewState(108)
|
||||||
|
mockState.SetFlag(flag_allow_update)
|
||||||
|
|
||||||
// Define test cases
|
// Define test cases
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
setupfunc func()
|
|
||||||
input []byte
|
input []byte
|
||||||
expectedGender string
|
expectedGender string
|
||||||
expectedResult resource.Result
|
|
||||||
executingSymbol string
|
executingSymbol string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Valid Male Input with `flag_allow_update_set` set",
|
name: "Valid Male Input",
|
||||||
input: []byte("1"),
|
input: []byte("1"),
|
||||||
setupfunc: func() {
|
|
||||||
mockState.SetFlag(flag_allow_update)
|
|
||||||
mockState.ExecPath = []string{}
|
|
||||||
},
|
|
||||||
expectedGender: "male",
|
expectedGender: "male",
|
||||||
executingSymbol: "set_male",
|
executingSymbol: "set_male",
|
||||||
expectedResult: resource.Result{
|
|
||||||
FlagSet: []uint32{flag_gender_set},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Valid Female Input when `flag_allow_update` is not set but `flag_gender_set` is set",
|
name: "Valid Female Input",
|
||||||
input: []byte("2"),
|
input: []byte("2"),
|
||||||
setupfunc: func() {
|
|
||||||
mockState.ResetFlag(flag_allow_update)
|
|
||||||
mockState.SetFlag(flag_gender_set)
|
|
||||||
mockState.ExecPath = []string{}
|
|
||||||
},
|
|
||||||
expectedResult: resource.Result{},
|
|
||||||
expectedGender: "female",
|
expectedGender: "female",
|
||||||
executingSymbol: "set_female",
|
executingSymbol: "set_female",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Valid Unspecified Input when both `flag_allow_update` and `flag_gender_set` are not set",
|
name: "Valid Unspecified Input",
|
||||||
setupfunc: func() {
|
|
||||||
mockState.ResetFlag(flag_allow_update)
|
|
||||||
mockState.ResetFlag(flag_gender_set)
|
|
||||||
mockState.ExecPath = []string{}
|
|
||||||
},
|
|
||||||
input: []byte("3"),
|
input: []byte("3"),
|
||||||
executingSymbol: "set_unspecified",
|
executingSymbol: "set_unspecified",
|
||||||
expectedResult: resource.Result{},
|
|
||||||
expectedGender: "unspecified",
|
expectedGender: "unspecified",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
tt.setupfunc()
|
|
||||||
mockState.ExecPath = append(mockState.ExecPath, tt.executingSymbol)
|
|
||||||
|
|
||||||
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(tt.expectedGender)); err != nil {
|
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(tt.expectedGender)); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mockState.ExecPath = append(mockState.ExecPath, tt.executingSymbol)
|
||||||
// Create the MenuHandlers instance with the mock store
|
// Create the MenuHandlers instance with the mock store
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
st: mockState,
|
st: mockState,
|
||||||
flagManager: fm,
|
flagManager: fm,
|
||||||
profile: &profile.Profile{Max: 6},
|
|
||||||
}
|
}
|
||||||
allowUpdate := h.st.MatchFlag(flag_allow_update, true)
|
|
||||||
|
expectedResult := resource.Result{}
|
||||||
|
|
||||||
// Call the method
|
// Call the method
|
||||||
res, err := h.SaveGender(ctx, "save_gender", tt.input)
|
res, err := h.SaveGender(ctx, "save_gender", tt.input)
|
||||||
|
|
||||||
|
expectedResult.FlagSet = []uint32{flag_gender_set}
|
||||||
|
|
||||||
// Assert results
|
// Assert results
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, tt.expectedResult, res)
|
assert.Equal(t, expectedResult, res)
|
||||||
|
|
||||||
// Verify that the DATA_GENDER entry if the flag_allow_update is set has been updated with the temporary value
|
// Verify that the DATA_GENDER entry has been updated with the temporary value
|
||||||
if allowUpdate {
|
storedGender, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_GENDER)
|
||||||
storedGender, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_GENDER)
|
assert.Equal(t, tt.expectedGender, string(storedGender))
|
||||||
assert.Equal(t, tt.expectedGender, string(storedGender))
|
|
||||||
} else {
|
|
||||||
// Verify that DATA_TEMPORARY_VALUE is updated with the latest user input
|
|
||||||
temporaryGenderValue, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE)
|
|
||||||
assert.Equal(t, tt.expectedGender, string(temporaryGenderValue))
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1315,15 +1071,8 @@ func TestAuthorize(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Test with PIN that is more than 4 digits",
|
name: "Test with pin that is not a 4 digit",
|
||||||
input: []byte("12357"),
|
input: []byte("1235aqds"),
|
||||||
expectedResult: resource.Result{
|
|
||||||
FlagSet: []uint32{flag_invalid_pin},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Test with pin that is less than 4 digit",
|
|
||||||
input: []byte("123"),
|
|
||||||
expectedResult: resource.Result{
|
expectedResult: resource.Result{
|
||||||
FlagSet: []uint32{flag_invalid_pin},
|
FlagSet: []uint32{flag_invalid_pin},
|
||||||
},
|
},
|
||||||
@@ -1901,7 +1650,7 @@ func TestValidateRecipient(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Test with valid unregistered recipient",
|
name: "Test with valid unregistered recepient",
|
||||||
input: []byte("0712345678"),
|
input: []byte("0712345678"),
|
||||||
expectedResult: resource.Result{
|
expectedResult: resource.Result{
|
||||||
FlagSet: []uint32{flag_invalid_recipient_with_invite},
|
FlagSet: []uint32{flag_invalid_recipient_with_invite},
|
||||||
@@ -1909,7 +1658,7 @@ func TestValidateRecipient(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Test with valid registered recipient",
|
name: "Test with valid registered recepient",
|
||||||
input: []byte("0711223344"),
|
input: []byte("0711223344"),
|
||||||
expectedResult: resource.Result{},
|
expectedResult: resource.Result{},
|
||||||
},
|
},
|
||||||
@@ -1919,12 +1668,7 @@ func TestValidateRecipient(t *testing.T) {
|
|||||||
expectedResult: resource.Result{},
|
expectedResult: resource.Result{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Test with alias recipient",
|
name: "Test with alias recepient",
|
||||||
input: []byte("foobar.sarafu.eth"),
|
|
||||||
expectedResult: resource.Result{},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Test with alias recipient",
|
|
||||||
input: []byte("alias123.sarafu.local"),
|
input: []byte("alias123.sarafu.local"),
|
||||||
expectedResult: resource.Result{},
|
expectedResult: resource.Result{},
|
||||||
},
|
},
|
||||||
@@ -1953,7 +1697,7 @@ func TestValidateRecipient(t *testing.T) {
|
|||||||
mockAccountService.On("CheckAliasAddress", string(tt.input)).Return(aliasResponse, nil)
|
mockAccountService.On("CheckAliasAddress", string(tt.input)).Return(aliasResponse, nil)
|
||||||
|
|
||||||
// Call the method
|
// Call the method
|
||||||
res, err := h.ValidateRecipient(ctx, "validate_recipient", tt.input)
|
res, err := h.ValidateRecipient(ctx, "validate_recepient", tt.input)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
@@ -1983,7 +1727,7 @@ func TestCheckBalance(t *testing.T) {
|
|||||||
publicKey: "0X98765432109",
|
publicKey: "0X98765432109",
|
||||||
activeSym: "ETH",
|
activeSym: "ETH",
|
||||||
activeBal: "1.5",
|
activeBal: "1.5",
|
||||||
expectedResult: resource.Result{Content: "balance: 1.50 ETH\n"},
|
expectedResult: resource.Result{Content: "Balance: 1.50 ETH\n"},
|
||||||
expectError: false,
|
expectError: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -2323,12 +2067,10 @@ func TestCheckVouchers(t *testing.T) {
|
|||||||
|
|
||||||
ctx, store := InitializeTestStore(t)
|
ctx, store := InitializeTestStore(t)
|
||||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||||
spdb := InitializeTestSubPrefixDb(t, ctx)
|
|
||||||
|
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
accountService: mockAccountService,
|
accountService: mockAccountService,
|
||||||
prefixDb: spdb,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err := store.WriteEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY, []byte(publicKey))
|
err := store.WriteEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY, []byte(publicKey))
|
||||||
@@ -2360,7 +2102,7 @@ func TestCheckVouchers(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// Read voucher sym data from the store
|
// Read voucher sym data from the store
|
||||||
voucherData, err := spdb.Get(ctx, storedb.ToBytes(storedb.DATA_VOUCHER_SYMBOLS))
|
voucherData, err := store.ReadEntry(ctx, sessionId, storedb.DATA_VOUCHER_SYMBOLS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -2382,20 +2124,19 @@ func TestCheckVouchers(t *testing.T) {
|
|||||||
func TestGetVoucherList(t *testing.T) {
|
func TestGetVoucherList(t *testing.T) {
|
||||||
sessionId := "session123"
|
sessionId := "session123"
|
||||||
|
|
||||||
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
ctx, store := InitializeTestStore(t)
|
||||||
|
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||||
spdb := InitializeTestSubPrefixDb(t, ctx)
|
|
||||||
|
|
||||||
// Initialize MenuHandlers
|
// Initialize MenuHandlers
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
prefixDb: spdb,
|
userdataStore: store,
|
||||||
ReplaceSeparatorFunc: mockReplaceSeparator,
|
ReplaceSeparatorFunc: mockReplaceSeparator,
|
||||||
}
|
}
|
||||||
|
|
||||||
mockSyms := []byte("1:SRF\n2:MILO")
|
mockSyms := []byte("1:SRF\n2:MILO")
|
||||||
|
|
||||||
// Put voucher sym data from the store
|
// Put voucher sym data from the store
|
||||||
err := spdb.Put(ctx, storedb.ToBytes(storedb.DATA_VOUCHER_SYMBOLS), mockSyms)
|
err := store.WriteEntry(ctx, sessionId, storedb.DATA_VOUCHER_SYMBOLS, mockSyms)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -2415,15 +2156,11 @@ func TestViewVoucher(t *testing.T) {
|
|||||||
}
|
}
|
||||||
ctx, store := InitializeTestStore(t)
|
ctx, store := InitializeTestStore(t)
|
||||||
sessionId := "session123"
|
sessionId := "session123"
|
||||||
|
|
||||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||||
|
|
||||||
spdb := InitializeTestSubPrefixDb(t, ctx)
|
|
||||||
|
|
||||||
h := &MenuHandlers{
|
h := &MenuHandlers{
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
flagManager: fm,
|
flagManager: fm,
|
||||||
prefixDb: spdb,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define mock voucher data
|
// Define mock voucher data
|
||||||
@@ -2436,7 +2173,7 @@ func TestViewVoucher(t *testing.T) {
|
|||||||
|
|
||||||
// Put the data
|
// Put the data
|
||||||
for key, value := range mockData {
|
for key, value := range mockData {
|
||||||
err = spdb.Put(ctx, []byte(storedb.ToBytes(key)), []byte(value))
|
err := store.WriteEntry(ctx, sessionId, key, []byte(value))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -3336,53 +3073,6 @@ func TestCheckBlockedNumPinMisMatch(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetBack(t *testing.T) {
|
|
||||||
ctx, store := InitializeTestStore(t)
|
|
||||||
|
|
||||||
fm, err := NewFlagManager(flagsPath)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
h := &MenuHandlers{
|
|
||||||
userdataStore: store,
|
|
||||||
flagManager: fm,
|
|
||||||
st: state.NewState(16),
|
|
||||||
}
|
|
||||||
|
|
||||||
flag_back_set, _ := h.flagManager.GetFlag("flag_back_set")
|
|
||||||
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
input []byte
|
|
||||||
expectedResult resource.Result
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "Test with `0` input for back navigation",
|
|
||||||
input: []byte("0"),
|
|
||||||
expectedResult: resource.Result{
|
|
||||||
FlagSet: []uint32{flag_back_set},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Test with input that is not back",
|
|
||||||
input: []byte("1345"),
|
|
||||||
expectedResult: resource.Result{
|
|
||||||
FlagReset: []uint32{flag_back_set},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
//Call the function under test
|
|
||||||
res, _ := h.SetBack(ctx, "set_back", tt.input)
|
|
||||||
|
|
||||||
//Assert that the result set to content is what was expected
|
|
||||||
assert.Equal(t, res, tt.expectedResult, "Result should contain flags set according to user input")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetCurrentProfileInfo(t *testing.T) {
|
func TestGetCurrentProfileInfo(t *testing.T) {
|
||||||
sessionId := "session123"
|
sessionId := "session123"
|
||||||
ctx, store := InitializeTestStore(t)
|
ctx, store := InitializeTestStore(t)
|
||||||
@@ -3779,15 +3469,6 @@ func TestUpdateAllProfileItems(t *testing.T) {
|
|||||||
err = store.WriteEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY, []byte(publicKey))
|
err = store.WriteEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY, []byte(publicKey))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
aliasInput := fmt.Sprintf("%s%s", profileItems[0], profileItems[1])
|
|
||||||
|
|
||||||
// Mock the account alias response
|
|
||||||
mockAccountService.On(
|
|
||||||
"RequestAlias",
|
|
||||||
publicKey,
|
|
||||||
aliasInput,
|
|
||||||
).Return(&models.RequestAliasResult{Alias: "JohnDoe"}, nil)
|
|
||||||
|
|
||||||
// Call the function under test
|
// Call the function under test
|
||||||
res, err := h.UpdateAllProfileItems(ctx, "symbol", nil)
|
res, err := h.UpdateAllProfileItems(ctx, "symbol", nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
@@ -3799,10 +3480,6 @@ func TestUpdateAllProfileItems(t *testing.T) {
|
|||||||
assert.Equal(t, profileItems[i], string(storedValue))
|
assert.Equal(t, profileItems[i], string(storedValue))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate alias storage
|
|
||||||
storedAlias, err := store.ReadEntry(ctx, sessionId, storedb.DATA_ACCOUNT_ALIAS)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, "JohnDoe", string(storedAlias))
|
|
||||||
assert.Equal(t, expectedResult, res)
|
assert.Equal(t, expectedResult, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3834,70 +3511,3 @@ func TestClearTemporaryValue(t *testing.T) {
|
|||||||
// assert that the temp value is empty
|
// assert that the temp value is empty
|
||||||
assert.Equal(t, currentTempValue, []byte(""))
|
assert.Equal(t, currentTempValue, []byte(""))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetSuggestedAlias(t *testing.T) {
|
|
||||||
ctx, store := InitializeTestStore(t)
|
|
||||||
sessionId := "session123"
|
|
||||||
alias := "foo.sarafu.eth"
|
|
||||||
|
|
||||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
|
||||||
|
|
||||||
h := &MenuHandlers{
|
|
||||||
userdataStore: store,
|
|
||||||
}
|
|
||||||
|
|
||||||
//Set a suggested alias a temporary value that will be expected to be in the result content
|
|
||||||
err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(alias))
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
res, err := h.GetSuggestedAlias(ctx, "getsuggested_alias", []byte(""))
|
|
||||||
if err != nil {
|
|
||||||
t.Fail()
|
|
||||||
}
|
|
||||||
assert.Equal(t, res.Content, alias)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestConfirmNewAlias(t *testing.T) {
|
|
||||||
ctx, store := InitializeTestStore(t)
|
|
||||||
sessionId := "session123"
|
|
||||||
expectedSavedAlias := "fooo.sarafu.eth"
|
|
||||||
|
|
||||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
|
||||||
|
|
||||||
//Set a temporary alias that is suggested,confirm if the the current new alias after confirmation
|
|
||||||
err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(expectedSavedAlias))
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
mockState := state.NewState(128)
|
|
||||||
|
|
||||||
fm, err := NewFlagManager(flagsPath)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
h := &MenuHandlers{
|
|
||||||
userdataStore: store,
|
|
||||||
st: mockState,
|
|
||||||
flagManager: fm,
|
|
||||||
}
|
|
||||||
flag_alias_set, _ := h.flagManager.GetFlag("flag_alias_set")
|
|
||||||
|
|
||||||
expectedResult := resource.Result{
|
|
||||||
FlagSet: []uint32{flag_alias_set},
|
|
||||||
}
|
|
||||||
|
|
||||||
res, err := h.ConfirmNewAlias(ctx, "confirm_new_alias", []byte(""))
|
|
||||||
if err != nil {
|
|
||||||
t.Fail()
|
|
||||||
}
|
|
||||||
accAlias, err := store.ReadEntry(ctx, sessionId, storedb.DATA_ACCOUNT_ALIAS)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
assert.Equal(t, expectedResult, res)
|
|
||||||
assert.Equal(t, expectedSavedAlias, string(accAlias))
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -49,9 +49,8 @@ func (eu *EventsUpdater) updateToken(ctx context.Context, identity identity.Iden
|
|||||||
|
|
||||||
// set default token to given symbol.
|
// set default token to given symbol.
|
||||||
func (eu *EventsUpdater) updateDefaultToken(ctx context.Context, identity identity.Identity, userStore *store.UserDataStore, activeSym string) error {
|
func (eu *EventsUpdater) updateDefaultToken(ctx context.Context, identity identity.Identity, userStore *store.UserDataStore, activeSym string) error {
|
||||||
pfxDb := toPrefixDb(userStore, identity.SessionId)
|
|
||||||
// TODO: the activeSym input should instead be newline separated list?
|
// TODO: the activeSym input should instead be newline separated list?
|
||||||
tokenData, err := store.GetVoucherData(ctx, pfxDb, activeSym)
|
tokenData, err := store.GetVoucherData(ctx, userStore, identity.SessionId, activeSym)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -128,6 +128,7 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService)
|
|||||||
ls.DbRs.AddLocalFunc("request_custom_alias", appHandlers.RequestCustomAlias)
|
ls.DbRs.AddLocalFunc("request_custom_alias", appHandlers.RequestCustomAlias)
|
||||||
ls.DbRs.AddLocalFunc("get_suggested_alias", appHandlers.GetSuggestedAlias)
|
ls.DbRs.AddLocalFunc("get_suggested_alias", appHandlers.GetSuggestedAlias)
|
||||||
ls.DbRs.AddLocalFunc("confirm_new_alias", appHandlers.ConfirmNewAlias)
|
ls.DbRs.AddLocalFunc("confirm_new_alias", appHandlers.ConfirmNewAlias)
|
||||||
|
ls.DbRs.AddLocalFunc("check_account_created", appHandlers.CheckAccountCreated)
|
||||||
|
|
||||||
ls.first = appHandlers.Init
|
ls.first = appHandlers.Init
|
||||||
|
|
||||||
|
|||||||
@@ -140,39 +140,6 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "menu_my_account_my_alias",
|
|
||||||
"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\n7:My Alias\n0:Back"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"input": "",
|
|
||||||
"expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"input": "7",
|
|
||||||
"expectedContent": "Current alias: Not Provided\nEdit my alias:\n0:Back"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"input": "foo",
|
|
||||||
"expectedContent": "Your full alias will be: \nPlease enter your PIN to confirm: \n\n0:Back"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"input": "1234",
|
|
||||||
"expectedContent": "Your alias has been updated successfully\n0:Back\n9:Quit"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"input": "0",
|
|
||||||
"expectedContent": "{balance}\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "menu_my_account_reset_others_pin_with_unregistered_number",
|
"name": "menu_my_account_reset_others_pin_with_unregistered_number",
|
||||||
"steps": [
|
"steps": [
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
LOAD reset_transaction_amount 0
|
LOAD reset_transaction_amount 0
|
||||||
LOAD max_amount 10
|
LOAD max_amount 40
|
||||||
RELOAD max_amount
|
RELOAD max_amount
|
||||||
MAP max_amount
|
MAP max_amount
|
||||||
MOUT back 0
|
MOUT back 0
|
||||||
|
|||||||
@@ -30,3 +30,7 @@ msgstr "Salio la Kikundi: 0.00"
|
|||||||
|
|
||||||
msgid "Symbol: %s\nBalance: %s"
|
msgid "Symbol: %s\nBalance: %s"
|
||||||
msgstr "Sarafu: %s\nSalio: %s"
|
msgstr "Sarafu: %s\nSalio: %s"
|
||||||
|
|
||||||
|
|
||||||
|
msgid "%s balance: %s\n"
|
||||||
|
msgstr "%s salio: %s\n"
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
Current alias: {{.get_current_profile_info}}
|
Current alias: {{.get_current_profile_info}}
|
||||||
Edit my alias:
|
Enter your preferred alias:
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
Lakabu ya sasa: {{.get_current_profile_info}}
|
Lakabu ya sasa: {{.get_current_profile_info}}
|
||||||
Badilisha Lakabu yangu:
|
Weka lakabu unalopendelea:
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
LOAD check_blocked_status 1
|
LOAD check_blocked_status 1
|
||||||
RELOAD check_blocked_status
|
RELOAD check_blocked_status
|
||||||
|
LOAD check_account_created 2
|
||||||
|
RELOAD check_account_created
|
||||||
CATCH blocked_account flag_account_blocked 1
|
CATCH blocked_account flag_account_blocked 1
|
||||||
CATCH select_language flag_language_set 0
|
CATCH select_language flag_language_set 0
|
||||||
CATCH terms flag_account_created 0
|
CATCH terms flag_account_created 0
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ const (
|
|||||||
DATA_INITIAL_LANGUAGE_CODE
|
DATA_INITIAL_LANGUAGE_CODE
|
||||||
//Fully qualified account alias string
|
//Fully qualified account alias string
|
||||||
DATA_ACCOUNT_ALIAS
|
DATA_ACCOUNT_ALIAS
|
||||||
|
//currently suggested alias by the api awaiting user's confirmation as accepted account alias
|
||||||
|
DATA_SUGGESTED_ALIAS
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -33,11 +33,14 @@ func (s *SubPrefixDb) toKey(k []byte) []byte {
|
|||||||
func (s *SubPrefixDb) Get(ctx context.Context, key []byte) ([]byte, error) {
|
func (s *SubPrefixDb) Get(ctx context.Context, key []byte) ([]byte, error) {
|
||||||
s.store.SetPrefix(db.DATATYPE_USERDATA)
|
s.store.SetPrefix(db.DATATYPE_USERDATA)
|
||||||
key = s.toKey(key)
|
key = s.toKey(key)
|
||||||
|
logg.InfoCtxf(ctx, "SubPrefixDb Get log", "key", string(key))
|
||||||
|
|
||||||
return s.store.Get(ctx, key)
|
return s.store.Get(ctx, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SubPrefixDb) Put(ctx context.Context, key []byte, val []byte) error {
|
func (s *SubPrefixDb) Put(ctx context.Context, key []byte, val []byte) error {
|
||||||
s.store.SetPrefix(db.DATATYPE_USERDATA)
|
s.store.SetPrefix(db.DATATYPE_USERDATA)
|
||||||
key = s.toKey(key)
|
key = s.toKey(key)
|
||||||
|
logg.InfoCtxf(ctx, "SubPrefixDb Put log", "key", string(key))
|
||||||
return s.store.Put(ctx, key, val)
|
return s.store.Put(ctx, key, val)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ func ScaleDownBalance(balance, decimals string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetVoucherData retrieves and matches voucher data
|
// GetVoucherData retrieves and matches voucher data
|
||||||
func GetVoucherData(ctx context.Context, db storedb.PrefixDb, input string) (*dataserviceapi.TokenHoldings, error) {
|
func GetVoucherData(ctx context.Context, store DataStore, sessionId string, input string) (*dataserviceapi.TokenHoldings, error) {
|
||||||
keys := []storedb.DataTyp{
|
keys := []storedb.DataTyp{
|
||||||
storedb.DATA_VOUCHER_SYMBOLS,
|
storedb.DATA_VOUCHER_SYMBOLS,
|
||||||
storedb.DATA_VOUCHER_BALANCES,
|
storedb.DATA_VOUCHER_BALANCES,
|
||||||
@@ -78,9 +78,9 @@ func GetVoucherData(ctx context.Context, db storedb.PrefixDb, input string) (*da
|
|||||||
data := make(map[storedb.DataTyp]string)
|
data := make(map[storedb.DataTyp]string)
|
||||||
|
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
value, err := db.Get(ctx, storedb.ToBytes(key))
|
value, err := store.ReadEntry(ctx, sessionId, key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get prefix key %x: %v", storedb.ToBytes(key), err)
|
return nil, fmt.Errorf("failed to get data key %x: %v", key, err)
|
||||||
}
|
}
|
||||||
data[key] = string(value)
|
data[key] = string(value)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"github.com/alecthomas/assert/v2"
|
"github.com/alecthomas/assert/v2"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
visedb "git.defalsify.org/vise.git/db"
|
|
||||||
memdb "git.defalsify.org/vise.git/db/mem"
|
memdb "git.defalsify.org/vise.git/db/mem"
|
||||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||||
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
|
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
|
||||||
@@ -77,16 +76,8 @@ func TestProcessVouchers(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetVoucherData(t *testing.T) {
|
func TestGetVoucherData(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx, store := InitializeTestDb(t)
|
||||||
|
sessionId := "session123"
|
||||||
db := memdb.NewMemDb()
|
|
||||||
err := db.Connect(ctx, "")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
prefix := storedb.ToBytes(visedb.DATATYPE_USERDATA)
|
|
||||||
spdb := storedb.NewSubPrefixDb(db, prefix)
|
|
||||||
|
|
||||||
// Test voucher data
|
// Test voucher data
|
||||||
mockData := map[storedb.DataTyp][]byte{
|
mockData := map[storedb.DataTyp][]byte{
|
||||||
@@ -98,13 +89,13 @@ func TestGetVoucherData(t *testing.T) {
|
|||||||
|
|
||||||
// Put the data
|
// Put the data
|
||||||
for key, value := range mockData {
|
for key, value := range mockData {
|
||||||
err = spdb.Put(ctx, []byte(storedb.ToBytes(key)), []byte(value))
|
err := store.WriteEntry(ctx, sessionId, key, []byte(value))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := GetVoucherData(ctx, spdb, "1")
|
result, err := GetVoucherData(ctx, store, sessionId, "1")
|
||||||
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "SRF", result.TokenSymbol)
|
assert.Equal(t, "SRF", result.TokenSymbol)
|
||||||
|
|||||||
Reference in New Issue
Block a user