Merge branch 'master' into api-structs
This commit is contained in:
commit
d19c20a9d7
@ -641,6 +641,10 @@ func (h *Handlers) CheckBalance(ctx context.Context, sym string, input []byte) (
|
|||||||
return res, fmt.Errorf("missing session")
|
return res, fmt.Errorf("missing session")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
code := codeFromCtx(ctx)
|
||||||
|
l := gotext.NewLocale(translationDir, code)
|
||||||
|
l.AddDomain("default")
|
||||||
|
|
||||||
store := h.userdataStore
|
store := h.userdataStore
|
||||||
publicKey, err := store.ReadEntry(ctx, sessionId, utils.DATA_PUBLIC_KEY)
|
publicKey, err := store.ReadEntry(ctx, sessionId, utils.DATA_PUBLIC_KEY)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -657,7 +661,8 @@ func (h *Handlers) CheckBalance(ctx context.Context, sym string, input []byte) (
|
|||||||
}
|
}
|
||||||
res.FlagReset = append(res.FlagReset, flag_api_error)
|
res.FlagReset = append(res.FlagReset, flag_api_error)
|
||||||
balance := balanceResponse.Result.Balance
|
balance := balanceResponse.Result.Balance
|
||||||
res.Content = balance
|
|
||||||
|
res.Content = l.Get("Balance: %s\n", balance)
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
@ -897,7 +902,7 @@ func (h *Handlers) GetRecipient(ctx context.Context, sym string, input []byte) (
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSender retrieves the public key from the Gdbm Db
|
// GetSender returns the sessionId (phoneNumber)
|
||||||
func (h *Handlers) GetSender(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (h *Handlers) GetSender(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
var res resource.Result
|
var res resource.Result
|
||||||
|
|
||||||
@ -906,10 +911,7 @@ func (h *Handlers) GetSender(ctx context.Context, sym string, input []byte) (res
|
|||||||
return res, fmt.Errorf("missing session")
|
return res, fmt.Errorf("missing session")
|
||||||
}
|
}
|
||||||
|
|
||||||
store := h.userdataStore
|
res.Content = string(sessionId)
|
||||||
publicKey, _ := store.ReadEntry(ctx, sessionId, utils.DATA_PUBLIC_KEY)
|
|
||||||
|
|
||||||
res.Content = string(publicKey)
|
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
@ -946,13 +948,12 @@ func (h *Handlers) InitiateTransaction(ctx context.Context, sym string, input []
|
|||||||
// TODO
|
// TODO
|
||||||
// Use the amount, recipient and sender to call the API and initialize the transaction
|
// Use the amount, recipient and sender to call the API and initialize the transaction
|
||||||
store := h.userdataStore
|
store := h.userdataStore
|
||||||
publicKey, _ := store.ReadEntry(ctx, sessionId, utils.DATA_PUBLIC_KEY)
|
|
||||||
|
|
||||||
amount, _ := store.ReadEntry(ctx, sessionId, utils.DATA_AMOUNT)
|
amount, _ := store.ReadEntry(ctx, sessionId, utils.DATA_AMOUNT)
|
||||||
|
|
||||||
recipient, _ := store.ReadEntry(ctx, sessionId, utils.DATA_RECIPIENT)
|
recipient, _ := store.ReadEntry(ctx, sessionId, utils.DATA_RECIPIENT)
|
||||||
|
|
||||||
res.Content = l.Get("Your request has been sent. %s will receive %s from %s.", string(recipient), string(amount), string(publicKey))
|
res.Content = l.Get("Your request has been sent. %s will receive %s from %s.", string(recipient), string(amount), string(sessionId))
|
||||||
|
|
||||||
account_authorized_flag, err := h.flagManager.GetFlag("flag_account_authorized")
|
account_authorized_flag, err := h.flagManager.GetFlag("flag_account_authorized")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -516,12 +516,8 @@ func TestGetSender(t *testing.T) {
|
|||||||
mockStore := new(mocks.MockUserDataStore)
|
mockStore := new(mocks.MockUserDataStore)
|
||||||
|
|
||||||
// Define test data
|
// Define test data
|
||||||
sessionId := "session123"
|
sessionId := "254712345678"
|
||||||
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
||||||
publicKey := "0xcasgatweksalw1018221"
|
|
||||||
|
|
||||||
// Set up the expected behavior of the mock
|
|
||||||
mockStore.On("ReadEntry", ctx, sessionId, utils.DATA_PUBLIC_KEY).Return([]byte(publicKey), nil)
|
|
||||||
|
|
||||||
// Create the Handlers instance with the mock store
|
// Create the Handlers instance with the mock store
|
||||||
h := &Handlers{
|
h := &Handlers{
|
||||||
@ -529,11 +525,10 @@ func TestGetSender(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Call the method
|
// Call the method
|
||||||
res, _ := h.GetSender(ctx, "max_amount", []byte("check_balance"))
|
res, _ := h.GetSender(ctx, "get_sender", []byte(""))
|
||||||
|
|
||||||
//Assert that the public key from readentry operation is what was set as the result content.
|
|
||||||
assert.Equal(t, publicKey, res.Content)
|
|
||||||
|
|
||||||
|
//Assert that the sessionId is what was set as the result content.
|
||||||
|
assert.Equal(t, sessionId, res.Content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetAmount(t *testing.T) {
|
func TestGetAmount(t *testing.T) {
|
||||||
@ -1297,7 +1292,7 @@ func TestResetInvalidAmount(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestInitiateTransaction(t *testing.T) {
|
func TestInitiateTransaction(t *testing.T) {
|
||||||
sessionId := "session123"
|
sessionId := "254712345678"
|
||||||
|
|
||||||
fm, err := NewFlagManager(flagsPath)
|
fm, err := NewFlagManager(flagsPath)
|
||||||
|
|
||||||
@ -1320,30 +1315,26 @@ func TestInitiateTransaction(t *testing.T) {
|
|||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
input []byte
|
input []byte
|
||||||
PublicKey []byte
|
|
||||||
Recipient []byte
|
Recipient []byte
|
||||||
Amount []byte
|
Amount []byte
|
||||||
status string
|
status string
|
||||||
expectedResult resource.Result
|
expectedResult resource.Result
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Test amount reset",
|
name: "Test initiate transaction",
|
||||||
PublicKey: []byte("0x1241527192"),
|
Amount: []byte("0.002 CELO"),
|
||||||
Amount: []byte("0.002CELO"),
|
|
||||||
Recipient: []byte("0x12415ass27192"),
|
Recipient: []byte("0x12415ass27192"),
|
||||||
expectedResult: resource.Result{
|
expectedResult: resource.Result{
|
||||||
FlagReset: []uint32{account_authorized_flag},
|
FlagReset: []uint32{account_authorized_flag},
|
||||||
Content: "Your request has been sent. 0x12415ass27192 will receive 0.002CELO from 0x1241527192.",
|
Content: "Your request has been sent. 0x12415ass27192 will receive 0.002 CELO from 254712345678.",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
// Define expected interactions with the mock
|
// Define expected interactions with the mock
|
||||||
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_PUBLIC_KEY).Return(tt.PublicKey, nil)
|
|
||||||
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_AMOUNT).Return(tt.Amount, nil)
|
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_AMOUNT).Return(tt.Amount, nil)
|
||||||
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_RECIPIENT).Return(tt.Recipient, nil)
|
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_RECIPIENT).Return(tt.Recipient, nil)
|
||||||
//mockDataStore.On("WriteEntry", ctx, sessionId, utils.DATA_AMOUNT, []byte("")).Return(nil)
|
|
||||||
|
|
||||||
// Call the method under test
|
// Call the method under test
|
||||||
res, _ := h.InitiateTransaction(ctx, "transaction_reset_amount", tt.input)
|
res, _ := h.InitiateTransaction(ctx, "transaction_reset_amount", tt.input)
|
||||||
@ -1356,10 +1347,8 @@ func TestInitiateTransaction(t *testing.T) {
|
|||||||
|
|
||||||
// Assert that expectations were met
|
// Assert that expectations were met
|
||||||
mockDataStore.AssertExpectations(t)
|
mockDataStore.AssertExpectations(t)
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestQuit(t *testing.T) {
|
func TestQuit(t *testing.T) {
|
||||||
@ -1638,7 +1627,6 @@ func TestValidateRecipient(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCheckBalance(t *testing.T) {
|
func TestCheckBalance(t *testing.T) {
|
||||||
|
|
||||||
sessionId := "session123"
|
sessionId := "session123"
|
||||||
publicKey := "0X13242618721"
|
publicKey := "0X13242618721"
|
||||||
fm, _ := NewFlagManager(flagsPath)
|
fm, _ := NewFlagManager(flagsPath)
|
||||||
@ -1680,7 +1668,7 @@ func TestCheckBalance(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedResult: resource.Result{
|
expectedResult: resource.Result{
|
||||||
Content: "0.003 CELO",
|
Content: "Balance: 0.003 CELO\n",
|
||||||
FlagReset: []uint32{flag_api_error},
|
FlagReset: []uint32{flag_api_error},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1713,10 +1701,8 @@ func TestCheckBalance(t *testing.T) {
|
|||||||
|
|
||||||
//Assert that the result set to content is what was expected
|
//Assert that the result set to content is what was expected
|
||||||
assert.Equal(t, res, tt.expectedResult, "Result should contain flags set according to user input")
|
assert.Equal(t, res, tt.expectedResult, "Result should contain flags set according to user input")
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetProfile(t *testing.T) {
|
func TestGetProfile(t *testing.T) {
|
||||||
|
@ -7,6 +7,8 @@ msgstr "Ombi lako limetumwa. %s atapokea %s kutoka kwa %s."
|
|||||||
msgid "Thank you for using Sarafu. Goodbye!"
|
msgid "Thank you for using Sarafu. Goodbye!"
|
||||||
msgstr "Asante kwa kutumia huduma ya Sarafu. Kwaheri!"
|
msgstr "Asante kwa kutumia huduma ya Sarafu. Kwaheri!"
|
||||||
|
|
||||||
|
|
||||||
msgid "For more help,please call: 0757628885"
|
msgid "For more help,please call: 0757628885"
|
||||||
msgstr "Kwa usaidizi zaidi,piga: 0757628885"
|
msgstr "Kwa usaidizi zaidi,piga: 0757628885"
|
||||||
|
|
||||||
|
msgid "Balance: %s\n"
|
||||||
|
msgstr "Salio: %s\n"
|
||||||
|
@ -1 +1 @@
|
|||||||
Balance: {{.check_balance}}
|
{{.check_balance}}
|
@ -1 +1 @@
|
|||||||
Salio: {{.check_balance}}
|
{{.check_balance}}
|
Loading…
Reference in New Issue
Block a user