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

     1  package systests
     2  
     3  import (
     4  	"testing"
     5  
     6  	"golang.org/x/net/context"
     7  
     8  	keybase1 "github.com/keybase/client/go/protocol/keybase1"
     9  
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func testSubteamCreate(t *testing.T, joinSubteam bool) {
    14  	t.Logf("testSubteamCreate(joinSubteam: %t)", joinSubteam)
    15  
    16  	tt := newTeamTester(t)
    17  	defer tt.cleanup()
    18  
    19  	ann := tt.addUser("ann")
    20  	t.Logf("Signed up ann %s", ann.username)
    21  
    22  	parentName := ann.createTeam()
    23  	subteamName := parentName + ".test"
    24  
    25  	cli := ann.teamsClient
    26  	res, err := cli.TeamCreate(context.Background(), keybase1.TeamCreateArg{
    27  		Name:        subteamName,
    28  		JoinSubteam: joinSubteam,
    29  	})
    30  	require.NoError(t, err)
    31  	require.Equal(t, joinSubteam, res.CreatorAdded)
    32  	require.True(t, res.ChatSent)
    33  
    34  	t.Logf("Created subteam %s", subteamName)
    35  
    36  	teamObj := ann.loadTeam(subteamName, false /* admin */)
    37  	role, err := teamObj.MemberRole(context.Background(), ann.userVersion())
    38  	require.NoError(t, err)
    39  
    40  	if joinSubteam {
    41  		require.Equal(t, keybase1.TeamRole_ADMIN, role, "role should be ADMIN")
    42  		require.EqualValues(t, 1, teamObj.CurrentSeqno(), "expecting just one link in team")
    43  	} else {
    44  		require.Equal(t, keybase1.TeamRole_NONE, role, "role should be NONE")
    45  		// Expecting 2 links in main chain: subteam_head, leave
    46  		// And a link in hidden chain after leave: rotate_key
    47  		ann.waitForAnyRotateByID(teamObj.ID, keybase1.Seqno(2) /* toSeqno */, keybase1.Seqno(1) /* toHiddenSeqno */)
    48  	}
    49  }
    50  
    51  func TestSubteamCreate(t *testing.T) {
    52  	t.Run("just create", func(t *testing.T) { testSubteamCreate(t, false) })
    53  	t.Run("create and join", func(t *testing.T) { testSubteamCreate(t, true) })
    54  }