github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/cf/commands/user/set_org_role_test.go (about)

     1  package user_test
     2  
     3  import (
     4  	testapi "github.com/cloudfoundry/cli/cf/api/fakes"
     5  	"github.com/cloudfoundry/cli/cf/command_registry"
     6  	"github.com/cloudfoundry/cli/cf/configuration/core_config"
     7  	"github.com/cloudfoundry/cli/cf/models"
     8  	testcmd "github.com/cloudfoundry/cli/testhelpers/commands"
     9  	testconfig "github.com/cloudfoundry/cli/testhelpers/configuration"
    10  	testreq "github.com/cloudfoundry/cli/testhelpers/requirements"
    11  	testterm "github.com/cloudfoundry/cli/testhelpers/terminal"
    12  	. "github.com/onsi/ginkgo"
    13  	. "github.com/onsi/gomega"
    14  
    15  	. "github.com/cloudfoundry/cli/testhelpers/matchers"
    16  )
    17  
    18  var _ = Describe("set-org-role command", func() {
    19  	var (
    20  		ui                  *testterm.FakeUI
    21  		requirementsFactory *testreq.FakeReqFactory
    22  		userRepo            *testapi.FakeUserRepository
    23  		configRepo          core_config.Repository
    24  		deps                command_registry.Dependency
    25  	)
    26  
    27  	updateCommandDependency := func(pluginCall bool) {
    28  		deps.Ui = ui
    29  		deps.Config = configRepo
    30  		deps.RepoLocator = deps.RepoLocator.SetUserRepository(userRepo)
    31  		command_registry.Commands.SetCommand(command_registry.Commands.FindCommand("set-org-role").SetDependency(deps, pluginCall))
    32  	}
    33  
    34  	BeforeEach(func() {
    35  		configRepo = testconfig.NewRepositoryWithDefaults()
    36  
    37  		ui = &testterm.FakeUI{}
    38  		requirementsFactory = &testreq.FakeReqFactory{}
    39  		userRepo = &testapi.FakeUserRepository{}
    40  	})
    41  
    42  	runCommand := func(args ...string) bool {
    43  		return testcmd.RunCliCommand("set-org-role", args, requirementsFactory, updateCommandDependency, false)
    44  	}
    45  
    46  	Describe("requirements", func() {
    47  		It("fails when not logged in", func() {
    48  			Expect(runCommand("hey", "there", "jude")).To(BeFalse())
    49  		})
    50  
    51  		It("fails with usage when not provided exactly three args", func() {
    52  			runCommand("one fish", "two fish") // red fish, blue fish
    53  			Expect(ui.Outputs).To(ContainSubstrings(
    54  				[]string{"Incorrect Usage", "Requires", "arguments"},
    55  			))
    56  		})
    57  	})
    58  
    59  	Context("when logged in", func() {
    60  		BeforeEach(func() {
    61  			requirementsFactory.LoginSuccess = true
    62  
    63  			org := models.Organization{}
    64  			org.Guid = "my-org-guid"
    65  			org.Name = "my-org"
    66  			requirementsFactory.UserFields = models.UserFields{Guid: "my-user-guid", Username: "my-user"}
    67  			requirementsFactory.Organization = org
    68  		})
    69  
    70  		It("sets the given org role on the given user", func() {
    71  			runCommand("some-user", "some-org", "OrgManager")
    72  
    73  			Expect(ui.Outputs).To(ContainSubstrings(
    74  				[]string{"Assigning role", "OrgManager", "my-user", "my-org", "my-user"},
    75  				[]string{"OK"},
    76  			))
    77  			Expect(userRepo.SetOrgRoleUserGuid).To(Equal("my-user-guid"))
    78  			Expect(userRepo.SetOrgRoleOrganizationGuid).To(Equal("my-org-guid"))
    79  			Expect(userRepo.SetOrgRoleRole).To(Equal(models.ORG_MANAGER))
    80  		})
    81  	})
    82  })