Compare commits
No commits in common. "8751c4f5bdc5fe14d4985907830a28ae2a154ab6" and "992dd0bd54322c8cf00c9c994404d059894b9316" have entirely different histories.
8751c4f5bd
...
992dd0bd54
@ -2,62 +2,25 @@ package driver
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Step struct {
|
type StepTest 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 Group struct {
|
type GroupTest 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)
|
||||||
@ -68,12 +31,24 @@ func LoadTestGroups(filePath string) (DataGroup, error) {
|
|||||||
return sessionsData, err
|
return sessionsData, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateTestCases(group DataGroup) []TestCase {
|
func CreateTestCases(group DataGroup) []struct {
|
||||||
var tests []TestCase
|
Name string
|
||||||
|
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, TestCase{
|
tests = append(tests, struct {
|
||||||
|
Name string
|
||||||
|
Input string
|
||||||
|
ExpectedContent string
|
||||||
|
}{
|
||||||
Name: group.Name,
|
Name: group.Name,
|
||||||
Input: step.Input,
|
Input: step.Input,
|
||||||
ExpectedContent: step.ExpectedContent,
|
ExpectedContent: step.ExpectedContent,
|
55
driver/testdata.go
Normal file
55
driver/testdata.go
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
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
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package testutil
|
package engine
|
||||||
|
|
||||||
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 testutil
|
package engine
|
||||||
|
|
||||||
const OnlineTestEnabled = false
|
const OnlineTestEnabled = false
|
@ -1,5 +1,5 @@
|
|||||||
// +build online
|
// +build online
|
||||||
|
|
||||||
package testutil
|
package engine
|
||||||
|
|
||||||
const OnlineTestEnabled = true
|
const OnlineTestEnabled = true
|
@ -94,6 +94,7 @@ 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,16 +238,56 @@ func (h *Handlers) SaveTemporaryPin(ctx context.Context, sym string, input []byt
|
|||||||
|
|
||||||
accountPIN := string(input)
|
accountPIN := string(input)
|
||||||
|
|
||||||
// Validate that the PIN is a 4-digit number
|
if accountPIN != "0" { // for the 0:Back case
|
||||||
if !isValidPIN(accountPIN) {
|
// Validate that the PIN is a 4-digit number
|
||||||
res.FlagSet = append(res.FlagSet, flag_incorrect_pin)
|
if !isValidPIN(accountPIN) {
|
||||||
|
res.FlagSet = append(res.FlagSet, flag_incorrect_pin)
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
store := h.userdataStore
|
||||||
|
err = store.WriteEntry(ctx, sessionId, utils.DATA_TEMPORARY_PIN, []byte(accountPIN))
|
||||||
|
if err != nil {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
store := h.userdataStore
|
|
||||||
err = store.WriteEntry(ctx, sessionId, utils.DATA_TEMPORARY_PIN, []byte(accountPIN))
|
return res, nil
|
||||||
if err != nil {
|
}
|
||||||
return res, err
|
|
||||||
|
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
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ MOUT help 4
|
|||||||
MOUT quit 9
|
MOUT quit 9
|
||||||
HALT
|
HALT
|
||||||
INCMP send 1
|
INCMP send 1
|
||||||
INCMP quit 2
|
INCMP my_vouchers 2
|
||||||
INCMP my_account 3
|
INCMP my_account 3
|
||||||
INCMP help 4
|
INCMP help 4
|
||||||
INCMP quit 9
|
INCMP quit 9
|
||||||
|
2
services/registration/select_voucher
Normal file
2
services/registration/select_voucher
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Select number or symbol from your vouchers:
|
||||||
|
{{.get_vouchers}}
|
11
services/registration/select_voucher.vis
Normal file
11
services/registration/select_voucher.vis
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
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"
|
||||||
"git.grassecon.net/urdt/ussd/internal/testutil"
|
enginetest "git.grassecon.net/urdt/ussd/engine"
|
||||||
"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 := testutil.TestEngine(sessionID)
|
en, fn := enginetest.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 := testutil.TestEngine(edgeCaseSessionID)
|
en, fn := enginetest.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 := testutil.TestEngine(sessionID)
|
en, fn := enginetest.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 := testutil.TestEngine(sessionID)
|
en, fn := enginetest.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 := testutil.TestEngine(sessionID)
|
en, fn := enginetest.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 := testutil.TestEngine(sessionID)
|
en, fn := enginetest.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 := testutil.TestEngine(sessionID)
|
en, fn := enginetest.TestEngine(sessionID)
|
||||||
defer fn()
|
defer fn()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
sessions := testData
|
sessions := testData
|
||||||
@ -286,8 +286,10 @@ func TestMyAccount_Check_Community_Balance(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func TestMyAccount_MyAddress(t *testing.T) {
|
func TestMyAccount_MyAddress(t *testing.T) {
|
||||||
en, fn := testutil.TestEngine(sessionID)
|
en, fn := enginetest.TestEngine(sessionID)
|
||||||
defer fn()
|
defer fn()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
sessions := testData
|
sessions := testData
|
||||||
@ -327,7 +329,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 := testutil.TestEngine(sessionID)
|
en, fn := enginetest.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