Skip to content

Commit 83dbfa8

Browse files
author
Brian Flores
committed
updatede command and added unit tets
1 parent 71ad0cc commit 83dbfa8

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

plugin/commands/user/details.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,14 @@ func baseUserPrint(user datatypes.User_Customer, keys bool, ui terminal.UI) {
188188
table.Add(T("ID"), utils.FormatIntPointer(user.Id))
189189
table.Add(T("Username"), utils.FormatStringPointer(user.Username))
190190

191-
if keys {
191+
if keys && user.ApiAuthenticationKeys != nil && len(user.ApiAuthenticationKeys) != 0 {
192192
for _, key := range user.ApiAuthenticationKeys {
193193
table.Add(T("APIKEY"), utils.FormatStringPointer(key.AuthenticationKey))
194194
}
195+
} else if user.ApiAuthenticationKeys != nil && len(user.ApiAuthenticationKeys) != 0 {
196+
table.Add(T("APIKEY"), T("Yes"))
197+
} else {
198+
table.Add(T("APIKEY"), T("No"))
195199
}
196200

197201
table.Add(T("Name"), utils.FormatStringPointer(user.FirstName)+" "+utils.FormatStringPointer(user.LastName))

plugin/commands/user/details_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,5 +425,55 @@ var _ = Describe("Detail", func() {
425425
Expect(fakeUI.Outputs()).To(ContainSubstring("2017-11-08T00:00:00Z IAM Token validation successful 80.80.80.80 test2@test.com test2_test.com"))
426426
})
427427
})
428+
429+
Context("user detail with correct id and without apikey", func() {
430+
BeforeEach(func() {
431+
created, _ := time.Parse(time.RFC3339, "2017-11-08T00:00:00Z")
432+
433+
testUser = datatypes.User_Customer{
434+
Id: sl.Int(5555),
435+
Username: sl.String("ATestUser"),
436+
ApiAuthenticationKeys: []datatypes.User_Customer_ApiAuthentication{},
437+
FirstName: sl.String("Name"),
438+
LastName: sl.String("LastName"),
439+
Email: sl.String("user@email.com"),
440+
OpenIdConnectUserName: sl.String("123456"),
441+
Address1: sl.String("addres with number N 123"),
442+
CompanyName: sl.String("NameCompany"),
443+
CreateDate: sl.Time(created),
444+
OfficePhone: sl.String("123456789"),
445+
PptpVpnAllowedFlag: sl.Bool(true),
446+
SslVpnAllowedFlag: sl.Bool(true),
447+
Parent: &datatypes.User_Customer{
448+
Username: sl.String("ParentName"),
449+
},
450+
UserStatus: &datatypes.User_Customer_Status{
451+
Name: sl.String("ACTIVE"),
452+
},
453+
}
454+
fakeUserManager.GetUserReturns(testUser, nil)
455+
})
456+
457+
It("return a user without apikey", func() {
458+
err := testhelpers.RunCobraCommand(cliCommand.Command, "5555", "--keys")
459+
Expect(err).NotTo(HaveOccurred())
460+
Expect(fakeUI.Outputs()).To(ContainSubstring("5555"))
461+
Expect(fakeUI.Outputs()).To(ContainSubstring("ATestUser"))
462+
Expect(fakeUI.Outputs()).To(ContainSubstring("No"))
463+
Expect(fakeUI.Outputs()).To(ContainSubstring("Name LastName"))
464+
Expect(fakeUI.Outputs()).To(ContainSubstring("user@email.com"))
465+
Expect(fakeUI.Outputs()).To(ContainSubstring("123456"))
466+
Expect(fakeUI.Outputs()).To(ContainSubstring("addres with number N 123 - - - - -"))
467+
Expect(fakeUI.Outputs()).To(ContainSubstring("NameCompany"))
468+
Expect(fakeUI.Outputs()).To(ContainSubstring("2017-11-08T00:00:00Z"))
469+
Expect(fakeUI.Outputs()).To(ContainSubstring("123456789"))
470+
Expect(fakeUI.Outputs()).To(ContainSubstring("ParentName"))
471+
Expect(fakeUI.Outputs()).To(ContainSubstring("ACTIVE"))
472+
Expect(fakeUI.Outputs()).To(ContainSubstring("true"))
473+
Expect(fakeUI.Outputs()).To(ContainSubstring("true"))
474+
Expect(fakeUI.Outputs()).To(ContainSubstring("2017-11-08T00:00:00Z"))
475+
Expect(fakeUI.Outputs()).To(ContainSubstring("2017-11-08T00:00:00Z"))
476+
})
477+
})
428478
})
429479
})

0 commit comments

Comments
 (0)