add mock account service

This commit is contained in:
Carlosokumu 2024-10-07 23:31:00 +03:00
parent 8313ca3509
commit 35acf75f6b
Signed by: carlos
GPG Key ID: 7BD6BC8160A5C953
4 changed files with 49 additions and 6 deletions

View File

@ -11,6 +11,7 @@ import (
"git.defalsify.org/vise.git/logging"
"git.defalsify.org/vise.git/resource"
"git.grassecon.net/urdt/ussd/internal/handlers"
"git.grassecon.net/urdt/ussd/internal/handlers/server"
"git.grassecon.net/urdt/ussd/internal/storage"
)
@ -84,8 +85,8 @@ func main() {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
hl, err := lhs.GetHandler()
accountService := server.AccountService{}
hl, err := lhs.GetHandler(&accountService)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)

View File

@ -7,6 +7,7 @@ import (
"git.defalsify.org/vise.git/persist"
"git.defalsify.org/vise.git/resource"
"git.grassecon.net/urdt/ussd/internal/handlers/ussd"
"git.grassecon.net/urdt/ussd/internal/handlers/server"
)
type HandlerService interface {
@ -52,8 +53,8 @@ func (ls *LocalHandlerService) SetDataStore(db *db.Db) {
ls.UserdataStore = db
}
func (ls *LocalHandlerService) GetHandler() (*ussd.Handlers, error) {
ussdHandlers, err := ussd.NewHandlers(ls.Parser, *ls.UserdataStore)
func (ls *LocalHandlerService) GetHandler(accountService server.AccountServiceInterface) (*ussd.Handlers, error) {
ussdHandlers, err := ussd.NewHandlers(ls.Parser, *ls.UserdataStore,accountService)
if err != nil {
return nil, err
}

View File

@ -18,6 +18,10 @@ type AccountServiceInterface interface {
type AccountService struct {
}
type MockAccountService struct {
}
// CheckAccountStatus retrieves the status of an account transaction based on the provided tracking ID.
@ -110,3 +114,40 @@ func (as *AccountService) CreateAccount() (*models.AccountResponse, error) {
return &accountResp, nil
}
func (mas *MockAccountService) CreateAccount() (*models.AccountResponse, error) {
return &models.AccountResponse{
Ok: true,
Result: struct {
CustodialId json.Number `json:"custodialId"`
PublicKey string `json:"publicKey"`
TrackingId string `json:"trackingId"`
}{
CustodialId: json.Number("182"),
PublicKey: "0x48ADca309b5085852207FAaf2816eD72B52F527C",
TrackingId: "28ebe84d-b925-472c-87ae-bbdfa1fb97be",
},
}, nil
}
func (mas *MockAccountService) CheckBalance(publicKey string) (string, error) {
balanceResponse := &models.BalanceResponse{
Ok: true,
Result: struct {
Balance string `json:"balance"`
Nonce json.Number `json:"nonce"`
}{
Balance: "0.003 CELO",
Nonce: json.Number("0"),
},
}
return balanceResponse.Result.Balance, nil
}
func (mas *MockAccountService) CheckAccountStatus(trackingId string) (string, error) {
return "SUCCESS", nil
}

View File

@ -61,7 +61,7 @@ type Handlers struct {
accountService server.AccountServiceInterface
}
func NewHandlers(appFlags *asm.FlagParser, userdataStore db.Db) (*Handlers, error) {
func NewHandlers(appFlags *asm.FlagParser, userdataStore db.Db, accountService server.AccountServiceInterface) (*Handlers, error) {
if userdataStore == nil {
return nil, fmt.Errorf("cannot create handler with nil userdata store")
}
@ -71,7 +71,7 @@ func NewHandlers(appFlags *asm.FlagParser, userdataStore db.Db) (*Handlers, erro
h := &Handlers{
userdataStore: userDb,
flagManager: appFlags,
accountService: &server.AccountService{},
accountService: accountService,
}
return h, nil
}