test: save_gender add check for values in respective data keys when flag_allow update is set
This commit is contained in:
parent
4dbe69954c
commit
2b16f57aad
@ -728,6 +728,7 @@ func TestSaveGender(t *testing.T) {
|
|||||||
input: []byte("1"),
|
input: []byte("1"),
|
||||||
setupfunc: func() {
|
setupfunc: func() {
|
||||||
mockState.SetFlag(flag_allow_update)
|
mockState.SetFlag(flag_allow_update)
|
||||||
|
mockState.ExecPath = []string{}
|
||||||
},
|
},
|
||||||
expectedGender: "male",
|
expectedGender: "male",
|
||||||
executingSymbol: "set_male",
|
executingSymbol: "set_male",
|
||||||
@ -741,6 +742,7 @@ func TestSaveGender(t *testing.T) {
|
|||||||
setupfunc: func() {
|
setupfunc: func() {
|
||||||
mockState.ResetFlag(flag_allow_update)
|
mockState.ResetFlag(flag_allow_update)
|
||||||
mockState.SetFlag(flag_gender_set)
|
mockState.SetFlag(flag_gender_set)
|
||||||
|
mockState.ExecPath = []string{}
|
||||||
},
|
},
|
||||||
expectedResult: resource.Result{},
|
expectedResult: resource.Result{},
|
||||||
expectedGender: "female",
|
expectedGender: "female",
|
||||||
@ -751,6 +753,7 @@ func TestSaveGender(t *testing.T) {
|
|||||||
setupfunc: func() {
|
setupfunc: func() {
|
||||||
mockState.ResetFlag(flag_allow_update)
|
mockState.ResetFlag(flag_allow_update)
|
||||||
mockState.ResetFlag(flag_gender_set)
|
mockState.ResetFlag(flag_gender_set)
|
||||||
|
mockState.ExecPath = []string{}
|
||||||
},
|
},
|
||||||
input: []byte("3"),
|
input: []byte("3"),
|
||||||
executingSymbol: "set_unspecified",
|
executingSymbol: "set_unspecified",
|
||||||
@ -763,6 +766,7 @@ func TestSaveGender(t *testing.T) {
|
|||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
tt.setupfunc()
|
tt.setupfunc()
|
||||||
mockState.ExecPath = append(mockState.ExecPath, tt.executingSymbol)
|
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)
|
||||||
}
|
}
|
||||||
@ -774,6 +778,7 @@ func TestSaveGender(t *testing.T) {
|
|||||||
flagManager: fm,
|
flagManager: fm,
|
||||||
profile: &profile.Profile{Max: 6},
|
profile: &profile.Profile{Max: 6},
|
||||||
}
|
}
|
||||||
|
allowUpdate := h.st.MatchFlag(flag_allow_update, true)
|
||||||
|
|
||||||
// Call the method
|
// Call the method
|
||||||
res, err := h.SaveGender(ctx, "save_gender", tt.input)
|
res, err := h.SaveGender(ctx, "save_gender", tt.input)
|
||||||
@ -782,9 +787,15 @@ func TestSaveGender(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, tt.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 if the flag_allow_update is set has been updated with the temporary value
|
||||||
storedGender, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_GENDER)
|
if allowUpdate {
|
||||||
assert.Equal(t, tt.expectedGender, string(storedGender))
|
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))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user