add method for getting financial report

This commit is contained in:
diPhantxm
2023-03-16 20:00:56 +03:00
parent 2c95f2e4c2
commit 0a3eaddf22
3 changed files with 145 additions and 4 deletions

View File

@@ -89,9 +89,7 @@ func TestGetReportDetails(t *testing.T) {
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&GetReportDetailsParams{
},
&GetReportDetailsParams{},
`{
"result": {
"code": "257bf213-ca57-405c-8edf-41d2ce22decf",
@@ -129,3 +127,69 @@ func TestGetReportDetails(t *testing.T) {
}
}
}
func TestGetFinancial(t *testing.T) {
tests := []struct {
statusCode int
headers map[string]string
params *GetFinancialReportParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&GetFinancialReportParams{
Date: GetFinancialReportDatePeriod{
From: core.TimeFromString(t, "2006-01-02T15:04:05Z", "2022-01-01T00:00:00.000Z"),
To: core.TimeFromString(t, "2006-01-02T15:04:05Z", "2022-12-31T00:00:00.000Z"),
},
Page: 1,
PageSize: 1,
},
`{
"result": {
"cash_flows": [
{
"period": {
"id": 11567022278500,
"begin": "2022-08-01T00:00:00Z",
"end": "2022-08-15T00:00:00Z"
},
"orders_amount": 1000,
"returns_amount": -3000,
"commission_amount": 1437,
"services_amount": 8471.28,
"item_delivery_and_return_amount": 1991,
"currency_code": "RUB"
}
],
"page_count": 15
}
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&GetFinancialReportParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
}
for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.Reports().GetFinancial(test.params)
if err != nil {
t.Error(err)
}
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
}
}