Compare commits
9 Commits
113f1a5b34
...
eaac771722
| Author | SHA1 | Date | |
|---|---|---|---|
| eaac771722 | |||
| f3a5178de7 | |||
| 549d09890b | |||
| 4a9ef6b5f2 | |||
| 961d8d1a5c | |||
| a904cdbf44 | |||
| 3af943f77c | |||
| 14455f65cb | |||
| 0c08654df3 |
@ -4,7 +4,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
|
||||||
|
|
||||||
"git.grassecon.net/urdt/ussd/config"
|
"git.grassecon.net/urdt/ussd/config"
|
||||||
"git.grassecon.net/urdt/ussd/internal/models"
|
"git.grassecon.net/urdt/ussd/internal/models"
|
||||||
@ -19,9 +18,6 @@ type AccountServiceInterface interface {
|
|||||||
type AccountService struct {
|
type AccountService struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type TestAccountService struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
// CheckAccountStatus retrieves the status of an account transaction based on the provided tracking ID.
|
// CheckAccountStatus retrieves the status of an account transaction based on the provided tracking ID.
|
||||||
//
|
//
|
||||||
// Parameters:
|
// Parameters:
|
||||||
@ -96,58 +92,3 @@ func (as *AccountService) CreateAccount() (*models.AccountResponse, error) {
|
|||||||
}
|
}
|
||||||
return &accountResp, nil
|
return &accountResp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tas *TestAccountService) 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 (tas *TestAccountService) CheckBalance(publicKey string) (*models.BalanceResponse, 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, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tas *TestAccountService) CheckAccountStatus(trackingId string) (*models.TrackStatusResponse, error) {
|
|
||||||
trackResponse := &models.TrackStatusResponse{
|
|
||||||
Ok: true,
|
|
||||||
Result: struct {
|
|
||||||
Transaction struct {
|
|
||||||
CreatedAt time.Time "json:\"createdAt\""
|
|
||||||
Status string "json:\"status\""
|
|
||||||
TransferValue json.Number "json:\"transferValue\""
|
|
||||||
TxHash string "json:\"txHash\""
|
|
||||||
TxType string "json:\"txType\""
|
|
||||||
}
|
|
||||||
}{
|
|
||||||
Transaction: models.Transaction{
|
|
||||||
CreatedAt: time.Now(),
|
|
||||||
Status: "SUCCESS",
|
|
||||||
TransferValue: json.Number("0.5"),
|
|
||||||
TxHash: "0x123abc456def",
|
|
||||||
TxType: "transfer",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
return trackResponse, nil
|
|
||||||
}
|
|
||||||
|
|||||||
@ -15,9 +15,10 @@ import (
|
|||||||
"git.defalsify.org/vise.git/persist"
|
"git.defalsify.org/vise.git/persist"
|
||||||
"git.defalsify.org/vise.git/resource"
|
"git.defalsify.org/vise.git/resource"
|
||||||
"git.defalsify.org/vise.git/state"
|
"git.defalsify.org/vise.git/state"
|
||||||
"git.grassecon.net/urdt/ussd/internal/handlers/server"
|
|
||||||
"git.grassecon.net/urdt/ussd/internal/mocks"
|
"git.grassecon.net/urdt/ussd/internal/mocks"
|
||||||
"git.grassecon.net/urdt/ussd/internal/models"
|
"git.grassecon.net/urdt/ussd/internal/models"
|
||||||
|
"git.grassecon.net/urdt/ussd/internal/testutil/testservice"
|
||||||
|
|
||||||
"git.grassecon.net/urdt/ussd/internal/utils"
|
"git.grassecon.net/urdt/ussd/internal/utils"
|
||||||
"github.com/alecthomas/assert/v2"
|
"github.com/alecthomas/assert/v2"
|
||||||
testdataloader "github.com/peteole/testdata-loader"
|
testdataloader "github.com/peteole/testdata-loader"
|
||||||
@ -31,7 +32,7 @@ var (
|
|||||||
|
|
||||||
func TestNewHandlers(t *testing.T) {
|
func TestNewHandlers(t *testing.T) {
|
||||||
fm, err := NewFlagManager(flagsPath)
|
fm, err := NewFlagManager(flagsPath)
|
||||||
accountService := server.TestAccountService{}
|
accountService := testservice.TestAccountService{}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Logf(err.Error())
|
t.Logf(err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,8 @@ import (
|
|||||||
"git.grassecon.net/urdt/ussd/internal/handlers"
|
"git.grassecon.net/urdt/ussd/internal/handlers"
|
||||||
"git.grassecon.net/urdt/ussd/internal/handlers/server"
|
"git.grassecon.net/urdt/ussd/internal/handlers/server"
|
||||||
"git.grassecon.net/urdt/ussd/internal/storage"
|
"git.grassecon.net/urdt/ussd/internal/storage"
|
||||||
|
"git.grassecon.net/urdt/ussd/internal/testutil/testservice"
|
||||||
|
"git.grassecon.net/urdt/ussd/internal/testutil/testtag"
|
||||||
testdataloader "github.com/peteole/testdata-loader"
|
testdataloader "github.com/peteole/testdata-loader"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -79,12 +81,12 @@ func TestEngine(sessionId string) (engine.Engine, func(), chan bool) {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if AccountService == nil {
|
if testtag.AccountService == nil {
|
||||||
AccountService = &server.AccountService{}
|
testtag.AccountService = &server.AccountService{}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch AccountService.(type) {
|
switch testtag.AccountService.(type) {
|
||||||
case *server.TestAccountService:
|
case *testservice.TestAccountService:
|
||||||
go func() {
|
go func() {
|
||||||
eventChannel <- false
|
eventChannel <- false
|
||||||
}()
|
}()
|
||||||
@ -97,7 +99,7 @@ func TestEngine(sessionId string) (engine.Engine, func(), chan bool) {
|
|||||||
panic("Unknown account service type")
|
panic("Unknown account service type")
|
||||||
}
|
}
|
||||||
|
|
||||||
hl, err := lhs.GetHandler(AccountService)
|
hl, err := lhs.GetHandler(testtag.AccountService)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|||||||
@ -1,11 +0,0 @@
|
|||||||
// +build !online
|
|
||||||
|
|
||||||
package testutil
|
|
||||||
|
|
||||||
import (
|
|
||||||
"git.grassecon.net/urdt/ussd/internal/handlers/server"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
AccountService server.AccountServiceInterface = &server.TestAccountService{}
|
|
||||||
)
|
|
||||||
65
internal/testutil/testservice/TestAccountService.go
Normal file
65
internal/testutil/testservice/TestAccountService.go
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
package testservice
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.grassecon.net/urdt/ussd/internal/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TestAccountService struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tas *TestAccountService) 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 (tas *TestAccountService) CheckBalance(publicKey string) (*models.BalanceResponse, 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, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tas *TestAccountService) CheckAccountStatus(trackingId string) (*models.TrackStatusResponse, error) {
|
||||||
|
trackResponse := &models.TrackStatusResponse{
|
||||||
|
Ok: true,
|
||||||
|
Result: struct {
|
||||||
|
Transaction struct {
|
||||||
|
CreatedAt time.Time "json:\"createdAt\""
|
||||||
|
Status string "json:\"status\""
|
||||||
|
TransferValue json.Number "json:\"transferValue\""
|
||||||
|
TxHash string "json:\"txHash\""
|
||||||
|
TxType string "json:\"txType\""
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
Transaction: models.Transaction{
|
||||||
|
CreatedAt: time.Now(),
|
||||||
|
Status: "SUCCESS",
|
||||||
|
TransferValue: json.Number("0.5"),
|
||||||
|
TxHash: "0x123abc456def",
|
||||||
|
TxType: "transfer",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return trackResponse, nil
|
||||||
|
}
|
||||||
12
internal/testutil/testtag/offlinetest.go
Normal file
12
internal/testutil/testtag/offlinetest.go
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// +build !online
|
||||||
|
|
||||||
|
package testtag
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.grassecon.net/urdt/ussd/internal/handlers/server"
|
||||||
|
accountservice "git.grassecon.net/urdt/ussd/internal/testutil/testservice"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
AccountService server.AccountServiceInterface = &accountservice.TestAccountService{}
|
||||||
|
)
|
||||||
@ -1,6 +1,6 @@
|
|||||||
// +build online
|
// +build online
|
||||||
|
|
||||||
package testutil
|
package testtag
|
||||||
|
|
||||||
import "git.grassecon.net/urdt/ussd/internal/handlers/server"
|
import "git.grassecon.net/urdt/ussd/internal/handlers/server"
|
||||||
|
|
||||||
@ -9,8 +9,8 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.grassecon.net/urdt/ussd/driver"
|
|
||||||
"git.grassecon.net/urdt/ussd/internal/testutil"
|
"git.grassecon.net/urdt/ussd/internal/testutil"
|
||||||
|
"git.grassecon.net/urdt/ussd/internal/testutil/driver"
|
||||||
"github.com/gofrs/uuid"
|
"github.com/gofrs/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user