forked from vickxxx/appstore
-
Notifications
You must be signed in to change notification settings - Fork 3
/
finances_filters_test.go
59 lines (51 loc) · 2.05 KB
/
finances_filters_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package appstore
import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"testing"
"time"
)
type FinancesReportsFilterTestSuite struct {
suite.Suite
}
func (suite *FinancesReportsFilterTestSuite) TestIsValid() {
date, _ := time.Parse("2006-01-02", "2020-04-17")
filter := NewFinancesReportsFilter()
filter.SetReportDate(date).SetRegionCode("US")
assert.NoError(suite.T(), filter.IsValid())
assert.Equal(suite.T(), FinancesReportTypeFinancial, filter.ReportType)
}
func (suite *FinancesReportsFilterTestSuite) TestIsInvalidEmptyReportType() {
date, _ := time.Parse("2006-01-02", "2020-04-17")
filter := &FinancesReportsFilter{ReportDate: date, RegionCode: "US"}
err := filter.IsValid()
assert.Error(suite.T(), err)
assert.Equal(suite.T(), "FinancesReportsFilter.IsValid: ReportType is required", err.Error())
}
func (suite *FinancesReportsFilterTestSuite) TestIsInvalidEmptyRegionCode() {
date, _ := time.Parse("2006-01-02", "2020-04-17")
filter := &FinancesReportsFilter{ReportDate: date}
filter.TypeFinancial()
err := filter.IsValid()
assert.Error(suite.T(), err)
assert.Equal(suite.T(), "FinancesReportsFilter.IsValid: RegionCode is required", err.Error())
}
func (suite *FinancesReportsFilterTestSuite) TestIsInvalidEmptyReportDate() {
filter := &FinancesReportsFilter{RegionCode: "US"}
filter.TypeFinanceDetail()
err := filter.IsValid()
assert.Error(suite.T(), err)
assert.Equal(suite.T(), "FinancesReportsFilter.IsValid: ReportDate is required", err.Error())
}
func (suite *FinancesReportsFilterTestSuite) TestToQueryParamsMap() {
date, _ := time.Parse("2006-01-02", "2020-05-04")
filter := &FinancesReportsFilter{ReportDate: date, RegionCode: "US", ReportType: FinancesReportTypeFinancial}
qs := make(map[string]interface{})
qs["filter[reportDate]"] = "2020-05"
qs["filter[reportType]"] = string(FinancesReportTypeFinancial)
qs["filter[regionCode]"] = "US"
assert.Equal(suite.T(), qs, filter.toQueryParamsMap())
}
func TestFinancesReportsFilterTestSuite(t *testing.T) {
suite.Run(t, new(FinancesReportsFilterTestSuite))
}