Compare commits

..

19 Commits

Author SHA1 Message Date
Carlosokumu
fabea46c49 Merge branch 'master' into test-coverage-bump 2025-03-19 09:06:53 +03:00
Carlosokumu
4b1e3f09d0 add test cases for non-4 digit entries 2025-03-19 09:05:19 +03:00
374f79388c ci/cd: remove ssh binary from Docker builds
Some checks failed
release / docker (push) Has been cancelled
2025-03-18 17:48:55 +03:00
lash
30644d3535 Merge branch 'lash/more-edbug' 2025-03-15 03:12:05 +00:00
lash
e5e857e3cb Upgrade deps 2025-03-15 03:02:25 +00:00
Carlosokumu
5317ed3bd5 add test to confirm new alias 2025-03-12 10:31:10 +03:00
Carlosokumu
e0636593fb add test for getsuggested alias 2025-03-12 09:33:22 +03:00
Carlosokumu
47dbf176da add my alias traversal test 2025-03-12 09:21:45 +03:00
carlos
7885c7f8fa Merge branch 'master' into test-coverage-bump 2025-03-12 06:43:49 +01:00
Carlosokumu
1af826e87f dep: update sarafu-api dep
Some checks failed
release / docker (push) Has been cancelled
2025-03-10 12:41:16 +03:00
Carlosokumu
38ef3b623e dep: update sarafu-api dep
Some checks failed
release / docker (push) Has been cancelled
2025-03-10 11:53:47 +03:00
Carlosokumu
f7e7f7bd1c add for check back,add logs for the alias 2025-03-10 11:51:02 +03:00
Carlosokumu
bd0e7822ed dep: upgrade sarafu-api dep
Some checks failed
release / docker (push) Has been cancelled
2025-03-07 16:13:23 +03:00
Carlosokumu
4dba5f2ab5 dep: upgrade sarafu-api dep
Some checks failed
release / docker (push) Has been cancelled
2025-03-07 09:48:30 +03:00
144398e18b Merge pull request 'ens' (#32) from ens into master
Reviewed-on: #32
Reviewed-by: lash <accounts-grassrootseconomics@holbrook.no>
2025-03-07 06:00:17 +01:00
Carlosokumu
2b16f57aad test: save_gender add check for values in respective data keys when flag_allow update is set 2025-03-05 10:59:00 +03:00
Carlosokumu
4dbe69954c test: improve test coverage on save gender 2025-03-05 08:27:44 +03:00
Carlosokumu
f7b81ab629 test: test aliases ending with .eth ,correct typo on recipient 2025-03-05 07:43:08 +03:00
Carlosokumu
d00d06a421 test: update profile update tests 2025-03-04 22:24:07 +03:00
6 changed files with 542 additions and 137 deletions

View File

@@ -22,7 +22,6 @@ WORKDIR /build/sarafu-vise
RUN echo "Building on $BUILDPLATFORM, building for $TARGETPLATFORM"
RUN go mod download
RUN go build -tags logtrace,online -o sarafu-at -ldflags="-X main.build=${BUILD} -s -w" cmd/africastalking/main.go
RUN go build -tags logtrace,online -o sarafu-ssh -ldflags="-X main.build=${BUILD} -s -w" cmd/ssh/main.go
FROM debian:bookworm-slim
@@ -37,7 +36,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
WORKDIR /service
COPY --from=build /build/sarafu-vise/sarafu-at .
COPY --from=build /build/sarafu-vise/sarafu-ssh .
COPY --from=build /build/sarafu-vise/LICENSE .
COPY --from=build /build/sarafu-vise/README.md .
COPY --from=build /build/sarafu-vise/services ./services
@@ -45,6 +43,5 @@ COPY --from=build /build/sarafu-vise/.env.example .
RUN mv .env.example .env
EXPOSE 7123
EXPOSE 7122
CMD ["./sarafu-at"]

6
go.mod
View File

@@ -3,10 +3,10 @@ module git.grassecon.net/grassrootseconomics/sarafu-vise
go 1.23.4
require (
git.defalsify.org/vise.git v0.2.3-0.20250205173834-d1f6647211ac
git.defalsify.org/vise.git v0.3.1
git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d
git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250206112944-31eb30de0f69
git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.1.0.20250204132347-1eb0b1555244
git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250310093912-8145b4bd004b
git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.2
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250129070628-5a539172c694
github.com/alecthomas/assert/v2 v2.2.2
github.com/gofrs/uuid v4.4.0+incompatible

12
go.sum
View File

@@ -1,11 +1,11 @@
git.defalsify.org/vise.git v0.2.3-0.20250205173834-d1f6647211ac h1:f/E0ZTclVfMEnD/3Alrzzbg+dOm138zGydV42jT0JPw=
git.defalsify.org/vise.git v0.2.3-0.20250205173834-d1f6647211ac/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck=
git.defalsify.org/vise.git v0.3.1 h1:A6FhMcur09ft/JzUPGXR+KpA17fltfeBnasyvLMZmq4=
git.defalsify.org/vise.git v0.3.1/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck=
git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d h1:5mzLas+jxTUtusOKx4XvU+n2QvrV/mH17MnJRy46siQ=
git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d/go.mod h1:wgQJZGIS6QuNLHqDhcsvehsbn5PvgV7aziRebMnJi60=
git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250206112944-31eb30de0f69 h1:cbBpm9uNJak58MpFpNXJuvgCmz+A8kquXr9har4expg=
git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250206112944-31eb30de0f69/go.mod h1:gOn89ipaDcDvmQXRMQYKUqcw/sJcwVOPVt2eC6Geip8=
git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.1.0.20250204132347-1eb0b1555244 h1:BXotWSKg04U97sf/xeWJuUTSVgKk2aEK+5BtBrnafXQ=
git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.1.0.20250204132347-1eb0b1555244/go.mod h1:6B6ByxXOiRY0NR7K02Bf3fEu7z+2c/6q8PFVNjC5G8w=
git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250310093912-8145b4bd004b h1:xiTpaqWWoF5qcnarY/9ZkT6aVdnKwqztb2gzIahJn4w=
git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250310093912-8145b4bd004b/go.mod h1:gOn89ipaDcDvmQXRMQYKUqcw/sJcwVOPVt2eC6Geip8=
git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.2 h1:YFztSsexCUgFo6M0tbngRwYdgJd3LQV3RO/Jw09u3+k=
git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.2/go.mod h1:6B6ByxXOiRY0NR7K02Bf3fEu7z+2c/6q8PFVNjC5G8w=
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250129070628-5a539172c694 h1:DjJlBSz0S13acft5XZDWk7ZYnzElym0xLMYEVgyNJ+E=
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250129070628-5a539172c694/go.mod h1:DpibtYpnT3nG4Kn556hRAkdu4+CtiI/6MbnQHal51mQ=
github.com/alecthomas/assert/v2 v2.2.2 h1:Z/iVC0xZfWTaFNE6bA3z07T86hd45Xe2eLt6WVy2bbk=

View File

@@ -1619,6 +1619,7 @@ func (h *MenuHandlers) ValidateRecipient(ctx context.Context, sym string, input
//Perform a search for each search domain,break on first match
for _, domain := range config.SearchDomains() {
fqdn := fmt.Sprintf("%s.%s", recipient, domain)
logg.InfoCtxf(ctx, "Resolving with fqdn alias", "alias", fqdn)
AliasAddress, err = h.accountService.CheckAliasAddress(ctx, fqdn)
if err == nil {
AliasAddressResult = AliasAddress.Address
@@ -2459,6 +2460,10 @@ func (h *MenuHandlers) RequestCustomAlias(ctx context.Context, sym string, input
if !ok {
return res, fmt.Errorf("missing session")
}
if string(input) == "0" {
return res, nil
}
store := h.userdataStore
aliasHint, err := store.ReadEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE)
if err != nil {

View File

@@ -275,36 +275,80 @@ func TestSaveFirstname(t *testing.T) {
// Set the flag in the State
mockState := state.NewState(128)
mockState.SetFlag(flag_allow_update)
expectedResult := resource.Result{}
// Define test data
firstName := "John"
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(firstName)); err != nil {
t.Fatal(err)
}
expectedResult.FlagSet = []uint32{flag_firstname_set}
// Create the MenuHandlers instance with the mock store
h := &MenuHandlers{
userdataStore: store,
flagManager: fm,
st: mockState,
profile: &profile.Profile{Max: 6},
}
// Call the method
res, err := h.SaveFirstname(ctx, "save_firstname", []byte(firstName))
tests := []struct {
name string
setupfunc func()
saveItem string
expectedSavedItem string
expectedResult resource.Result
}{
{
name: "test when `flag_allow_update` flag is set",
saveItem: "John",
setupfunc: func() {
//setup the required flags
mockState.SetFlag(flag_allow_update)
},
expectedSavedItem: "John",
expectedResult: resource.Result{
FlagSet: []uint32{flag_firstname_set},
},
},
{
name: "test when `flag_allow_update flag` is not set but `flag_firstname_set` set ",
setupfunc: func() {
//setup the required flags
mockState.ResetFlag(flag_allow_update)
mockState.SetFlag(flag_firstname_set)
},
saveItem: "John",
expectedSavedItem: "John",
expectedResult: resource.Result{},
},
{
name: "test when both `flag_allow_update flag` `flag_firstname_set` are not set ",
setupfunc: func() {
//setup the required flags
mockState.ResetFlag(flag_allow_update)
mockState.ResetFlag(flag_firstname_set)
},
saveItem: "John",
expectedSavedItem: "John",
expectedResult: resource.Result{},
},
}
// Assert results
assert.NoError(t, err)
assert.Equal(t, expectedResult, res)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.setupfunc()
// Verify that the DATA_FIRST_NAME entry has been updated with the temporary value
storedFirstName, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_FIRST_NAME)
assert.Equal(t, firstName, string(storedFirstName))
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(tt.saveItem)); err != nil {
t.Fatal(err)
}
// Call the method
res, err := h.SaveFirstname(ctx, "save_firstname", []byte(tt.saveItem))
if err != nil {
t.Fatalf("Failed to save firstname with error %v", err)
}
// Assert results
assert.NoError(t, err)
assert.Equal(t, tt.expectedResult, res)
// Verify that the DATA_FIRST_NAME entry has been updated with the temporary value
storedFirstName, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_FIRST_NAME)
assert.Equal(t, tt.expectedSavedItem, string(storedFirstName))
})
}
}
func TestSaveFamilyname(t *testing.T) {
@@ -315,40 +359,84 @@ func TestSaveFamilyname(t *testing.T) {
fm, _ := NewFlagManager(flagsPath)
flag_allow_update, _ := fm.GetFlag("flag_allow_update")
flag_firstname_set, _ := fm.GetFlag("flag_familyname_set")
flag_familyname_set, _ := fm.GetFlag("flag_familyname_set")
// Set the flag in the State
mockState := state.NewState(128)
mockState.SetFlag(flag_allow_update)
expectedResult := resource.Result{}
expectedResult.FlagSet = []uint32{flag_firstname_set}
// Define test data
familyName := "Doeee"
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(familyName)); err != nil {
t.Fatal(err)
}
// Create the MenuHandlers instance with the mock store
h := &MenuHandlers{
userdataStore: store,
st: mockState,
flagManager: fm,
st: mockState,
profile: &profile.Profile{Max: 6},
}
// Call the method
res, err := h.SaveFamilyname(ctx, "save_familyname", []byte(familyName))
tests := []struct {
name string
setupfunc func()
saveItem string
expectedSavedItem string
expectedResult resource.Result
}{
{
name: "test when `flag_allow_update` flag is set",
saveItem: "Doe",
setupfunc: func() {
//setup the required flags
mockState.SetFlag(flag_allow_update)
},
expectedSavedItem: "Doe",
expectedResult: resource.Result{
FlagSet: []uint32{flag_familyname_set},
},
},
{
name: "test when `flag_allow_update flag` is not set but `flag_familyname_set` set ",
setupfunc: func() {
//setup the required flags
mockState.ResetFlag(flag_allow_update)
mockState.SetFlag(flag_familyname_set)
},
saveItem: "Doe",
expectedSavedItem: "Doe",
expectedResult: resource.Result{},
},
{
name: "test when both `flag_allow_update flag` `flag_familyname_set` are not set ",
setupfunc: func() {
//setup the required flags
mockState.ResetFlag(flag_allow_update)
mockState.ResetFlag(flag_familyname_set)
},
saveItem: "Doe",
expectedSavedItem: "Doe",
expectedResult: resource.Result{},
},
}
// Assert results
assert.NoError(t, err)
assert.Equal(t, expectedResult, res)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.setupfunc()
// Verify that the DATA_FAMILY_NAME entry has been updated with the temporary value
storedFamilyName, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_FAMILY_NAME)
assert.Equal(t, familyName, string(storedFamilyName))
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(tt.saveItem)); err != nil {
t.Fatal(err)
}
// Call the method
res, err := h.SaveFamilyname(ctx, "save_yob", []byte(tt.saveItem))
if err != nil {
t.Fatalf("Failed to save family name with error %v", err)
}
// Assert results
assert.NoError(t, err)
assert.Equal(t, tt.expectedResult, res)
// Verify that the DATA_FAMILY_NAME entry has been updated with the temporary value
storedFamilyname, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_FAMILY_NAME)
assert.Equal(t, tt.expectedSavedItem, string(storedFamilyname))
})
}
}
func TestSaveYoB(t *testing.T) {
@@ -365,37 +453,83 @@ func TestSaveYoB(t *testing.T) {
mockState := state.NewState(108)
mockState.SetFlag(flag_allow_update)
expectedResult := resource.Result{}
// Define test data
yob := "1980"
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(yob)); err != nil {
t.Fatal(err)
}
expectedResult.FlagSet = []uint32{flag_yob_set}
// Create the MenuHandlers instance with the mock store
h := &MenuHandlers{
userdataStore: store,
flagManager: fm,
st: mockState,
profile: &profile.Profile{Max: 6},
}
// Call the method
res, err := h.SaveYob(ctx, "save_yob", []byte(yob))
tests := []struct {
name string
setupfunc func()
saveItem string
expectedSavedItem string
expectedResult resource.Result
}{
{
name: "test when `flag_allow_update` flag is set",
saveItem: "1980",
setupfunc: func() {
//setup the required flags
mockState.SetFlag(flag_allow_update)
},
expectedSavedItem: "1980",
expectedResult: resource.Result{
FlagSet: []uint32{flag_yob_set},
},
},
{
name: "test when `flag_allow_update flag` is not set but `flag_yob_set` set ",
setupfunc: func() {
//setup the required flags
mockState.ResetFlag(flag_allow_update)
mockState.SetFlag(flag_yob_set)
},
saveItem: "1980",
expectedSavedItem: "1980",
expectedResult: resource.Result{},
},
{
name: "test when both `flag_allow_update flag` `flag_yob_set` are not set ",
setupfunc: func() {
//setup the required flags
mockState.ResetFlag(flag_allow_update)
mockState.ResetFlag(flag_yob_set)
},
saveItem: "1980",
expectedSavedItem: "1980",
expectedResult: resource.Result{},
},
}
// Assert results
assert.NoError(t, err)
assert.Equal(t, expectedResult, res)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.setupfunc()
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(tt.saveItem)); err != nil {
t.Fatal(err)
}
// Call the method
res, err := h.SaveYob(ctx, "save_yob", []byte(tt.saveItem))
// Verify that the DATA_YOB entry has been updated with the temporary value
storedYob, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_YOB)
assert.Equal(t, yob, string(storedYob))
if err != nil {
t.Fatalf("Failed to save location with error %v", err)
}
// Assert results
assert.NoError(t, err)
assert.Equal(t, tt.expectedResult, res)
// Verify that the DATA_YOB entry has been updated with the temporary value
storedYob, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_YOB)
assert.Equal(t, tt.expectedSavedItem, string(storedYob))
})
}
}
func TestSaveLocation(t *testing.T) {
sessionId := "session123"
ctx, store := InitializeTestStore(t)
ctx = context.WithValue(ctx, "SessionId", sessionId)
@@ -407,36 +541,80 @@ func TestSaveLocation(t *testing.T) {
// Set the flag in the State
mockState := state.NewState(108)
mockState.SetFlag(flag_allow_update)
expectedResult := resource.Result{}
// Define test data
location := "Kilifi"
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(location)); err != nil {
t.Fatal(err)
}
expectedResult.FlagSet = []uint32{flag_location_set}
// Create the MenuHandlers instance with the mock store
h := &MenuHandlers{
userdataStore: store,
flagManager: fm,
profile: &profile.Profile{Max: 6},
st: mockState,
}
// Call the method
res, err := h.SaveLocation(ctx, "save_location", []byte(location))
tests := []struct {
name string
setupfunc func()
saveItem string
expectedSavedItem string
expectedResult resource.Result
}{
{
name: "test when `flag_allow_update` flag is set",
saveItem: "Kilifi",
setupfunc: func() {
//setup the required flags
mockState.SetFlag(flag_allow_update)
},
expectedSavedItem: "Kilifi",
expectedResult: resource.Result{
FlagSet: []uint32{flag_location_set},
},
},
{
name: "test when `flag_allow_update flag` is not set but `flag_location_set` set ",
setupfunc: func() {
//setup the required flags
mockState.ResetFlag(flag_allow_update)
mockState.SetFlag(flag_location_set)
},
saveItem: "Kilifi",
expectedSavedItem: "Kilifi",
expectedResult: resource.Result{FlagSet: []uint32{flag_location_set}},
},
{
name: "test when both `flag_allow_update flag` `flag_location_set` are not set ",
setupfunc: func() {
//setup the required flags
mockState.ResetFlag(flag_allow_update)
mockState.ResetFlag(flag_location_set)
},
saveItem: "Kilifi",
expectedSavedItem: "Kilifi",
expectedResult: resource.Result{},
},
}
// Assert results
assert.NoError(t, err)
assert.Equal(t, expectedResult, res)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.setupfunc()
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(tt.saveItem)); err != nil {
t.Fatal(err)
}
// Call the method
res, err := h.SaveLocation(ctx, "save_location", []byte(tt.saveItem))
// Verify that the DATA_LOCATION entry has been updated with the temporary value
storedLocation, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_LOCATION)
assert.Equal(t, location, string(storedLocation))
if err != nil {
t.Fatalf("Failed to save location with error %v", err)
}
// Assert results
assert.NoError(t, err)
assert.Equal(t, tt.expectedResult, res)
// Verify that the DATA_LOCATION entry has been updated with the temporary value
storedLocation, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_LOCATION)
assert.Equal(t, tt.expectedSavedItem, string(storedLocation))
})
}
}
func TestSaveOfferings(t *testing.T) {
@@ -451,36 +629,76 @@ func TestSaveOfferings(t *testing.T) {
// Set the flag in the State
mockState := state.NewState(108)
mockState.SetFlag(flag_allow_update)
expectedResult := resource.Result{}
// Define test data
offerings := "Bananas"
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(offerings)); err != nil {
t.Fatal(err)
}
expectedResult.FlagSet = []uint32{flag_offerings_set}
// Create the MenuHandlers instance with the mock store
h := &MenuHandlers{
userdataStore: store,
flagManager: fm,
st: mockState,
profile: &profile.Profile{Max: 6},
}
// Call the method
res, err := h.SaveOfferings(ctx, "save_offerings", []byte(offerings))
tests := []struct {
name string
setupfunc func()
saveItem string
expectedSavedItem string
expectedResult resource.Result
}{
{
name: "test when `flag_allow_update` flag is set",
saveItem: "Bananas",
setupfunc: func() {
//setup the required flags
mockState.SetFlag(flag_allow_update)
},
expectedSavedItem: "Bananas",
expectedResult: resource.Result{
FlagSet: []uint32{flag_offerings_set},
},
},
{
name: "test when `flag_allow_update flag` is not set but `flag_offerings_set` set ",
setupfunc: func() {
//setup the required flags
mockState.ResetFlag(flag_allow_update)
mockState.SetFlag(flag_offerings_set)
},
saveItem: "Bananas",
expectedSavedItem: "Bananas",
expectedResult: resource.Result{},
},
{
name: "test when both `flag_allow_update flag` `flag_offerings_set` are not set ",
setupfunc: func() {
//setup the required flags
mockState.ResetFlag(flag_allow_update)
mockState.ResetFlag(flag_offerings_set)
},
saveItem: "Bananas",
expectedSavedItem: "Bananas",
expectedResult: resource.Result{},
},
}
// Assert results
assert.NoError(t, err)
assert.Equal(t, expectedResult, res)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.setupfunc()
// Verify that the DATA_OFFERINGS entry has been updated with the temporary value
storedOfferings, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_OFFERINGS)
assert.Equal(t, offerings, string(storedOfferings))
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(tt.saveItem)); err != nil {
t.Fatal(err)
}
res, err := h.SaveOfferings(ctx, "save_offerings", []byte(tt.saveItem))
// Assert results
assert.NoError(t, err)
assert.Equal(t, tt.expectedResult, res)
// Verify that the DATA_OFFERINGS entry has been updated with the temporary value
storedOfferings, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_OFFERINGS)
assert.Equal(t, tt.expectedSavedItem, string(storedOfferings))
})
}
}
func TestSaveGender(t *testing.T) {
@@ -495,63 +713,89 @@ func TestSaveGender(t *testing.T) {
// Set the flag in the State
mockState := state.NewState(108)
mockState.SetFlag(flag_allow_update)
// Define test cases
tests := []struct {
name string
setupfunc func()
input []byte
expectedGender string
expectedResult resource.Result
executingSymbol string
}{
{
name: "Valid Male Input",
input: []byte("1"),
name: "Valid Male Input with `flag_allow_update_set` set",
input: []byte("1"),
setupfunc: func() {
mockState.SetFlag(flag_allow_update)
mockState.ExecPath = []string{}
},
expectedGender: "male",
executingSymbol: "set_male",
expectedResult: resource.Result{
FlagSet: []uint32{flag_gender_set},
},
},
{
name: "Valid Female Input",
input: []byte("2"),
name: "Valid Female Input when `flag_allow_update` is not set but `flag_gender_set` is set",
input: []byte("2"),
setupfunc: func() {
mockState.ResetFlag(flag_allow_update)
mockState.SetFlag(flag_gender_set)
mockState.ExecPath = []string{}
},
expectedResult: resource.Result{},
expectedGender: "female",
executingSymbol: "set_female",
},
{
name: "Valid Unspecified Input",
name: "Valid Unspecified Input when both `flag_allow_update` and `flag_gender_set` are not set",
setupfunc: func() {
mockState.ResetFlag(flag_allow_update)
mockState.ResetFlag(flag_gender_set)
mockState.ExecPath = []string{}
},
input: []byte("3"),
executingSymbol: "set_unspecified",
expectedResult: resource.Result{},
expectedGender: "unspecified",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.setupfunc()
mockState.ExecPath = append(mockState.ExecPath, tt.executingSymbol)
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(tt.expectedGender)); err != nil {
t.Fatal(err)
}
mockState.ExecPath = append(mockState.ExecPath, tt.executingSymbol)
// Create the MenuHandlers instance with the mock store
h := &MenuHandlers{
userdataStore: store,
st: mockState,
flagManager: fm,
profile: &profile.Profile{Max: 6},
}
expectedResult := resource.Result{}
allowUpdate := h.st.MatchFlag(flag_allow_update, true)
// Call the method
res, err := h.SaveGender(ctx, "save_gender", tt.input)
expectedResult.FlagSet = []uint32{flag_gender_set}
// Assert results
assert.NoError(t, err)
assert.Equal(t, expectedResult, res)
assert.Equal(t, tt.expectedResult, res)
// Verify that the DATA_GENDER entry has been updated with the temporary value
storedGender, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_GENDER)
assert.Equal(t, tt.expectedGender, string(storedGender))
// Verify that the DATA_GENDER entry if the flag_allow_update is set has been updated with the temporary value
if allowUpdate {
storedGender, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_GENDER)
assert.Equal(t, tt.expectedGender, string(storedGender))
} else {
// Verify that DATA_TEMPORARY_VALUE is updated with the latest user input
temporaryGenderValue, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE)
assert.Equal(t, tt.expectedGender, string(temporaryGenderValue))
}
})
}
}
@@ -1071,8 +1315,15 @@ func TestAuthorize(t *testing.T) {
},
},
{
name: "Test with pin that is not a 4 digit",
input: []byte("1235aqds"),
name: "Test with PIN that is more than 4 digits",
input: []byte("12357"),
expectedResult: resource.Result{
FlagSet: []uint32{flag_invalid_pin},
},
},
{
name: "Test with pin that is less than 4 digit",
input: []byte("123"),
expectedResult: resource.Result{
FlagSet: []uint32{flag_invalid_pin},
},
@@ -1650,7 +1901,7 @@ func TestValidateRecipient(t *testing.T) {
},
},
{
name: "Test with valid unregistered recepient",
name: "Test with valid unregistered recipient",
input: []byte("0712345678"),
expectedResult: resource.Result{
FlagSet: []uint32{flag_invalid_recipient_with_invite},
@@ -1658,7 +1909,7 @@ func TestValidateRecipient(t *testing.T) {
},
},
{
name: "Test with valid registered recepient",
name: "Test with valid registered recipient",
input: []byte("0711223344"),
expectedResult: resource.Result{},
},
@@ -1668,7 +1919,12 @@ func TestValidateRecipient(t *testing.T) {
expectedResult: resource.Result{},
},
{
name: "Test with alias recepient",
name: "Test with alias recipient",
input: []byte("foobar.sarafu.eth"),
expectedResult: resource.Result{},
},
{
name: "Test with alias recipient",
input: []byte("alias123.sarafu.local"),
expectedResult: resource.Result{},
},
@@ -1697,7 +1953,7 @@ func TestValidateRecipient(t *testing.T) {
mockAccountService.On("CheckAliasAddress", string(tt.input)).Return(aliasResponse, nil)
// Call the method
res, err := h.ValidateRecipient(ctx, "validate_recepient", tt.input)
res, err := h.ValidateRecipient(ctx, "validate_recipient", tt.input)
if err != nil {
t.Error(err)
@@ -3080,6 +3336,53 @@ func TestCheckBlockedNumPinMisMatch(t *testing.T) {
}
}
func TestSetBack(t *testing.T) {
ctx, store := InitializeTestStore(t)
fm, err := NewFlagManager(flagsPath)
if err != nil {
t.Fatal(err)
}
h := &MenuHandlers{
userdataStore: store,
flagManager: fm,
st: state.NewState(16),
}
flag_back_set, _ := h.flagManager.GetFlag("flag_back_set")
tests := []struct {
name string
input []byte
expectedResult resource.Result
}{
{
name: "Test with `0` input for back navigation",
input: []byte("0"),
expectedResult: resource.Result{
FlagSet: []uint32{flag_back_set},
},
},
{
name: "Test with input that is not back",
input: []byte("1345"),
expectedResult: resource.Result{
FlagReset: []uint32{flag_back_set},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
//Call the function under test
res, _ := h.SetBack(ctx, "set_back", tt.input)
//Assert that the result set to content is what was expected
assert.Equal(t, res, tt.expectedResult, "Result should contain flags set according to user input")
})
}
}
func TestGetCurrentProfileInfo(t *testing.T) {
sessionId := "session123"
ctx, store := InitializeTestStore(t)
@@ -3531,3 +3834,70 @@ func TestClearTemporaryValue(t *testing.T) {
// assert that the temp value is empty
assert.Equal(t, currentTempValue, []byte(""))
}
func TestGetSuggestedAlias(t *testing.T) {
ctx, store := InitializeTestStore(t)
sessionId := "session123"
alias := "foo.sarafu.eth"
ctx = context.WithValue(ctx, "SessionId", sessionId)
h := &MenuHandlers{
userdataStore: store,
}
//Set a suggested alias a temporary value that will be expected to be in the result content
err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(alias))
if err != nil {
t.Fatal(err)
}
res, err := h.GetSuggestedAlias(ctx, "getsuggested_alias", []byte(""))
if err != nil {
t.Fail()
}
assert.Equal(t, res.Content, alias)
}
func TestConfirmNewAlias(t *testing.T) {
ctx, store := InitializeTestStore(t)
sessionId := "session123"
expectedSavedAlias := "fooo.sarafu.eth"
ctx = context.WithValue(ctx, "SessionId", sessionId)
//Set a temporary alias that is suggested,confirm if the the current new alias after confirmation
err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(expectedSavedAlias))
if err != nil {
t.Fatal(err)
}
mockState := state.NewState(128)
fm, err := NewFlagManager(flagsPath)
if err != nil {
t.Fatal(err)
}
h := &MenuHandlers{
userdataStore: store,
st: mockState,
flagManager: fm,
}
flag_alias_set, _ := h.flagManager.GetFlag("flag_alias_set")
expectedResult := resource.Result{
FlagSet: []uint32{flag_alias_set},
}
res, err := h.ConfirmNewAlias(ctx, "confirm_new_alias", []byte(""))
if err != nil {
t.Fail()
}
accAlias, err := store.ReadEntry(ctx, sessionId, storedb.DATA_ACCOUNT_ALIAS)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, expectedResult, res)
assert.Equal(t, expectedSavedAlias, string(accAlias))
}

View File

@@ -140,6 +140,39 @@
}
]
},
{
"name": "menu_my_account_my_alias",
"steps": [
{
"input": "",
"expectedContent": "{balance}\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit"
},
{
"input": "3",
"expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back"
},
{
"input": "",
"expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back"
},
{
"input": "7",
"expectedContent": "Current alias: Not Provided\nEdit my alias:\n0:Back"
},
{
"input": "foo",
"expectedContent": "Your full alias will be: \nPlease enter your PIN to confirm: \n\n0:Back"
},
{
"input": "1234",
"expectedContent": "Your alias has been updated successfully\n0:Back\n9:Quit"
},
{
"input": "0",
"expectedContent": "{balance}\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit"
}
]
},
{
"name": "menu_my_account_reset_others_pin_with_unregistered_number",
"steps": [