@@ -16,7 +16,7 @@ import (
1616 "github.com/openmeterio/openmeter/pkg/timeutil"
1717)
1818
19- func TestMergeStandardLineFromInvoiceLineReplaceUpdatePreservesResolvedTaxCode (t * testing.T ) {
19+ func TestMergeStandardLineFromInvoiceLineReplaceUpdateOverwritesTaxConfig (t * testing.T ) {
2020 price := api.RateCardUsageBasedPrice {}
2121 require .NoError (t , price .FromUnitPriceWithCommitments (api.UnitPriceWithCommitments {
2222 Amount : "1" ,
@@ -84,8 +84,74 @@ func TestMergeStandardLineFromInvoiceLineReplaceUpdatePreservesResolvedTaxCode(t
8484 })
8585 require .NoError (t , err )
8686 require .NotNil (t , mergedLine .TaxConfig )
87- require .NotNil (t , mergedLine .TaxConfig .TaxCode )
88- require .Equal (t , taxCodeID , mergedLine .TaxConfig .TaxCode .ID )
87+ require .Equal (t , taxCodeID , * mergedLine .TaxConfig .TaxCodeID )
88+ require .Nil (t , mergedLine .TaxConfig .TaxCode )
89+ }
90+
91+ func TestMergeStandardLineFromInvoiceLineReplaceUpdateLeavesProviderDefaultOmissionForInvoiceNormalization (t * testing.T ) {
92+ period := invoiceLineTestPeriod ()
93+ line := standardInvoiceLineForMergeTest (t , period )
94+
95+ defaultTaxCodeID := "default-tax-code-id"
96+ productCatalogTaxBehavior := productcatalog .ExclusiveTaxBehavior
97+ line .TaxConfig = & billing.TaxConfig {
98+ TaxConfig : productcatalog.TaxConfig {
99+ Behavior : & productCatalogTaxBehavior ,
100+ TaxCodeID : & defaultTaxCodeID ,
101+ },
102+ TaxCode : & taxcode.TaxCode {
103+ NamespacedID : models.NamespacedID {
104+ Namespace : "ns" ,
105+ ID : defaultTaxCodeID ,
106+ },
107+ Name : "Default Tax Code" ,
108+ },
109+ }
110+
111+ taxBehavior := api .TaxBehaviorExclusive
112+ mergedLine , err := mergeStandardLineFromInvoiceLineReplaceUpdate (line , invoiceLineReplaceUpdateForMergeTest (t , period , line .UsageBased .FeatureKey , "1" , func (update * api.InvoiceLineReplaceUpdate ) {
113+ update .RateCard .TaxConfig = & api.TaxConfig {
114+ Behavior : & taxBehavior ,
115+ }
116+ update .TaxConfig = update .RateCard .TaxConfig
117+ }))
118+ require .NoError (t , err )
119+ require .NotNil (t , mergedLine .TaxConfig )
120+ require .Nil (t , mergedLine .TaxConfig .TaxCodeID )
121+ require .Nil (t , mergedLine .TaxConfig .TaxCode )
122+ }
123+
124+ func TestMergeStandardLineFromInvoiceLineReplaceUpdateDoesNotPreserveExplicitTaxCodeWhenPayloadOmitsTaxCodeIdentity (t * testing.T ) {
125+ period := invoiceLineTestPeriod ()
126+ line := standardInvoiceLineForMergeTest (t , period )
127+
128+ explicitTaxCodeID := "explicit-tax-code-id"
129+ productCatalogTaxBehavior := productcatalog .ExclusiveTaxBehavior
130+ line .TaxConfig = & billing.TaxConfig {
131+ TaxConfig : productcatalog.TaxConfig {
132+ Behavior : & productCatalogTaxBehavior ,
133+ TaxCodeID : & explicitTaxCodeID ,
134+ },
135+ TaxCode : & taxcode.TaxCode {
136+ NamespacedID : models.NamespacedID {
137+ Namespace : "ns" ,
138+ ID : explicitTaxCodeID ,
139+ },
140+ Name : "Explicit Tax Code" ,
141+ },
142+ }
143+
144+ taxBehavior := api .TaxBehaviorExclusive
145+ mergedLine , err := mergeStandardLineFromInvoiceLineReplaceUpdate (line , invoiceLineReplaceUpdateForMergeTest (t , period , line .UsageBased .FeatureKey , "1" , func (update * api.InvoiceLineReplaceUpdate ) {
146+ update .RateCard .TaxConfig = & api.TaxConfig {
147+ Behavior : & taxBehavior ,
148+ }
149+ update .TaxConfig = update .RateCard .TaxConfig
150+ }))
151+ require .NoError (t , err )
152+ require .NotNil (t , mergedLine .TaxConfig )
153+ require .Nil (t , mergedLine .TaxConfig .TaxCodeID )
154+ require .Nil (t , mergedLine .TaxConfig .TaxCode )
89155}
90156
91157func TestMergeStandardLineFromInvoiceLineReplaceUpdateDropsResolvedTaxCodeWhenTaxConfigChanges (t * testing.T ) {
0 commit comments