Example #1
0
		It("passes requirements when targeting a space or org", func() {
			callTarget([]string{"-s", "i-love-space"}, reqFactory, config, orgRepo, spaceRepo)
			Expect(testcmd.CommandDidPassRequirements).To(BeTrue())

			callTarget([]string{"-o", "orgs-are-delightful"}, reqFactory, config, orgRepo, spaceRepo)
			Expect(testcmd.CommandDidPassRequirements).To(BeTrue())
		})

		It("TestTargetOrganizationWhenUserHasAccess", func() {
			org := models.Organization{}
			org.Name = "my-organization"
			org.Guid = "my-organization-guid"

			orgRepo.Organizations = []models.Organization{org}
			orgRepo.FindByNameOrganization = org

			ui := callTarget([]string{"-o", "my-organization"}, reqFactory, config, orgRepo, spaceRepo)

			Expect(orgRepo.FindByNameName).To(Equal("my-organization"))
			Expect(ui.ShowConfigurationCalled).To(BeTrue())

			Expect(config.OrganizationFields().Guid).To(Equal("my-organization-guid"))
		})

		It("TestTargetOrganizationWhenUserDoesNotHaveAccess", func() {
			orgs := []models.Organization{}
			orgRepo.Organizations = orgs
			orgRepo.FindByNameErr = true

			ui := callTarget([]string{"-o", "my-organization"}, reqFactory, config, orgRepo, spaceRepo)
Example #2
0
				"password": "******",
			}))

			Expect(orgRepo.FindByNameName).To(Equal("my-org"))
			Expect(spaceRepo.FindByNameName).To(Equal("my-space"))

			Expect(ui.ShowConfigurationCalled).To(BeTrue())
		})

		It("doesn't ask the user to select an org if they have one in their config", func() {
			Config.SetOrganizationFields(org2.OrganizationFields)

			Flags = []string{"-s", "my-space"}
			ui.Inputs = []string{"http://api.example.com", "*****@*****.**", "password"}

			orgRepo.FindByNameOrganization = models.Organization{}

			l := NewLogin(ui, Config, authRepo, endpointRepo, orgRepo, spaceRepo)
			testcmd.RunCommand(l, testcmd.NewContext("login", Flags), nil)

			Expect(Config.ApiEndpoint()).To(Equal("http://api.example.com"))
			Expect(Config.OrganizationFields().Guid).To(Equal("my-org-guid"))
			Expect(Config.SpaceFields().Guid).To(Equal("my-space-guid"))
			Expect(Config.AccessToken()).To(Equal("my_access_token"))
			Expect(Config.RefreshToken()).To(Equal("my_refresh_token"))

			Expect(endpointRepo.UpdateEndpointReceived).To(Equal("http://api.example.com"))
			Expect(authRepo.AuthenticateArgs.Credentials).To(Equal(map[string]string{
				"username": "******",
				"password": "******",
			}))