forked from urdt/ussd
add mock account service
This commit is contained in:
parent
8313ca3509
commit
35acf75f6b
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user