Compare commits
15 Commits
fix-multip
...
address-sm
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2634790118 | ||
|
|
272a7ac05f
|
||
|
|
39c0d31995
|
||
|
|
18acb53ead
|
||
|
|
43d91f84f6
|
||
|
0791eb1f11
|
|||
|
|
8ebd2bbbfa
|
||
|
|
06c534cbb1
|
||
|
|
b8d53f82bb
|
||
|
|
71c01e00cd
|
||
|
|
419716a2b4
|
||
|
|
54b2088842
|
||
|
|
b2208359d6 | ||
|
|
0828b1eb10 | ||
|
|
c22f9edeca |
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
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)
|
logg.ErrorCtxf(ctx, "failed to read voucherData entires with", "key", storedb.DATA_VOUCHER_SYMBOLS, "error", err)
|
||||||
return res, 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))
|
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())
|
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
|
||||||
@@ -2570,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
|
||||||
}
|
}
|
||||||
@@ -2578,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
|
||||||
@@ -2589,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)
|
||||||
|
|||||||
@@ -2067,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))
|
||||||
@@ -2104,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)
|
||||||
}
|
}
|
||||||
@@ -2126,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)
|
||||||
}
|
}
|
||||||
@@ -2159,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
|
||||||
@@ -2180,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)
|
||||||
}
|
}
|
||||||
@@ -3476,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)
|
||||||
@@ -3496,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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
Current alias: {{.get_current_profile_info}}
|
Current alias: {{.get_current_profile_info}}
|
||||||
Enter your preferred alias::
|
Enter your preferred alias:
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
Lakabu ya sasa: {{.get_current_profile_info}}
|
Lakabu ya sasa: {{.get_current_profile_info}}
|
||||||
Weka lakabu unalopendelea::
|
Weka lakabu unalopendelea:
|
||||||
@@ -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 (
|
||||||
|
|||||||
@@ -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