github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/api/uaa/prompts_test.go (about)

     1  package uaa_test
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"code.cloudfoundry.org/cli/api/uaa"
     7  	. "code.cloudfoundry.org/cli/api/uaa"
     8  	"code.cloudfoundry.org/cli/api/uaa/uaafakes"
     9  
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  	. "github.com/onsi/gomega/ghttp"
    13  )
    14  
    15  var _ = Describe("Prompts", func() {
    16  	var (
    17  		client     *Client
    18  		fakeConfig *uaafakes.FakeConfig
    19  	)
    20  
    21  	BeforeEach(func() {
    22  		fakeConfig = NewTestConfig()
    23  		client = NewClient(fakeConfig)
    24  
    25  		client.Info.Links.Login = "https://" + TestAuthorizationResource
    26  	})
    27  
    28  	Describe("GetLoginPrompts", func() {
    29  		var (
    30  			prompts map[string][]string
    31  			err     error
    32  		)
    33  
    34  		JustBeforeEach(func() {
    35  			prompts, err = client.GetLoginPrompts()
    36  		})
    37  
    38  		When("the request succeeds", func() {
    39  			BeforeEach(func() {
    40  				response := `{
    41  					"prompts": {
    42  						"one": ["a", "b"],
    43  						"two": ["c", "d"]
    44  					}
    45  				}`
    46  
    47  				server.AppendHandlers(
    48  					CombineHandlers(
    49  						verifyRequestHost(TestAuthorizationResource),
    50  						VerifyRequest(http.MethodGet, "/login"),
    51  						RespondWith(http.StatusOK, response),
    52  					),
    53  				)
    54  			})
    55  
    56  			It("returns the login prompts", func() {
    57  				Expect(err).NotTo(HaveOccurred())
    58  				Expect(prompts).To(Equal(map[string][]string{
    59  					"one": {"a", "b"},
    60  					"two": {"c", "d"},
    61  				}))
    62  			})
    63  		})
    64  
    65  		When("the request fails", func() {
    66  			BeforeEach(func() {
    67  				server.AppendHandlers(
    68  					CombineHandlers(
    69  						verifyRequestHost(TestAuthorizationResource),
    70  						VerifyRequest(http.MethodGet, "/login"),
    71  						RespondWith(http.StatusTeapot, `{}`),
    72  					),
    73  				)
    74  			})
    75  
    76  			It("returns the error", func() {
    77  				Expect(err).To(MatchError(uaa.RawHTTPStatusError{
    78  					StatusCode:  http.StatusTeapot,
    79  					RawResponse: []byte(`{}`),
    80  				}))
    81  			})
    82  		})
    83  	})
    84  })