Compare commits

...

2 Commits

View File

@ -713,59 +713,74 @@ func TestSaveGender(t *testing.T) {
// Set the flag in the State // Set the flag in the State
mockState := state.NewState(108) mockState := state.NewState(108)
mockState.SetFlag(flag_allow_update)
// Define test cases // Define test cases
tests := []struct { tests := []struct {
name string name string
setupfunc func()
input []byte input []byte
expectedGender string expectedGender string
expectedResult resource.Result
executingSymbol string executingSymbol string
}{ }{
{ {
name: "Valid Male Input", name: "Valid Male Input with `flag_allow_update_set` set",
input: []byte("1"), input: []byte("1"),
setupfunc: func() {
mockState.SetFlag(flag_allow_update)
},
expectedGender: "male", expectedGender: "male",
executingSymbol: "set_male", executingSymbol: "set_male",
expectedResult: resource.Result{
FlagSet: []uint32{flag_gender_set},
},
}, },
{ {
name: "Valid Female Input", name: "Valid Female Input when `flag_allow_update` is not set but `flag_gender_set` is set",
input: []byte("2"), input: []byte("2"),
setupfunc: func() {
mockState.ResetFlag(flag_allow_update)
mockState.SetFlag(flag_gender_set)
},
expectedResult: resource.Result{},
expectedGender: "female", expectedGender: "female",
executingSymbol: "set_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)
},
input: []byte("3"), input: []byte("3"),
executingSymbol: "set_unspecified", executingSymbol: "set_unspecified",
expectedResult: resource.Result{},
expectedGender: "unspecified", expectedGender: "unspecified",
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { 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 { if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(tt.expectedGender)); err != nil {
t.Fatal(err) t.Fatal(err)
} }
mockState.ExecPath = append(mockState.ExecPath, tt.executingSymbol)
// Create the MenuHandlers instance with the mock store // Create the MenuHandlers instance with the mock store
h := &MenuHandlers{ h := &MenuHandlers{
userdataStore: store, userdataStore: store,
st: mockState, st: mockState,
flagManager: fm, flagManager: fm,
profile: &profile.Profile{Max: 6},
} }
expectedResult := resource.Result{}
// Call the method // Call the method
res, err := h.SaveGender(ctx, "save_gender", tt.input) res, err := h.SaveGender(ctx, "save_gender", tt.input)
expectedResult.FlagSet = []uint32{flag_gender_set}
// Assert results // Assert results
assert.NoError(t, err) 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 // Verify that the DATA_GENDER entry has been updated with the temporary value
storedGender, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_GENDER) storedGender, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_GENDER)
@ -1865,7 +1880,7 @@ func TestValidateRecipient(t *testing.T) {
}, },
}, },
{ {
name: "Test with valid unregistered recepient", name: "Test with valid unregistered recipient",
input: []byte("0712345678"), input: []byte("0712345678"),
expectedResult: resource.Result{ expectedResult: resource.Result{
FlagSet: []uint32{flag_invalid_recipient_with_invite}, FlagSet: []uint32{flag_invalid_recipient_with_invite},
@ -1873,7 +1888,7 @@ func TestValidateRecipient(t *testing.T) {
}, },
}, },
{ {
name: "Test with valid registered recepient", name: "Test with valid registered recipient",
input: []byte("0711223344"), input: []byte("0711223344"),
expectedResult: resource.Result{}, expectedResult: resource.Result{},
}, },
@ -1883,12 +1898,12 @@ func TestValidateRecipient(t *testing.T) {
expectedResult: resource.Result{}, expectedResult: resource.Result{},
}, },
{ {
name: "Test with alias recepient", name: "Test with alias recipient",
input: []byte("foobar"), input: []byte("foobar.sarafu.eth"),
expectedResult: resource.Result{}, expectedResult: resource.Result{},
}, },
{ {
name: "Test with alias recepient", name: "Test with alias recipient",
input: []byte("alias123.sarafu.local"), input: []byte("alias123.sarafu.local"),
expectedResult: resource.Result{}, expectedResult: resource.Result{},
}, },
@ -1917,7 +1932,7 @@ func TestValidateRecipient(t *testing.T) {
mockAccountService.On("CheckAliasAddress", string(tt.input)).Return(aliasResponse, nil) mockAccountService.On("CheckAliasAddress", string(tt.input)).Return(aliasResponse, nil)
// Call the method // Call the method
res, err := h.ValidateRecipient(ctx, "validate_recepient", tt.input) res, err := h.ValidateRecipient(ctx, "validate_recipient", tt.input)
if err != nil { if err != nil {
t.Error(err) t.Error(err)