github.com/sacloud/iaas-api-go@v1.12.0/test/bill_op_test.go (about) 1 // Copyright 2022-2023 The sacloud/iaas-api-go Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package test 16 17 import ( 18 "context" 19 "testing" 20 21 "github.com/sacloud/iaas-api-go" 22 "github.com/sacloud/iaas-api-go/testutil" 23 "github.com/stretchr/testify/assert" 24 ) 25 26 func TestBillOp_ByContract(t *testing.T) { 27 t.Parallel() 28 29 client := iaas.NewBillOp(singletonAPICaller()) 30 31 // get account ID 32 authStatusOp := iaas.NewAuthStatusOp(singletonAPICaller()) 33 authStatus, err := authStatusOp.Read(context.Background()) 34 if !assert.NoError(t, err) { 35 return 36 } 37 38 // check current permission 39 if !authStatus.ExternalPermission.PermittedBill() { 40 t.Skip("current account is not permitted to viewing bills") 41 } 42 43 searched, err := client.ByContract(context.Background(), authStatus.AccountID) 44 if !assert.NoError(t, err) { 45 return 46 } 47 48 err = testutil.DoAsserts( 49 testutil.AssertTrueFunc(t, len(searched.Bills) > 0, "len(Bills)"), 50 testutil.AssertNotEmptyFunc(t, searched.Bills[0].ID, "Bill.ID"), 51 testutil.AssertNotEmptyFunc(t, searched.Bills[0].Date, "Bill.Date"), 52 testutil.AssertNotEmptyFunc(t, searched.Bills[0].MemberID, "Bill.MemberID"), 53 ) 54 assert.NoError(t, err) 55 56 // Details 57 details, err := client.Details(context.Background(), authStatus.MemberCode, searched.Bills[0].ID) 58 if !assert.NoError(t, err) { 59 return 60 } 61 err = testutil.DoAsserts( 62 testutil.AssertTrueFunc(t, len(details.BillDetails) > 0, "len(Bills)"), 63 testutil.AssertNotEmptyFunc(t, details.BillDetails[0].ServiceClassID, "BillDetails.ServiceClassID"), 64 ) 65 assert.NoError(t, err) 66 }