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

     1  package engine
     2  
     3  import (
     4  	"github.com/keybase/client/go/libkb"
     5  	keybase1 "github.com/keybase/client/go/protocol/keybase1"
     6  	"testing"
     7  )
     8  
     9  func assertEmail(mctx libkb.MetaContext, t *testing.T, expected string) {
    10  	res, err := mctx.G().API.Get(mctx, libkb.APIArg{
    11  		Endpoint:    "me",
    12  		SessionType: libkb.APISessionTypeREQUIRED,
    13  	})
    14  	if err != nil {
    15  		t.Fatal(err)
    16  	}
    17  	gotten, err := res.Body.AtPath("me.emails.primary.email").GetString()
    18  	if err != nil {
    19  		t.Fatal(err)
    20  	}
    21  	if gotten != expected {
    22  		t.Fatalf("wanted email '%s', but got '%s'", expected, gotten)
    23  	}
    24  }
    25  
    26  func TestSignedEmailChange(t *testing.T) {
    27  	tc := SetupEngineTest(t, "EmailChange")
    28  	defer tc.Cleanup()
    29  
    30  	u := CreateAndSignupFakeUser(tc, "email")
    31  
    32  	m := NewMetaContextForTest(tc)
    33  	assertEmail(m, t, u.Email)
    34  
    35  	newEmail := "new-" + u.Email
    36  	arg := &keybase1.EmailChangeArg{
    37  		NewEmail: newEmail,
    38  	}
    39  
    40  	// using an empty secret ui to make sure existing pp doesn't come from ui prompt:
    41  	uis := libkb.UIs{
    42  		SecretUI: &libkb.TestSecretUI{},
    43  	}
    44  	m = m.WithUIs(uis)
    45  	eng := NewEmailChange(tc.G, arg)
    46  	if err := RunEngine2(m, eng); err != nil {
    47  		t.Fatal(err)
    48  	}
    49  	assertEmail(m, t, newEmail)
    50  }