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