github.com/aiven/aiven-go-client@v1.36.0/billing_group_acc_test.go (about)

     1  package aiven
     2  
     3  import (
     4  	"math/rand"
     5  	"strconv"
     6  
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/gomega"
     9  )
    10  
    11  var _ = Describe("BillingGroup", func() {
    12  	var (
    13  		billingGName string
    14  		billingG     *BillingGroup
    15  		copiedBG     *BillingGroup
    16  		err          error
    17  	)
    18  
    19  	BeforeEach(func() {
    20  		billingGName = "test-acc-bg-" + strconv.Itoa(rand.Int())
    21  		billingG, err = client.BillingGroup.Create(BillingGroupRequest{
    22  			BillingGroupName: billingGName,
    23  			Company:          ToStringPointer("testC1"),
    24  			AddressLines:     []string{"NYC Some Street 123 A"},
    25  			CountryCode:      ToStringPointer("US"),
    26  			City:             ToStringPointer("NY"),
    27  			ZipCode:          ToStringPointer("101778"),
    28  			BillingCurrency:  ToStringPointer("EUR"),
    29  		})
    30  	})
    31  
    32  	Context("Billing group tests", func() {
    33  		It("should not error", func() {
    34  			Expect(err).NotTo(HaveOccurred())
    35  		})
    36  
    37  		It("should populate fields properly", func() {
    38  			Expect(billingG).NotTo(BeNil())
    39  
    40  			if billingG != nil {
    41  				Expect(*billingG.Company).NotTo(BeEmpty())
    42  				Expect(billingG.AddressLines).NotTo(BeEmpty())
    43  				Expect(*billingG.CountryCode).NotTo(BeEmpty())
    44  				Expect(*billingG.City).NotTo(BeEmpty())
    45  				Expect(*billingG.ZipCode).NotTo(BeEmpty())
    46  				Expect(*billingG.BillingCurrency).NotTo(BeEmpty())
    47  				Expect(billingG.BillingGroupName).NotTo(BeEmpty())
    48  			}
    49  		})
    50  
    51  		It("update and get checks", func() {
    52  			_, err = client.BillingGroup.Update(billingG.Id, BillingGroupRequest{
    53  				BillingExtraText: ToStringPointer("some text ..."),
    54  			})
    55  			Expect(err).NotTo(HaveOccurred())
    56  
    57  			billingG, err = client.BillingGroup.Get(billingG.Id)
    58  			Expect(err).NotTo(HaveOccurred())
    59  
    60  			if billingG != nil {
    61  				Expect(*billingG.Company).NotTo(BeEmpty())
    62  				Expect(billingG.AddressLines).NotTo(BeEmpty())
    63  				Expect(*billingG.CountryCode).NotTo(BeEmpty())
    64  				Expect(*billingG.City).NotTo(BeEmpty())
    65  				Expect(*billingG.ZipCode).NotTo(BeEmpty())
    66  				Expect(*billingG.BillingCurrency).NotTo(BeEmpty())
    67  				Expect(billingG.BillingGroupName).NotTo(BeEmpty())
    68  				Expect(*billingG.BillingExtraText).NotTo(BeEmpty())
    69  			}
    70  		})
    71  
    72  		It("check empty assigned projects list", func() {
    73  			projects, err := client.BillingGroup.GetProjects(billingG.Id)
    74  			Expect(err).NotTo(HaveOccurred())
    75  			Expect(projects).To(BeEmpty())
    76  		})
    77  
    78  		It("assign a project", func() {
    79  			projectName := "test-acc-pr-" + strconv.Itoa(rand.Int())
    80  			_, err = client.Projects.Create(CreateProjectRequest{
    81  				Project: projectName,
    82  				VatID:   ToStringPointer(""),
    83  				Tags:    map[string]string{},
    84  			})
    85  			Expect(err).NotTo(HaveOccurred())
    86  
    87  			err = client.BillingGroup.AssignProjects(billingG.Id, []string{projectName})
    88  			Expect(err).NotTo(HaveOccurred())
    89  
    90  			projects, errG := client.BillingGroup.GetProjects(billingG.Id)
    91  			Expect(errG).NotTo(HaveOccurred())
    92  			Expect(projects).NotTo(BeEmpty())
    93  
    94  			err = client.Projects.Delete(projectName)
    95  			Expect(err).NotTo(HaveOccurred())
    96  		})
    97  
    98  		It("list all billing groups", func() {
    99  			list, err := client.BillingGroup.ListAll()
   100  			Expect(err).NotTo(HaveOccurred())
   101  			Expect(list).NotTo(BeEmpty())
   102  		})
   103  
   104  		It("create billing group by copy from an existing one", func() {
   105  			billingGName = "copy-from-" + billingG.BillingGroupName
   106  			copiedBG, err = client.BillingGroup.Create(BillingGroupRequest{
   107  				BillingGroupName:     billingGName,
   108  				CopyFromBillingGroup: ToStringPointer(billingG.Id),
   109  			})
   110  			Expect(err).NotTo(HaveOccurred())
   111  			Expect(copiedBG.Id).NotTo(BeNil())
   112  			Expect(copiedBG.Id).NotTo(Equal(billingG.Id))
   113  			Expect(copiedBG.Company).To(Equal(billingG.Company))
   114  			Expect(copiedBG.AddressLines).To(Equal(billingG.AddressLines))
   115  			Expect(copiedBG.CountryCode).To(Equal(billingG.CountryCode))
   116  			Expect(copiedBG.City).To(Equal(billingG.City))
   117  			Expect(copiedBG.ZipCode).To(Equal(billingG.ZipCode))
   118  			Expect(copiedBG.BillingCurrency).To(Equal(billingG.BillingCurrency))
   119  		})
   120  	})
   121  
   122  	AfterEach(func() {
   123  		err = client.BillingGroup.Delete(billingG.Id)
   124  		if err != nil {
   125  			Fail("cannot delete billing group : " + err.Error())
   126  		}
   127  	})
   128  })