Skip to content

Commit 18fe50d

Browse files
allmightyspiffGitHub Enterprise
authored andcommitted
Merge pull request #909 from SoftLayer/issues904
#904 added notes to invoice details listing
2 parents f801c10 + d479617 commit 18fe50d

File tree

3 files changed

+73
-16
lines changed

3 files changed

+73
-16
lines changed

plugin/commands/account/invoice-detail.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (cmd *InvoiceDetailCommand) Run(args []string) error {
5252

5353
mask := `mask[id, description, hostName, domainName, oneTimeAfterTaxAmount, recurringAfterTaxAmount, ` +
5454
`createDate,categoryCode,category[name],location[name],children[id, category[name], description, ` +
55-
`oneTimeAfterTaxAmount, recurringAfterTaxAmount]]`
55+
`oneTimeAfterTaxAmount, recurringAfterTaxAmount], notes]`
5656
invoice, err := cmd.AccountManager.GetInvoiceDetail(invoiceID, mask)
5757
if err != nil {
5858
subs := map[string]interface{}{"invoiceID": invoiceID}
@@ -79,8 +79,11 @@ func PrintInvoiceDetail(invoiceID int, invoice []datatypes.Billing_Invoice_Item,
7979
}
8080
fqdn := fmt.Sprintf("%s.%s", utils.FormatStringPointerName(invoiceDetail.HostName), utils.FormatStringPointerName(invoiceDetail.DomainName))
8181
Description := utils.FormatStringPointer(invoiceDetail.Description)
82+
Notes := utils.FormatStringPointer(invoiceDetail.Notes)
8283
if fqdn != "." {
8384
Description = fmt.Sprintf("%s (%s)", Description, fqdn)
85+
} else if Notes != "-" {
86+
Description = fmt.Sprintf("%s (%s)", Description, Notes)
8487
}
8588
location := "None"
8689
if invoiceDetail.Location != nil {

plugin/commands/account/invoice-detail_test.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package account_test
22

33
import (
4+
"strings"
5+
"fmt"
46
"github.com/IBM-Cloud/ibm-cloud-cli-sdk/testhelpers/terminal"
57
. "github.com/onsi/ginkgo/v2"
68
. "github.com/onsi/gomega"
@@ -55,25 +57,24 @@ var _ = Describe("Account list InvoiceDetail", func() {
5557
It("return account invoice detail", func() {
5658
err := testhelpers.RunCobraCommand(cliCommand.Command, "123")
5759
Expect(err).NotTo(HaveOccurred())
58-
Expect(fakeUI.Outputs()).To(ContainSubstring("Item Id Category Description Single Monthly Create Date Location"))
59-
Expect(fakeUI.Outputs()).To(ContainSubstring("123456789 Server Dual Intel Xeon Silver 4210 (20 Cores, 2.20 GHz) (test-gpu.softlayer-community-f... 22.59 35.26 2022-04-04 mex01"))
60-
Expect(fakeUI.Outputs()).To(ContainSubstring("123456789123 server Dual E5-2690 v3 (12 Cores, 2.60 GHz) (test-vs.support2.com) 23.81 36.04 2022-04-04 ams01"))
60+
Expect(fakeUI.Outputs()).To(ContainSubstring("Item Id Category Description Single Monthly Create Date Location"))
61+
Expect(fakeUI.Outputs()).To(ContainSubstring("123456789 Server Dual Intel Xeon Silver 4210 (20 Cores, 2.20 GHz) (test-gpu.softlayer-community-f... 22.59 35.26 2022-04-04 mex01"))
62+
Expect(fakeUI.Outputs()).To(ContainSubstring("123456789123 server Dual E5-2690 v3 (12 Cores, 2.60 GHz) (test-vs.support2.com) 23.81 36.04 2022-04-04 ams01"))
63+
Expect(fakeUI.Outputs()).To(ContainSubstring("1531470246 Endurance Endurance Storage (SL-1234566789) 0.00 0.00 2020-05-04 ams01"))
6164
})
6265
It("return account invoice detail with additionals details", func() {
6366
err := testhelpers.RunCobraCommand(cliCommand.Command, "123", "--details")
6467
Expect(err).NotTo(HaveOccurred())
65-
Expect(fakeUI.Outputs()).To(Equal(
66-
`Item Id Category Description Single Monthly Create Date Location
67-
123456789 Server Dual Intel Xeon Silver 4210 (20 Cores, 2.20 GHz) (test-gpu.softlayer-community-f... 22.59 35.26 2022-04-04 mex01
68-
>>> Server Dual Intel Xeon Silver 4210 (20 Cores, 2.20 GHz) (test-gpu.softlayer-community-f... 10.23 20.34 --- ---
69-
>>> Second Processor Intel Xeon (12 Cores, 2.40 GHz) 5.24 6.12 --- ---
70-
>>> Operating System Virtual (up to 1Gbps) 7.12 8.79 --- ---
71-
123456789123 server Dual E5-2690 v3 (12 Cores, 2.60 GHz) (test-vs.support2.com) 23.81 36.04 2022-04-04 ams01
72-
>>> server Dual E5-2690 v3 (12 Cores, 2.60 GHz) (test-vs.support2.com) 11.23 21.12 --- ---
73-
>>> Second Processor Intel Xeon (12 Cores, 2.40 GHz) 5.35 6.23 --- ---
74-
>>> Operating System Virtual (up to 1Gbps) 7.23 8.68 --- ---
75-
`))
76-
})
68+
// Unsure if removing whitespace from the output makes it easier or harder to test. Looks ugly here, but
69+
// at least it won't break if formatting slightly changes.
70+
output := strings.Split(strings.ReplaceAll(fakeUI.Outputs(), " ", ""), "\n")
71+
fmt.Printf(fakeUI.Outputs())
72+
Expect(output[1]).To(Equal(`123456789ServerDualIntelXeonSilver4210(20Cores,2.20GHz)(test-gpu.softlayer-community-f...22.5935.262022-04-04mex01`))
73+
Expect(output[2]).To(Equal(`>>>ServerDualIntelXeonSilver4210(20Cores,2.20GHz)(test-gpu.softlayer-community-f...10.2320.34------`))
74+
Expect(output[3]).To(Equal(`>>>SecondProcessorIntelXeon(12Cores,2.40GHz)5.246.12------`))
75+
// https://github.ibm.com/SoftLayer/softlayer-cli/issues/904
76+
Expect(output[9]).To(Equal(`1531470246EnduranceEnduranceStorage(SL-1234566789)0.000.002020-05-04ams01`))
77+
})
7778
It("return account invoice detail in format json", func() {
7879
err := testhelpers.RunCobraCommand(cliCommand.Command, "123", "--output", "json")
7980
Expect(err).NotTo(HaveOccurred())

plugin/testfixtures/SoftLayer_Billing_Invoice/getInvoiceTopLevelItems.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,58 @@
7070
"location": {
7171
"name": "ams01"
7272
}
73+
},
74+
{
75+
"category": {
76+
"name": "Endurance"
77+
},
78+
"categoryCode": "storage_service_enterprise",
79+
"children": [
80+
{
81+
"category": {
82+
"name": "Block Storage"
83+
},
84+
"description": "Block Storage",
85+
"id": 1531470258,
86+
"oneTimeAfterTaxAmount": "0",
87+
"recurringAfterTaxAmount": "0"
88+
},
89+
{
90+
"category": {
91+
"name": "Storage Tier Level"
92+
},
93+
"description": "0.25 IOPS per GB",
94+
"id": 1531470268,
95+
"oneTimeAfterTaxAmount": "0",
96+
"recurringAfterTaxAmount": "0"
97+
},
98+
{
99+
"category": {
100+
"name": "Storage Space"
101+
},
102+
"description": "20 GB Storage Space",
103+
"id": 1531470274,
104+
"oneTimeAfterTaxAmount": "0",
105+
"recurringAfterTaxAmount": "0"
106+
},
107+
{
108+
"category": {
109+
"name": "Storage Snapshot Space"
110+
},
111+
"description": "10 GB Storage Space (Snapshot Space)",
112+
"id": 1531470282,
113+
"oneTimeAfterTaxAmount": "0",
114+
"recurringAfterTaxAmount": "0"
115+
}
116+
],
117+
"createDate": "2020-05-03T23:11:25-06:00",
118+
"description": "Endurance Storage",
119+
"id": 1531470246,
120+
"location": {
121+
"name": "ams01"
122+
},
123+
"oneTimeAfterTaxAmount": "0",
124+
"recurringAfterTaxAmount": "0",
125+
"notes": "SL-1234566789"
73126
}
74127
]

0 commit comments

Comments
 (0)