Compare commits
6 Commits
992dd0bd54
...
8751c4f5bd
Author | SHA1 | Date | |
---|---|---|---|
8751c4f5bd | |||
fc935535f9 | |||
ef4846b11f | |||
827b99e48d | |||
e09c1e1e98 | |||
87c6029199 |
@ -1,55 +0,0 @@
|
|||||||
package driver
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Step struct {
|
|
||||||
Input string `json:"input"`
|
|
||||||
ExpectedContent string `json:"expectedContent"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Group struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Steps []Step `json:"steps"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Session struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Groups []Group `json:"groups"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func ReadData() []Session {
|
|
||||||
data, err := os.ReadFile("test_setup.json")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to read file: %v", err)
|
|
||||||
}
|
|
||||||
// Unmarshal JSON data
|
|
||||||
var sessions []Session
|
|
||||||
err = json.Unmarshal(data, &sessions)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to unmarshal JSON: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return sessions
|
|
||||||
}
|
|
||||||
|
|
||||||
func FilterGroupsByName(groups []Group, name string) []Group {
|
|
||||||
var filteredGroups []Group
|
|
||||||
for _, group := range groups {
|
|
||||||
if group.Name == name {
|
|
||||||
filteredGroups = append(filteredGroups, group)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return filteredGroups
|
|
||||||
}
|
|
||||||
|
|
||||||
func Map[T any, U any](input []T, fn func(T) U) []U {
|
|
||||||
result := make([]U, len(input))
|
|
||||||
for i, v := range input {
|
|
||||||
result[i] = fn(v)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
@ -2,25 +2,62 @@ package driver
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
type StepTest struct {
|
type Step struct {
|
||||||
Input string `json:"input"`
|
Input string `json:"input"`
|
||||||
ExpectedContent string `json:"expectedContent"`
|
ExpectedContent string `json:"expectedContent"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Group represents a group of steps.
|
// Group represents a group of steps
|
||||||
type GroupTest struct {
|
type Group struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Steps []Step `json:"steps"`
|
Steps []Step `json:"steps"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TestCase struct {
|
||||||
|
Name string
|
||||||
|
Input string
|
||||||
|
ExpectedContent string
|
||||||
|
}
|
||||||
|
|
||||||
// DataGroup represents the overall structure of the JSON.
|
// DataGroup represents the overall structure of the JSON.
|
||||||
type DataGroup struct {
|
type DataGroup struct {
|
||||||
Groups []Group `json:"groups"`
|
Groups []Group `json:"groups"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Session struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Groups []Group `json:"groups"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func ReadData() []Session {
|
||||||
|
data, err := os.ReadFile("test_setup.json")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to read file: %v", err)
|
||||||
|
}
|
||||||
|
// Unmarshal JSON data
|
||||||
|
var sessions []Session
|
||||||
|
err = json.Unmarshal(data, &sessions)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to unmarshal JSON: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return sessions
|
||||||
|
}
|
||||||
|
|
||||||
|
func FilterGroupsByName(groups []Group, name string) []Group {
|
||||||
|
var filteredGroups []Group
|
||||||
|
for _, group := range groups {
|
||||||
|
if group.Name == name {
|
||||||
|
filteredGroups = append(filteredGroups, group)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filteredGroups
|
||||||
|
}
|
||||||
|
|
||||||
func LoadTestGroups(filePath string) (DataGroup, error) {
|
func LoadTestGroups(filePath string) (DataGroup, error) {
|
||||||
var sessionsData DataGroup
|
var sessionsData DataGroup
|
||||||
data, err := os.ReadFile(filePath)
|
data, err := os.ReadFile(filePath)
|
||||||
@ -31,24 +68,12 @@ func LoadTestGroups(filePath string) (DataGroup, error) {
|
|||||||
return sessionsData, err
|
return sessionsData, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateTestCases(group DataGroup) []struct {
|
func CreateTestCases(group DataGroup) []TestCase {
|
||||||
Name string
|
var tests []TestCase
|
||||||
Input string
|
|
||||||
ExpectedContent string
|
|
||||||
} {
|
|
||||||
var tests []struct {
|
|
||||||
Name string
|
|
||||||
Input string
|
|
||||||
ExpectedContent string
|
|
||||||
}
|
|
||||||
for _, group := range group.Groups {
|
for _, group := range group.Groups {
|
||||||
for _, step := range group.Steps {
|
for _, step := range group.Steps {
|
||||||
// Create a test case for each group
|
// Create a test case for each group
|
||||||
tests = append(tests, struct {
|
tests = append(tests, TestCase{
|
||||||
Name string
|
|
||||||
Input string
|
|
||||||
ExpectedContent string
|
|
||||||
}{
|
|
||||||
Name: group.Name,
|
Name: group.Name,
|
||||||
Input: step.Input,
|
Input: step.Input,
|
||||||
ExpectedContent: step.ExpectedContent,
|
ExpectedContent: step.ExpectedContent,
|
@ -94,7 +94,6 @@ func (ls *LocalHandlerService) GetHandler(accountService server.AccountServiceIn
|
|||||||
ls.DbRs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin)
|
ls.DbRs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin)
|
||||||
ls.DbRs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange)
|
ls.DbRs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange)
|
||||||
ls.DbRs.AddLocalFunc("quit_with_help", ussdHandlers.QuitWithHelp)
|
ls.DbRs.AddLocalFunc("quit_with_help", ussdHandlers.QuitWithHelp)
|
||||||
ls.DbRs.AddLocalFunc("get_vouchers", ussdHandlers.GetVoucherList)
|
|
||||||
|
|
||||||
return ussdHandlers, nil
|
return ussdHandlers, nil
|
||||||
}
|
}
|
||||||
|
@ -238,7 +238,6 @@ func (h *Handlers) SaveTemporaryPin(ctx context.Context, sym string, input []byt
|
|||||||
|
|
||||||
accountPIN := string(input)
|
accountPIN := string(input)
|
||||||
|
|
||||||
if accountPIN != "0" { // for the 0:Back case
|
|
||||||
// Validate that the PIN is a 4-digit number
|
// Validate that the PIN is a 4-digit number
|
||||||
if !isValidPIN(accountPIN) {
|
if !isValidPIN(accountPIN) {
|
||||||
res.FlagSet = append(res.FlagSet, flag_incorrect_pin)
|
res.FlagSet = append(res.FlagSet, flag_incorrect_pin)
|
||||||
@ -252,45 +251,6 @@ func (h *Handlers) SaveTemporaryPin(ctx context.Context, sym string, input []byt
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *Handlers) GetVoucherList(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
|
||||||
var res resource.Result
|
|
||||||
vouchers := []string{
|
|
||||||
"SRF",
|
|
||||||
"CRF",
|
|
||||||
"VCF",
|
|
||||||
"VSAPA",
|
|
||||||
"FSTMP",
|
|
||||||
"FSAW",
|
|
||||||
"PTAQ",
|
|
||||||
"VCRXT",
|
|
||||||
"VSGAQ",
|
|
||||||
"QPWIQQ",
|
|
||||||
"FSTMP",
|
|
||||||
"FSAW",
|
|
||||||
"PTAQ",
|
|
||||||
"VCRXT",
|
|
||||||
"VSGAQ",
|
|
||||||
"QPWIQQ",
|
|
||||||
"FSTMP",
|
|
||||||
"FSAW",
|
|
||||||
"PTAQ",
|
|
||||||
"VCRXT",
|
|
||||||
"VSGAQ",
|
|
||||||
"QPWIQQ",
|
|
||||||
}
|
|
||||||
|
|
||||||
var numberedVouchers []string
|
|
||||||
for i, voucher := range vouchers {
|
|
||||||
numberedVouchers = append(numberedVouchers, fmt.Sprintf("%d:%s", i+1, voucher))
|
|
||||||
}
|
|
||||||
res.Content = strings.Join(numberedVouchers, "\n")
|
|
||||||
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *Handlers) ConfirmPinChange(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (h *Handlers) ConfirmPinChange(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
var res resource.Result
|
var res resource.Result
|
||||||
sessionId, ok := ctx.Value("SessionId").(string)
|
sessionId, ok := ctx.Value("SessionId").(string)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package engine
|
package testutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -104,6 +104,6 @@ func TestEngine(sessionId string) (engine.Engine, func()) {
|
|||||||
logg.Infof("testengine storage closed")
|
logg.Infof("testengine storage closed")
|
||||||
}
|
}
|
||||||
|
|
||||||
//en = en.WithDebug(nil)
|
en = en.WithDebug(nil)
|
||||||
return en, cleanFn
|
return en, cleanFn
|
||||||
}
|
}
|
@ -1,5 +1,5 @@
|
|||||||
// +build !online
|
// +build !online
|
||||||
|
|
||||||
package engine
|
package testutil
|
||||||
|
|
||||||
const OnlineTestEnabled = false
|
const OnlineTestEnabled = false
|
@ -1,5 +1,5 @@
|
|||||||
// +build online
|
// +build online
|
||||||
|
|
||||||
package engine
|
package testutil
|
||||||
|
|
||||||
const OnlineTestEnabled = true
|
const OnlineTestEnabled = true
|
@ -8,7 +8,7 @@ MOUT help 4
|
|||||||
MOUT quit 9
|
MOUT quit 9
|
||||||
HALT
|
HALT
|
||||||
INCMP send 1
|
INCMP send 1
|
||||||
INCMP my_vouchers 2
|
INCMP quit 2
|
||||||
INCMP my_account 3
|
INCMP my_account 3
|
||||||
INCMP help 4
|
INCMP help 4
|
||||||
INCMP quit 9
|
INCMP quit 9
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
Select number or symbol from your vouchers:
|
|
||||||
{{.get_vouchers}}
|
|
@ -1,11 +0,0 @@
|
|||||||
LOAD get_vouchers 0
|
|
||||||
MAP get_vouchers
|
|
||||||
MOUT back 0
|
|
||||||
MOUT quit 9
|
|
||||||
MNEXT next 11
|
|
||||||
MPREV prev 22
|
|
||||||
HALT
|
|
||||||
INCMP _ 0
|
|
||||||
INCMP quit 9
|
|
||||||
INCMP > 11
|
|
||||||
INCMP < 22
|
|
@ -11,7 +11,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.grassecon.net/urdt/ussd/driver"
|
"git.grassecon.net/urdt/ussd/driver"
|
||||||
enginetest "git.grassecon.net/urdt/ussd/engine"
|
"git.grassecon.net/urdt/ussd/internal/testutil"
|
||||||
"github.com/gofrs/uuid"
|
"github.com/gofrs/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ func TestMain(m *testing.M) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAccountCreationSuccessful(t *testing.T) {
|
func TestAccountCreationSuccessful(t *testing.T) {
|
||||||
en, fn := enginetest.TestEngine(sessionID)
|
en, fn := testutil.TestEngine(sessionID)
|
||||||
defer fn()
|
defer fn()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
sessions := testData
|
sessions := testData
|
||||||
@ -94,7 +94,7 @@ func TestAccountRegistrationRejectTerms(t *testing.T) {
|
|||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
edgeCaseSessionID := v.String()
|
edgeCaseSessionID := v.String()
|
||||||
en, fn := enginetest.TestEngine(edgeCaseSessionID)
|
en, fn := testutil.TestEngine(edgeCaseSessionID)
|
||||||
defer fn()
|
defer fn()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
sessions := testData
|
sessions := testData
|
||||||
@ -125,7 +125,7 @@ func TestAccountRegistrationRejectTerms(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSendWithInvalidInputs(t *testing.T) {
|
func TestSendWithInvalidInputs(t *testing.T) {
|
||||||
en, fn := enginetest.TestEngine(sessionID)
|
en, fn := testutil.TestEngine(sessionID)
|
||||||
defer fn()
|
defer fn()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
sessions := testData
|
sessions := testData
|
||||||
@ -163,7 +163,7 @@ func TestSendWithInvalidInputs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMyAccount_Check_My_Balance(t *testing.T) {
|
func TestMyAccount_Check_My_Balance(t *testing.T) {
|
||||||
en, fn := enginetest.TestEngine(sessionID)
|
en, fn := testutil.TestEngine(sessionID)
|
||||||
defer fn()
|
defer fn()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
sessions := testData
|
sessions := testData
|
||||||
@ -194,7 +194,7 @@ func TestMyAccount_Check_My_Balance(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMainMenuHelp(t *testing.T) {
|
func TestMainMenuHelp(t *testing.T) {
|
||||||
en, fn := enginetest.TestEngine(sessionID)
|
en, fn := testutil.TestEngine(sessionID)
|
||||||
defer fn()
|
defer fn()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
sessions := testData
|
sessions := testData
|
||||||
@ -225,7 +225,7 @@ func TestMainMenuHelp(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMainMenuQuit(t *testing.T) {
|
func TestMainMenuQuit(t *testing.T) {
|
||||||
en, fn := enginetest.TestEngine(sessionID)
|
en, fn := testutil.TestEngine(sessionID)
|
||||||
defer fn()
|
defer fn()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
sessions := testData
|
sessions := testData
|
||||||
@ -256,7 +256,7 @@ func TestMainMenuQuit(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMyAccount_Check_Community_Balance(t *testing.T) {
|
func TestMyAccount_Check_Community_Balance(t *testing.T) {
|
||||||
en, fn := enginetest.TestEngine(sessionID)
|
en, fn := testutil.TestEngine(sessionID)
|
||||||
defer fn()
|
defer fn()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
sessions := testData
|
sessions := testData
|
||||||
@ -286,10 +286,8 @@ func TestMyAccount_Check_Community_Balance(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func TestMyAccount_MyAddress(t *testing.T) {
|
func TestMyAccount_MyAddress(t *testing.T) {
|
||||||
en, fn := enginetest.TestEngine(sessionID)
|
en, fn := testutil.TestEngine(sessionID)
|
||||||
defer fn()
|
defer fn()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
sessions := testData
|
sessions := testData
|
||||||
@ -329,7 +327,7 @@ func TestGroups(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to load test groups: %v", err)
|
log.Fatalf("Failed to load test groups: %v", err)
|
||||||
}
|
}
|
||||||
en, fn := enginetest.TestEngine(sessionID)
|
en, fn := testutil.TestEngine(sessionID)
|
||||||
defer fn()
|
defer fn()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
// Create test cases from loaded groups
|
// Create test cases from loaded groups
|
||||||
|
Loading…
Reference in New Issue
Block a user