From d1e9340ea9888acd1bbc7dbb0dc4f9e71b6c6004 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 21 Nov 2024 13:03:43 +0300 Subject: [PATCH 1/5] add voucher details --- models/voucher_data_result.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/models/voucher_data_result.go b/models/voucher_data_result.go index c9f0b74..9a10831 100644 --- a/models/voucher_data_result.go +++ b/models/voucher_data_result.go @@ -1,8 +1,10 @@ package models type VoucherDataResult struct { - TokenName string `json:"tokenName"` - TokenSymbol string `json:"tokenSymbol"` - TokenDecimals int `json:"tokenDecimals"` - SinkAddress string `json:"sinkAddress"` + TokenName string `json:"tokenName"` + TokenSymbol string `json:"tokenSymbol"` + TokenDecimals int `json:"tokenDecimals"` + SinkAddress string `json:"sinkAddress"` + TokenCommodity string `json:"tokenCommodity"` + TokenLocation string `json:"tokenLocation"` } From b8d938d3aa99ddecd999a2a68cf6b326b8f9b71f Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 21 Nov 2024 13:04:19 +0300 Subject: [PATCH 2/5] add voucher details --- internal/handlers/ussd/menuhandler.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index d8e6fa0..8f206e3 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -1626,10 +1626,9 @@ func (h *Handlers) GetVoucherDetails(ctx context.Context, sym string, input []by return res, nil } - tokenSymbol := voucherData.TokenSymbol - tokenName := voucherData.TokenName - - res.Content = fmt.Sprintf("%s %s", tokenSymbol, tokenName) + res.Content = fmt.Sprintf( + "name: %s\nsymbol: %s\ncommodity: %s\nlocation: %s", voucherData.TokenName, voucherData.TokenSymbol, voucherData.TokenCommodity, voucherData.TokenLocation, + ) return res, nil } From 1174500e3fce4d0621924d936370eac2d63ea9ad Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 21 Nov 2024 15:19:36 +0300 Subject: [PATCH 3/5] add test for voucher details --- internal/handlers/ussd/menuhandler_test.go | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/internal/handlers/ussd/menuhandler_test.go b/internal/handlers/ussd/menuhandler_test.go index 51693df..2559a54 100644 --- a/internal/handlers/ussd/menuhandler_test.go +++ b/internal/handlers/ussd/menuhandler_test.go @@ -2024,3 +2024,44 @@ func TestSetVoucher(t *testing.T) { assert.Equal(t, string(tempData.TokenSymbol), res.Content) } + +func TestGetVoucherDetails(t *testing.T) { + + ctx, store := InitializeTestStore(t) + fm, err := NewFlagManager(flagsPath) + if err != nil { + t.Logf(err.Error()) + } + mockAccountService := new(mocks.MockAccountService) + + sessionId := "session123" + ctx = context.WithValue(ctx, "SessionId", sessionId) + expectedResult := resource.Result{} + + tokA_AAddress := "0x0000000000000000000000000000000000000000" + + h := &Handlers{ + userdataStore: store, + flagManager: fm.parser, + accountService: mockAccountService, + } + err = store.WriteEntry(ctx, sessionId, common.DATA_ACTIVE_ADDRESS, []byte(tokA_AAddress)) + if err != nil { + t.Fatal(err) + } + tokenDetails := &models.VoucherDataResult{ + TokenName: "Token A", + TokenSymbol: "TOKA", + TokenLocation: "Kilifi,Kenya", + TokenCommodity: "Farming", + } + expectedResult.Content = fmt.Sprintf( + "name: %s\nsymbol: %s\ncommodity: %s\nlocation: %s", tokenDetails.TokenName, tokenDetails.TokenSymbol, tokenDetails.TokenCommodity, tokenDetails.TokenLocation, + ) + mockAccountService.On("VoucherData", string(tokA_AAddress)).Return(tokenDetails, nil) + + res, err := h.GetVoucherDetails(ctx, "SessionId", []byte("")) + assert.NoError(t, err) + assert.Equal(t, expectedResult, res) + +} From c2019267d1a77f55a4ae6f373416a5c80a93ef36 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Mon, 2 Dec 2024 13:26:46 +0300 Subject: [PATCH 4/5] capitalize the voucher descriptions --- internal/handlers/ussd/menuhandler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index 8f206e3..5bc95bc 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -1627,7 +1627,7 @@ func (h *Handlers) GetVoucherDetails(ctx context.Context, sym string, input []by } res.Content = fmt.Sprintf( - "name: %s\nsymbol: %s\ncommodity: %s\nlocation: %s", voucherData.TokenName, voucherData.TokenSymbol, voucherData.TokenCommodity, voucherData.TokenLocation, + "Name: %s\nSymbol: %s\nCommodity: %s\nLocation: %s", voucherData.TokenName, voucherData.TokenSymbol, voucherData.TokenCommodity, voucherData.TokenLocation, ) return res, nil From ef3a3d6717c98a17516281e04f271c8fb6e712fd Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Mon, 2 Dec 2024 13:30:33 +0300 Subject: [PATCH 5/5] updated the TestGetVoucherDetails --- internal/handlers/ussd/menuhandler_test.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/internal/handlers/ussd/menuhandler_test.go b/internal/handlers/ussd/menuhandler_test.go index 2559a54..6f1d57a 100644 --- a/internal/handlers/ussd/menuhandler_test.go +++ b/internal/handlers/ussd/menuhandler_test.go @@ -2026,7 +2026,6 @@ func TestSetVoucher(t *testing.T) { } func TestGetVoucherDetails(t *testing.T) { - ctx, store := InitializeTestStore(t) fm, err := NewFlagManager(flagsPath) if err != nil { @@ -2056,12 +2055,11 @@ func TestGetVoucherDetails(t *testing.T) { TokenCommodity: "Farming", } expectedResult.Content = fmt.Sprintf( - "name: %s\nsymbol: %s\ncommodity: %s\nlocation: %s", tokenDetails.TokenName, tokenDetails.TokenSymbol, tokenDetails.TokenCommodity, tokenDetails.TokenLocation, + "Name: %s\nSymbol: %s\nCommodity: %s\nLocation: %s", tokenDetails.TokenName, tokenDetails.TokenSymbol, tokenDetails.TokenCommodity, tokenDetails.TokenLocation, ) mockAccountService.On("VoucherData", string(tokA_AAddress)).Return(tokenDetails, nil) res, err := h.GetVoucherDetails(ctx, "SessionId", []byte("")) assert.NoError(t, err) assert.Equal(t, expectedResult, res) - }