github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/engine/profile_edit_test.go (about)

     1  package engine
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/keybase/client/go/libkb"
     7  	keybase1 "github.com/keybase/client/go/protocol/keybase1"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func TestProfileEdit(t *testing.T) {
    12  	tc := SetupEngineTest(t, "TestProfileEdit")
    13  	defer tc.Cleanup()
    14  	fu := CreateAndSignupFakeUser(tc, "track")
    15  
    16  	identify := func() keybase1.UserCard {
    17  		i := newIdentify2WithUIDTester(tc.G)
    18  		tc.G.SetProofServices(i)
    19  
    20  		// add NoSkipSelf and NeedProofSet to go through with the full identify,
    21  		// with RPCs to the outside and all.
    22  		arg := &keybase1.Identify2Arg{
    23  			Uid:              fu.UID(),
    24  			NoSkipSelf:       true,
    25  			NeedProofSet:     true,
    26  			IdentifyBehavior: keybase1.TLFIdentifyBehavior_CLI,
    27  		}
    28  		eng := NewIdentify2WithUID(tc.G, arg)
    29  		uis := libkb.UIs{IdentifyUI: i}
    30  		waiter := launchWaiter(t, i.finishCh)
    31  		m := NewMetaContextForTest(tc).WithUIs(uis)
    32  		err := eng.Run(m)
    33  		if err != nil {
    34  			t.Fatal(err)
    35  		}
    36  		waiter()
    37  		return i.card
    38  	}
    39  
    40  	update := func(b, n, l string) {
    41  		eng := NewProfileEdit(tc.G, keybase1.ProfileEditArg{Location: l, FullName: n, Bio: b})
    42  		m := NewMetaContextForTest(tc)
    43  		err := eng.Run(m)
    44  		if err != nil {
    45  			t.Fatal(err)
    46  		}
    47  	}
    48  
    49  	check := func(card keybase1.UserCard, b, n, l string) {
    50  		require.Equal(t, card.Bio, b, "bio")
    51  		require.Equal(t, card.FullName, n, "fullname")
    52  		require.Equal(t, card.Location, l, "location")
    53  	}
    54  
    55  	card := identify()
    56  	check(card, "", "", "")
    57  
    58  	updateAndCheck := func(b, n, l string) {
    59  		update(b, n, l)
    60  		card = identify()
    61  		check(card, b, n, l)
    62  	}
    63  
    64  	updateAndCheck("An average homo sapien", "Celia", "Earth")
    65  	updateAndCheck("An explorer", "Damon", "Mars")
    66  }