From 589a94216b93dd8592645953c89c6af3a80ab549 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Thu, 5 Dec 2024 17:02:26 +0300 Subject: [PATCH] Use the DATATYPE_USERDATA as the prefix for the NewSubPrefixDb func --- common/vouchers_test.go | 5 ++++- internal/handlers/ussd/menuhandler.go | 6 ++++-- internal/handlers/ussd/menuhandler_test.go | 4 +++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/common/vouchers_test.go b/common/vouchers_test.go index e6f449d..560fb5b 100644 --- a/common/vouchers_test.go +++ b/common/vouchers_test.go @@ -8,6 +8,7 @@ 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" "git.grassecon.net/urdt/ussd/internal/storage" dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api" @@ -83,7 +84,9 @@ func TestGetVoucherData(t *testing.T) { if err != nil { t.Fatal(err) } - spdb := storage.NewSubPrefixDb(db, []byte("vouchers")) + + prefix := IntToBytes(visedb.DATATYPE_USERDATA) + spdb := storage.NewSubPrefixDb(db, prefix) // Test voucher data mockData := map[DataTyp][]byte{ diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index 14cfc50..812c897 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -85,8 +85,10 @@ func NewHandlers(appFlags *asm.FlagParser, userdataStore db.Db, adminstore *util userDb := &common.UserDataStore{ Db: userdataStore, } - // Instantiate the SubPrefixDb with "vouchers" prefix - prefixDb := storage.NewSubPrefixDb(userdataStore, []byte("vouchers")) + + // Instantiate the SubPrefixDb with "DATATYPE_USERDATA" prefix + prefix := common.IntToBytes(db.DATATYPE_USERDATA) + prefixDb := storage.NewSubPrefixDb(userdataStore, prefix) h := &Handlers{ userdataStore: userDb, diff --git a/internal/handlers/ussd/menuhandler_test.go b/internal/handlers/ussd/menuhandler_test.go index 9fabe97..1aa7c28 100644 --- a/internal/handlers/ussd/menuhandler_test.go +++ b/internal/handlers/ussd/menuhandler_test.go @@ -22,6 +22,7 @@ import ( testdataloader "github.com/peteole/testdata-loader" "github.com/stretchr/testify/require" + visedb "git.defalsify.org/vise.git/db" memdb "git.defalsify.org/vise.git/db/mem" dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api" ) @@ -56,7 +57,8 @@ func InitializeTestSubPrefixDb(t *testing.T, ctx context.Context) *storage.SubPr if err != nil { t.Fatal(err) } - spdb := storage.NewSubPrefixDb(db, []byte("vouchers")) + prefix := common.IntToBytes(visedb.DATATYPE_USERDATA) + spdb := storage.NewSubPrefixDb(db, prefix) return spdb }