github.com/liamawhite/cli-with-i18n@v6.32.1-0.20171122084555-dede0a5c3448+incompatible/api/cloudcontroller/ccv2/delete_organization_test.go (about)

     1  // generated from codetemplates/delete_async_by_guid_test.go.template
     2  
     3  package ccv2_test
     4  
     5  import (
     6  	"net/http"
     7  
     8  	"github.com/liamawhite/cli-with-i18n/api/cloudcontroller/ccerror"
     9  	. "github.com/liamawhite/cli-with-i18n/api/cloudcontroller/ccv2"
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  	. "github.com/onsi/gomega/ghttp"
    13  )
    14  
    15  var _ = Describe("DeleteOrganization", func() {
    16  	var client *Client
    17  
    18  	BeforeEach(func() {
    19  		client = NewTestClient()
    20  	})
    21  
    22  	Context("when no errors are encountered", func() {
    23  		BeforeEach(func() {
    24  			jsonResponse := `{
    25  				"metadata": {
    26  					"guid": "job-guid",
    27  					"created_at": "2016-06-08T16:41:27Z",
    28  					"url": "/v2/jobs/job-guid"
    29  				},
    30  				"entity": {
    31  					"guid": "job-guid",
    32  					"status": "queued"
    33  				}
    34  			}`
    35  
    36  			server.AppendHandlers(
    37  				CombineHandlers(
    38  					VerifyRequest(http.MethodDelete, "/v2/organizations/some-organization-guid", "recursive=true&async=true"),
    39  					RespondWith(http.StatusAccepted, jsonResponse, http.Header{"X-Cf-Warnings": {"warning-1, warning-2"}}),
    40  				))
    41  		})
    42  
    43  		It("deletes the Organization and returns all warnings", func() {
    44  			job, warnings, err := client.DeleteOrganization("some-organization-guid")
    45  
    46  			Expect(err).NotTo(HaveOccurred())
    47  			Expect(warnings).To(ConsistOf(Warnings{"warning-1", "warning-2"}))
    48  			Expect(job.GUID).To(Equal("job-guid"))
    49  			Expect(job.Status).To(Equal(JobStatusQueued))
    50  		})
    51  	})
    52  
    53  	Context("when an error is encountered", func() {
    54  		BeforeEach(func() {
    55  			response := `{
    56  "code": 30003,
    57  "description": "The Organization could not be found: some-organization-guid",
    58  "error_code": "CF-OrganizationNotFound"
    59  }`
    60  			server.AppendHandlers(
    61  				CombineHandlers(
    62  					VerifyRequest(http.MethodDelete, "/v2/organizations/some-organization-guid", "recursive=true&async=true"),
    63  					RespondWith(http.StatusNotFound, response, http.Header{"X-Cf-Warnings": {"warning-1, warning-2"}}),
    64  				))
    65  		})
    66  
    67  		It("returns an error and all warnings", func() {
    68  			_, warnings, err := client.DeleteOrganization("some-organization-guid")
    69  
    70  			Expect(err).To(MatchError(ccerror.ResourceNotFoundError{
    71  				Message: "The Organization could not be found: some-organization-guid",
    72  			}))
    73  			Expect(warnings).To(ConsistOf(Warnings{"warning-1", "warning-2"}))
    74  		})
    75  	})
    76  })