update tests

This commit is contained in:
Carlosokumu 2024-12-04 09:08:25 +03:00
parent ed632248c5
commit e7c4b5bca7
Signed by: carlos
GPG Key ID: 7BD6BC8160A5C953

View File

@ -179,11 +179,14 @@ func TestSaveFirstname(t *testing.T) {
fm, _ := NewFlagManager(flagsPath) fm, _ := NewFlagManager(flagsPath)
flag_allow_update, _ := fm.GetFlag("flag_allow_update") flag_allow_update, _ := fm.GetFlag("flag_allow_update")
flag_firstname_set, _ := fm.GetFlag("flag_firstname_set")
// Set the flag in the State // Set the flag in the State
mockState := state.NewState(16) mockState := state.NewState(128)
mockState.SetFlag(flag_allow_update) mockState.SetFlag(flag_allow_update)
expectedResult := resource.Result{}
// Define test data // Define test data
firstName := "John" firstName := "John"
@ -191,6 +194,8 @@ func TestSaveFirstname(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
expectedResult.FlagSet = []uint32{flag_firstname_set}
// Create the Handlers instance with the mock store // Create the Handlers instance with the mock store
h := &Handlers{ h := &Handlers{
userdataStore: store, userdataStore: store,
@ -203,7 +208,7 @@ func TestSaveFirstname(t *testing.T) {
// Assert results // Assert results
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, resource.Result{}, res) assert.Equal(t, expectedResult, res)
// Verify that the DATA_FIRST_NAME entry has been updated with the temporary value // Verify that the DATA_FIRST_NAME entry has been updated with the temporary value
storedFirstName, _ := store.ReadEntry(ctx, sessionId, common.DATA_FIRST_NAME) storedFirstName, _ := store.ReadEntry(ctx, sessionId, common.DATA_FIRST_NAME)
@ -218,11 +223,16 @@ func TestSaveFamilyname(t *testing.T) {
fm, _ := NewFlagManager(flagsPath) fm, _ := NewFlagManager(flagsPath)
flag_allow_update, _ := fm.GetFlag("flag_allow_update") flag_allow_update, _ := fm.GetFlag("flag_allow_update")
flag_firstname_set, _ := fm.GetFlag("flag_familyname_set")
// Set the flag in the State // Set the flag in the State
mockState := state.NewState(16) mockState := state.NewState(128)
mockState.SetFlag(flag_allow_update) mockState.SetFlag(flag_allow_update)
expectedResult := resource.Result{}
expectedResult.FlagSet = []uint32{flag_firstname_set}
// Define test data // Define test data
familyName := "Doeee" familyName := "Doeee"
@ -242,7 +252,7 @@ func TestSaveFamilyname(t *testing.T) {
// Assert results // Assert results
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, resource.Result{}, res) assert.Equal(t, expectedResult, res)
// Verify that the DATA_FAMILY_NAME entry has been updated with the temporary value // Verify that the DATA_FAMILY_NAME entry has been updated with the temporary value
storedFamilyName, _ := store.ReadEntry(ctx, sessionId, common.DATA_FAMILY_NAME) storedFamilyName, _ := store.ReadEntry(ctx, sessionId, common.DATA_FAMILY_NAME)
@ -257,11 +267,14 @@ func TestSaveYoB(t *testing.T) {
fm, _ := NewFlagManager(flagsPath) fm, _ := NewFlagManager(flagsPath)
flag_allow_update, _ := fm.GetFlag("flag_allow_update") flag_allow_update, _ := fm.GetFlag("flag_allow_update")
flag_yob_set, _ := fm.GetFlag("flag_yob_set")
// Set the flag in the State // Set the flag in the State
mockState := state.NewState(16) mockState := state.NewState(108)
mockState.SetFlag(flag_allow_update) mockState.SetFlag(flag_allow_update)
expectedResult := resource.Result{}
// Define test data // Define test data
yob := "1980" yob := "1980"
@ -269,6 +282,8 @@ func TestSaveYoB(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
expectedResult.FlagSet = []uint32{flag_yob_set}
// Create the Handlers instance with the mock store // Create the Handlers instance with the mock store
h := &Handlers{ h := &Handlers{
userdataStore: store, userdataStore: store,
@ -281,7 +296,7 @@ func TestSaveYoB(t *testing.T) {
// Assert results // Assert results
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, resource.Result{}, res) assert.Equal(t, expectedResult, res)
// Verify that the DATA_YOB entry has been updated with the temporary value // Verify that the DATA_YOB entry has been updated with the temporary value
storedYob, _ := store.ReadEntry(ctx, sessionId, common.DATA_YOB) storedYob, _ := store.ReadEntry(ctx, sessionId, common.DATA_YOB)
@ -296,11 +311,14 @@ func TestSaveLocation(t *testing.T) {
fm, _ := NewFlagManager(flagsPath) fm, _ := NewFlagManager(flagsPath)
flag_allow_update, _ := fm.GetFlag("flag_allow_update") flag_allow_update, _ := fm.GetFlag("flag_allow_update")
flag_location_set, _ := fm.GetFlag("flag_location_set")
// Set the flag in the State // Set the flag in the State
mockState := state.NewState(16) mockState := state.NewState(108)
mockState.SetFlag(flag_allow_update) mockState.SetFlag(flag_allow_update)
expectedResult := resource.Result{}
// Define test data // Define test data
location := "Kilifi" location := "Kilifi"
@ -308,6 +326,8 @@ func TestSaveLocation(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
expectedResult.FlagSet = []uint32{flag_location_set}
// Create the Handlers instance with the mock store // Create the Handlers instance with the mock store
h := &Handlers{ h := &Handlers{
userdataStore: store, userdataStore: store,
@ -320,7 +340,7 @@ func TestSaveLocation(t *testing.T) {
// Assert results // Assert results
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, resource.Result{}, res) assert.Equal(t, expectedResult, res)
// Verify that the DATA_LOCATION entry has been updated with the temporary value // Verify that the DATA_LOCATION entry has been updated with the temporary value
storedLocation, _ := store.ReadEntry(ctx, sessionId, common.DATA_LOCATION) storedLocation, _ := store.ReadEntry(ctx, sessionId, common.DATA_LOCATION)
@ -335,11 +355,14 @@ func TestSaveOfferings(t *testing.T) {
fm, _ := NewFlagManager(flagsPath) fm, _ := NewFlagManager(flagsPath)
flag_allow_update, _ := fm.GetFlag("flag_allow_update") flag_allow_update, _ := fm.GetFlag("flag_allow_update")
flag_offerings_set, _ := fm.GetFlag("flag_offerings_set")
// Set the flag in the State // Set the flag in the State
mockState := state.NewState(16) mockState := state.NewState(108)
mockState.SetFlag(flag_allow_update) mockState.SetFlag(flag_allow_update)
expectedResult := resource.Result{}
// Define test data // Define test data
offerings := "Bananas" offerings := "Bananas"
@ -347,6 +370,8 @@ func TestSaveOfferings(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
expectedResult.FlagSet = []uint32{flag_offerings_set}
// Create the Handlers instance with the mock store // Create the Handlers instance with the mock store
h := &Handlers{ h := &Handlers{
userdataStore: store, userdataStore: store,
@ -359,7 +384,7 @@ func TestSaveOfferings(t *testing.T) {
// Assert results // Assert results
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, resource.Result{}, res) assert.Equal(t, expectedResult, res)
// Verify that the DATA_OFFERINGS entry has been updated with the temporary value // Verify that the DATA_OFFERINGS entry has been updated with the temporary value
storedOfferings, _ := store.ReadEntry(ctx, sessionId, common.DATA_OFFERINGS) storedOfferings, _ := store.ReadEntry(ctx, sessionId, common.DATA_OFFERINGS)
@ -374,9 +399,10 @@ func TestSaveGender(t *testing.T) {
fm, _ := NewFlagManager(flagsPath) fm, _ := NewFlagManager(flagsPath)
flag_allow_update, _ := fm.GetFlag("flag_allow_update") flag_allow_update, _ := fm.GetFlag("flag_allow_update")
flag_gender_set, _ := fm.GetFlag("flag_gender_set")
// Set the flag in the State // Set the flag in the State
mockState := state.NewState(16) mockState := state.NewState(108)
mockState.SetFlag(flag_allow_update) mockState.SetFlag(flag_allow_update)
// Define test cases // Define test cases
@ -420,12 +446,16 @@ func TestSaveGender(t *testing.T) {
flagManager: fm.parser, flagManager: fm.parser,
} }
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, resource.Result{}, res) assert.Equal(t, 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, common.DATA_GENDER) storedGender, _ := store.ReadEntry(ctx, sessionId, common.DATA_GENDER)