Compare commits
No commits in common. "055c2db790281cfc9517f7aa878c32f2329b5670" and "fda68231eacefcdb20edab828f3903b1fc8642c3" have entirely different histories.
055c2db790
...
fda68231ea
@ -5,7 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.defalsify.org/vise.git/lang"
|
"git.defalsify.org/vise.git/lang"
|
||||||
@ -33,11 +32,6 @@ var (
|
|||||||
flagsPath = path.Join(baseDir, "services", "registration", "pp.csv")
|
flagsPath = path.Join(baseDir, "services", "registration", "pp.csv")
|
||||||
)
|
)
|
||||||
|
|
||||||
// mockReplaceSeparator function
|
|
||||||
var mockReplaceSeparator = func(input string) string {
|
|
||||||
return strings.ReplaceAll(input, ":", ": ")
|
|
||||||
}
|
|
||||||
|
|
||||||
// InitializeTestStore sets up and returns an in-memory database and store.
|
// InitializeTestStore sets up and returns an in-memory database and store.
|
||||||
func InitializeTestStore(t *testing.T) (context.Context, *common.UserDataStore) {
|
func InitializeTestStore(t *testing.T) (context.Context, *common.UserDataStore) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
@ -73,15 +67,12 @@ func TestNewHandlers(t *testing.T) {
|
|||||||
_, store := InitializeTestStore(t)
|
_, store := InitializeTestStore(t)
|
||||||
|
|
||||||
fm, err := NewFlagManager(flagsPath)
|
fm, err := NewFlagManager(flagsPath)
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
accountService := testservice.TestAccountService{}
|
accountService := testservice.TestAccountService{}
|
||||||
|
if err != nil {
|
||||||
// Test case for valid UserDataStore
|
t.Logf(err.Error())
|
||||||
|
}
|
||||||
t.Run("Valid UserDataStore", func(t *testing.T) {
|
t.Run("Valid UserDataStore", func(t *testing.T) {
|
||||||
handlers, err := NewHandlers(fm.parser, store, nil, &accountService, mockReplaceSeparator)
|
handlers, err := NewHandlers(fm.parser, store, nil, &accountService)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("expected no error, got %v", err)
|
t.Fatalf("expected no error, got %v", err)
|
||||||
}
|
}
|
||||||
@ -91,30 +82,19 @@ func TestNewHandlers(t *testing.T) {
|
|||||||
if handlers.userdataStore == nil {
|
if handlers.userdataStore == nil {
|
||||||
t.Fatal("expected userdataStore to be set in handlers")
|
t.Fatal("expected userdataStore to be set in handlers")
|
||||||
}
|
}
|
||||||
if handlers.ReplaceSeparator == nil {
|
|
||||||
t.Fatal("expected ReplaceSeparator to be set in handlers")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test ReplaceSeparator functionality
|
|
||||||
input := "1:Menu item"
|
|
||||||
expectedOutput := "1: Menu item"
|
|
||||||
if handlers.ReplaceSeparator(input) != expectedOutput {
|
|
||||||
t.Fatalf("ReplaceSeparator function did not return expected output: got %v, want %v", handlers.ReplaceSeparator(input), expectedOutput)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Test case for nil UserDataStore
|
// Test case for nil userdataStore
|
||||||
t.Run("Nil UserDataStore", func(t *testing.T) {
|
t.Run("Nil UserDataStore", func(t *testing.T) {
|
||||||
handlers, err := NewHandlers(fm.parser, nil, nil, &accountService, mockReplaceSeparator)
|
handlers, err := NewHandlers(fm.parser, nil, nil, &accountService)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected an error, got none")
|
t.Fatal("expected an error, got none")
|
||||||
}
|
}
|
||||||
if handlers != nil {
|
if handlers != nil {
|
||||||
t.Fatal("expected handlers to be nil")
|
t.Fatal("expected handlers to be nil")
|
||||||
}
|
}
|
||||||
expectedError := "cannot create handler with nil userdata store"
|
if err.Error() != "cannot create handler with nil userdata store" {
|
||||||
if err.Error() != expectedError {
|
t.Fatalf("expected specific error, got %v", err)
|
||||||
t.Fatalf("expected error '%s', got '%v'", expectedError, err)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -2002,31 +1982,30 @@ func TestCheckVouchers(t *testing.T) {
|
|||||||
|
|
||||||
func TestGetVoucherList(t *testing.T) {
|
func TestGetVoucherList(t *testing.T) {
|
||||||
sessionId := "session123"
|
sessionId := "session123"
|
||||||
|
menuSeparator := ":"
|
||||||
|
|
||||||
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
||||||
|
ctx = context.WithValue(ctx, "MenuSeparator", menuSeparator)
|
||||||
|
|
||||||
|
|
||||||
spdb := InitializeTestSubPrefixDb(t, ctx)
|
spdb := InitializeTestSubPrefixDb(t, ctx)
|
||||||
|
|
||||||
// Initialize Handlers
|
|
||||||
h := &Handlers{
|
h := &Handlers{
|
||||||
prefixDb: spdb,
|
prefixDb: spdb,
|
||||||
ReplaceSeparator: mockReplaceSeparator,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mockSyms := []byte("1:SRF\n2:MILO")
|
expectedSym := []byte("1:SRF\n2:MILO")
|
||||||
|
|
||||||
// Put voucher sym data from the store
|
// Put voucher sym data from the store
|
||||||
err := spdb.Put(ctx, common.ToBytes(common.DATA_VOUCHER_SYMBOLS), mockSyms)
|
err := spdb.Put(ctx, common.ToBytes(common.DATA_VOUCHER_SYMBOLS), expectedSym)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedSyms := []byte("1: SRF\n2: MILO")
|
|
||||||
|
|
||||||
res, err := h.GetVoucherList(ctx, "", []byte(""))
|
res, err := h.GetVoucherList(ctx, "", []byte(""))
|
||||||
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, res.Content, string(expectedSyms))
|
assert.Equal(t, res.Content, string(expectedSym))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestViewVoucher(t *testing.T) {
|
func TestViewVoucher(t *testing.T) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user