From 5317ed3bd571f2ec981f20591a9bf692ec235ea5 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 12 Mar 2025 10:31:10 +0300 Subject: [PATCH] add test to confirm new alias --- handlers/application/menuhandler_test.go | 42 ++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/handlers/application/menuhandler_test.go b/handlers/application/menuhandler_test.go index 6b1261e..a4501aa 100644 --- a/handlers/application/menuhandler_test.go +++ b/handlers/application/menuhandler_test.go @@ -3852,3 +3852,45 @@ func TestGetSuggestedAlias(t *testing.T) { 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)) +}