Compare commits

...

15 Commits

Author SHA1 Message Date
carlos
2634790118 Merge pull request 'use a different key for the suggested aliases' (#47) from fix-double-alias-request into master
Some checks failed
release / docker (push) Has been cancelled
Reviewed-on: #47
2025-03-28 09:35:10 +01:00
Carlosokumu
272a7ac05f chore: remove extra colon 2025-03-28 11:32:24 +03:00
Carlosokumu
39c0d31995 remove verbose logs 2025-03-28 11:26:32 +03:00
Carlosokumu
18acb53ead add alias logs
Some checks failed
release / docker (push) Has been cancelled
2025-03-28 11:08:50 +03:00
Carlosokumu
43d91f84f6 use a different key for the suggested aliases 2025-03-28 10:49:31 +03:00
0791eb1f11 ci/cd: build with log warn only
Some checks failed
release / docker (push) Has been cancelled
2025-03-25 09:52:37 +03:00
alfred-mk
8ebd2bbbfa remove alias updates from TestUpdateAllProfileItems
Some checks failed
release / docker (push) Has been cancelled
2025-03-24 20:06:07 +03:00
alfred-mk
06c534cbb1 remove the subprefix db from TestViewVoucher 2025-03-24 20:03:20 +03:00
alfred-mk
b8d53f82bb remove the subprefix db from TestGetVoucherList 2025-03-24 20:01:44 +03:00
alfred-mk
71c01e00cd remove commented out code 2025-03-24 19:58:43 +03:00
alfred-mk
419716a2b4 remove the subprefix db from TestCheckVouchers 2025-03-24 19:57:08 +03:00
alfred-mk
54b2088842 Pass correct arguments in the TestGetVoucherData 2025-03-24 19:53:02 +03:00
alfred-mk
b2208359d6 Add missing param to the GetVoucherData 2025-03-24 19:46:58 +03:00
alfred-mk
0828b1eb10 Increase the limit for the max_amount output 2025-03-24 19:46:58 +03:00
carlos
c22f9edeca Merge pull request 'fix-multiple-alias-requests' (#38) from fix-multiple-alias-requests into master
Some checks failed
release / docker (push) Has been cancelled
Reviewed-on: #38
2025-03-24 15:47:26 +01:00
9 changed files with 23 additions and 60 deletions

View File

@@ -21,7 +21,7 @@ RUN make VISE_PATH=/build/go-vise -B
WORKDIR /build/sarafu-vise
RUN echo "Building on $BUILDPLATFORM, building for $TARGETPLATFORM"
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

View File

@@ -2110,12 +2110,6 @@ func (h *MenuHandlers) CheckVouchers(ctx context.Context, sym string, input []by
}
}
// for key, value := range dataMap {
// if err := h.prefixDb.Put(ctx, []byte(storedb.ToBytes(key)), []byte(value)); err != nil {
// return res, nil
// }
// }
return res, nil
}
@@ -2136,11 +2130,6 @@ func (h *MenuHandlers) GetVoucherList(ctx context.Context, sym string, input []b
logg.ErrorCtxf(ctx, "failed to read voucherData entires with", "key", storedb.DATA_VOUCHER_SYMBOLS, "error", err)
return res, err
}
// voucherData, err := h.prefixDb.Get(ctx, storedb.ToBytes(storedb.DATA_VOUCHER_SYMBOLS))
// if err != nil {
// logg.ErrorCtxf(ctx, "Failed to read the voucherData from prefixDb", "error", err)
// return res, err
// }
formattedData := h.ReplaceSeparatorFunc(string(voucherData))
@@ -2539,9 +2528,10 @@ func (h *MenuHandlers) RequestCustomAlias(ctx context.Context, sym string, input
return res, fmt.Errorf("Failed to retrieve alias: %s", err.Error())
}
alias := aliasResult.Alias
logg.InfoCtxf(ctx, "Suggested alias ", "alias", 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 {
logg.ErrorCtxf(ctx, "failed to write account alias", "key", storedb.DATA_TEMPORARY_VALUE, "value", alias, "error", err)
return res, err
@@ -2570,7 +2560,7 @@ func (h *MenuHandlers) GetSuggestedAlias(ctx context.Context, sym string, input
if !ok {
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 {
return res, nil
}
@@ -2578,7 +2568,7 @@ func (h *MenuHandlers) GetSuggestedAlias(ctx context.Context, sym string, input
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) {
var res resource.Result
store := h.userdataStore
@@ -2589,10 +2579,11 @@ func (h *MenuHandlers) ConfirmNewAlias(ctx context.Context, sym string, input []
if !ok {
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 {
return res, nil
}
logg.InfoCtxf(ctx, "Confirming new alias", "alias", string(newAlias))
err = store.WriteEntry(ctx, sessionId, storedb.DATA_ACCOUNT_ALIAS, []byte(string(newAlias)))
if err != nil {
logg.ErrorCtxf(ctx, "failed to clear DATA_ACCOUNT_ALIAS_VALUE entry with", "key", storedb.DATA_ACCOUNT_ALIAS, "value", "empty", "error", err)

View File

@@ -2067,12 +2067,10 @@ func TestCheckVouchers(t *testing.T) {
ctx, store := InitializeTestStore(t)
ctx = context.WithValue(ctx, "SessionId", sessionId)
spdb := InitializeTestSubPrefixDb(t, ctx)
h := &MenuHandlers{
userdataStore: store,
accountService: mockAccountService,
prefixDb: spdb,
}
err := store.WriteEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY, []byte(publicKey))
@@ -2104,7 +2102,7 @@ func TestCheckVouchers(t *testing.T) {
assert.NoError(t, err)
// 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 {
t.Fatal(err)
}
@@ -2126,20 +2124,19 @@ func TestCheckVouchers(t *testing.T) {
func TestGetVoucherList(t *testing.T) {
sessionId := "session123"
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
spdb := InitializeTestSubPrefixDb(t, ctx)
ctx, store := InitializeTestStore(t)
ctx = context.WithValue(ctx, "SessionId", sessionId)
// Initialize MenuHandlers
h := &MenuHandlers{
prefixDb: spdb,
userdataStore: store,
ReplaceSeparatorFunc: mockReplaceSeparator,
}
mockSyms := []byte("1:SRF\n2:MILO")
// 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 {
t.Fatal(err)
}
@@ -2159,15 +2156,11 @@ func TestViewVoucher(t *testing.T) {
}
ctx, store := InitializeTestStore(t)
sessionId := "session123"
ctx = context.WithValue(ctx, "SessionId", sessionId)
spdb := InitializeTestSubPrefixDb(t, ctx)
h := &MenuHandlers{
userdataStore: store,
flagManager: fm,
prefixDb: spdb,
}
// Define mock voucher data
@@ -2180,7 +2173,7 @@ func TestViewVoucher(t *testing.T) {
// Put the data
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 {
t.Fatal(err)
}
@@ -3476,15 +3469,6 @@ func TestUpdateAllProfileItems(t *testing.T) {
err = store.WriteEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY, []byte(publicKey))
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
res, err := h.UpdateAllProfileItems(ctx, "symbol", nil)
assert.NoError(t, err)
@@ -3496,10 +3480,6 @@ func TestUpdateAllProfileItems(t *testing.T) {
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)
}

View File

@@ -49,9 +49,8 @@ func (eu *EventsUpdater) updateToken(ctx context.Context, identity identity.Iden
// set default token to given symbol.
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?
tokenData, err := store.GetVoucherData(ctx, pfxDb, activeSym)
tokenData, err := store.GetVoucherData(ctx, userStore, identity.SessionId, activeSym)
if err != nil {
return err
}

View File

@@ -1,5 +1,5 @@
LOAD reset_transaction_amount 0
LOAD max_amount 10
LOAD max_amount 40
RELOAD max_amount
MAP max_amount
MOUT back 0

View File

@@ -1,2 +1,2 @@
Current alias: {{.get_current_profile_info}}
Enter your preferred alias::
Enter your preferred alias:

View File

@@ -1,2 +1,2 @@
Lakabu ya sasa: {{.get_current_profile_info}}
Weka lakabu unalopendelea::
Weka lakabu unalopendelea:

View File

@@ -63,6 +63,8 @@ const (
DATA_INITIAL_LANGUAGE_CODE
//Fully qualified account alias string
DATA_ACCOUNT_ALIAS
//currently suggested alias by the api awaiting user's confirmation as accepted account alias
DATA_SUGGESTED_ALIAS
)
const (

View File

@@ -8,7 +8,6 @@ import (
"github.com/alecthomas/assert/v2"
"github.com/stretchr/testify/require"
visedb "git.defalsify.org/vise.git/db"
memdb "git.defalsify.org/vise.git/db/mem"
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
@@ -77,16 +76,8 @@ func TestProcessVouchers(t *testing.T) {
}
func TestGetVoucherData(t *testing.T) {
ctx := context.Background()
db := memdb.NewMemDb()
err := db.Connect(ctx, "")
if err != nil {
t.Fatal(err)
}
prefix := storedb.ToBytes(visedb.DATATYPE_USERDATA)
spdb := storedb.NewSubPrefixDb(db, prefix)
ctx, store := InitializeTestDb(t)
sessionId := "session123"
// Test voucher data
mockData := map[storedb.DataTyp][]byte{
@@ -98,13 +89,13 @@ func TestGetVoucherData(t *testing.T) {
// Put the data
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 {
t.Fatal(err)
}
}
result, err := GetVoucherData(ctx, spdb, "1")
result, err := GetVoucherData(ctx, store, sessionId, "1")
assert.NoError(t, err)
assert.Equal(t, "SRF", result.TokenSymbol)