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 } 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) + +} 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"` }