@@ -34,11 +34,12 @@ func (c *sequentialMockClient) MakeUnauthenticatedRequest(_ string, _ string, _
3434}
3535
3636func TestWhoAmI (t * testing.T ) {
37- t .Run ("shows member name, email, role, and token " , func (t * testing.T ) {
37+ t .Run ("shows member name, email, role, token, and organization " , func (t * testing.T ) {
3838 mockClient := & sequentialMockClient {
3939 responses : [][]byte {
4040 []byte (`{"memberId": "abc123", "tokenName": "my-token", "tokenKind": "personal", "accountId": "acct1"}` ),
4141 []byte (`{"_id": "abc123", "email": "ariel@acme.com", "firstName": "Ariel", "lastName": "Flores", "role": "admin"}` ),
42+ []byte (`{"_id": "acct1", "organization": "Acme Inc"}` ),
4243 },
4344 }
4445
@@ -55,6 +56,30 @@ func TestWhoAmI(t *testing.T) {
5556 assert .Contains (t , string (output ), "Ariel Flores <ariel@acme.com>" )
5657 assert .Contains (t , string (output ), "Role: admin" )
5758 assert .Contains (t , string (output ), "Token: my-token (personal)" )
59+ assert .Contains (t , string (output ), "Account: Acme Inc (acct1)" )
60+ })
61+
62+ t .Run ("falls back to account ID when organization is unavailable" , func (t * testing.T ) {
63+ mockClient := & sequentialMockClient {
64+ responses : [][]byte {
65+ []byte (`{"memberId": "abc123", "tokenName": "my-token", "tokenKind": "personal", "accountId": "acct1"}` ),
66+ []byte (`{"_id": "abc123", "email": "ariel@acme.com", "firstName": "Ariel", "lastName": "Flores", "role": "admin"}` ),
67+ []byte (`{"_id": "acct1"}` ),
68+ },
69+ }
70+
71+ t .Setenv ("LD_ACCESS_TOKEN" , "abcd1234" )
72+
73+ output , err := cmd .CallCmd (
74+ t ,
75+ cmd.APIClients {ResourcesClient : mockClient },
76+ analytics.NoopClientFn {}.Tracker (),
77+ []string {"whoami" },
78+ )
79+
80+ require .NoError (t , err )
81+ assert .Contains (t , string (output ), "Account: acct1" )
82+ assert .NotContains (t , string (output ), "Account: Acme" )
5883 })
5984
6085 t .Run ("without member ID shows token info only" , func (t * testing.T ) {
0 commit comments