Skip to content

Commit

Permalink
Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefanos Papadakis committed Aug 28, 2022
1 parent 99eaa7c commit 2c96e63
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pkg/models/expense_classification_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package models

import (
"encoding/xml"
"testing"

"github.com/ppapapetrou76/go-testing/assert"
)

func TestExpensesClassificationType_MarshalXML(t *testing.T) {
t.Run("should have `ecls` namespace", func(t *testing.T) {
id := byte(1)
classification := ExpensesClassificationType{
ClassificationType: "type",
ClassificationCategory: "category",
Amount: 12,
ID: &id,
}

ft := assert.NewFluentT(t)

got, err := xml.Marshal(classification)
ft.AssertThat(err).IsNil()

want := []byte(`<ExpensesClassificationType><ecls:classificationType>type</ecls:classificationType><ecls:classificationCategory>category</ecls:classificationCategory><ecls:amount>12</ecls:amount><ecls:id>1</ecls:id></ExpensesClassificationType>`)
ft.AssertThat(got).IsEqualTo(want)
})
}
28 changes: 28 additions & 0 deletions pkg/models/income_classification_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package models

import (
"encoding/xml"
"testing"

"github.com/ppapapetrou76/go-testing/assert"
)

func TestIncomeClassificationType_MarshalXML(t *testing.T) {
t.Run("should have `icls` namespace", func(t *testing.T) {
id := byte(1)
classification := IncomeClassificationType{
ClassificationType: "type",
ClassificationCategory: "category",
Amount: 12,
ID: &id,
}

ft := assert.NewFluentT(t)

got, err := xml.Marshal(classification)
ft.AssertThat(err).IsNil()

want := []byte(`<IncomeClassificationType><icls:classificationType>type</icls:classificationType><icls:classificationCategory>category</icls:classificationCategory><icls:amount>12</icls:amount><icls:id>1</icls:id></IncomeClassificationType>`)
ft.AssertThat(got).IsEqualTo(want)
})
}
44 changes: 44 additions & 0 deletions pkg/mydata/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,36 @@ func runRequestTest(t *testing.T, client *Client, f func(mark string, nextPartit
ft.AssertThatStruct(docs.InvoicesDoc.Invoices[0]).IsEqualTo(expectedInvoice())
ft.AssertThatSlice(docs.InvoicesDoc.Invoices).HasSize(1).Contains(expectedInvoice())
})

t.Run("should include next partition and row key in the URL", func(t *testing.T) {
client.myDataClient.Client = httpmock.NewMockClient(
httpmock.NewMockResponse(&http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewBuffer(response)),
}, nil))

want := map[string][]string{
"mark": {"123"},
"nextPartitionKey": {"1"},
"nextRowKey": {"2"},
}

checkParameters := func(_ context.Context, req *http.Request) error {
values := req.URL.Query()
for k, got := range values {
ft.AssertThat(got).IsEqualTo(want[k])
}

return nil
}
client.myDataClient.RequestEditors = append(client.myDataClient.RequestEditors, checkParameters)

mark = "123"
nextPartitionKeyValue := "1"
nextRowKeyValue := "2"
_, err := f(mark, &nextPartitionKeyValue, &nextRowKeyValue)
ft.AssertThat(err).IsNil()
})
}

func expectedInvoice() models.Invoice {
Expand Down Expand Up @@ -384,6 +414,20 @@ func expectedInvoice() models.Invoice {
NetValue: 50.00,
VatCategory: 1,
VatAmount: 12,
IncomeClassification: []*models.IncomeClassificationType{
{
ClassificationType: "E3_561_001",
ClassificationCategory: "category1_2",
Amount: 15,
ID: nil,
},
{
ClassificationType: "E3_561_001",
ClassificationCategory: "category1_3",
Amount: 20,
ID: nil,
},
},
},
},
InvoiceSummary: &models.InvoiceSummary{
Expand Down
10 changes: 10 additions & 0 deletions pkg/mydata/testdata/request_response.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@
<vatCategory>1</vatCategory>
<vatAmount>12</vatAmount>
<lineComments>LineItems</lineComments>
<incomeClassification>
<icls:classificationType>E3_561_001</icls:classificationType>
<icls:classificationCategory>category1_2</icls:classificationCategory>
<icls:amount>15</icls:amount>
</incomeClassification>
<incomeClassification>
<icls:classificationType>E3_561_001</icls:classificationType>
<icls:classificationCategory>category1_3</icls:classificationCategory>
<icls:amount>20</icls:amount>
</incomeClassification>
</invoiceDetails>
<invoiceSummary>
<totalNetValue>50</totalNetValue>
Expand Down

0 comments on commit 2c96e63

Please sign in to comment.