Skip to content

Commit

Permalink
Merge 71b5d56 into 3657b8e
Browse files Browse the repository at this point in the history
  • Loading branch information
brunomvsouza committed Jul 31, 2018
2 parents 3657b8e + 71b5d56 commit 3a21cf9
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 32 deletions.
21 changes: 17 additions & 4 deletions api/category/entity.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package category // import "go.bmvs.io/ynab/api/category"
import "go.bmvs.io/ynab/api"

// Category represents a category for a budget
type Category struct {
Expand All @@ -19,14 +20,26 @@ type Category struct {
// OriginalCategoryGroupID If category is hidden this is the ID of the category
// group it originally belonged to before it was hidden
OriginalCategoryGroupID *string `json:"original_category_group_id"`

GoalType *Goal `json:"goal_type"`
// GoalCreationMonth the month a goal was created
GoalCreationMonth *api.Date `json:"goal_creation_month"`
// GoalTarget the goal target amount in milliunits
GoalTarget *int64 `json:"goal_target"`
// GoalTargetMonth if the goal type is GoalTargetCategoryBalanceByDate,
// this is the target month for the goal to be completed
GoalTargetMonth *api.Date `json:"goal_target_month"`
// GoalPercentageComplete the percentage completion of the goal
GoalPercentageComplete *uint8 `json:"goal_percentage_complete"`
}

// Group represents a resumed category group for a budget
type Group struct {
ID string `json:"id"`
Name string `json:"name"`
Hidden bool `json:"hidden"`
Deleted bool `json:"deleted"`
ID string `json:"id"`
Name string `json:"name"`
Hidden bool `json:"hidden"`
// Deleted Deleted category groups will only be included in delta requests
Deleted bool `json:"deleted"`
}

// GroupWithCategories represents a category group for a budget
Expand Down
18 changes: 18 additions & 0 deletions api/category/enum.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package category

// Goal represents the goal of a category
type Goal string

// Pointer returns the pointer of a Goal
func (g Goal) Pointer() *Goal {
return &g
}

const (
// GoalTargetCategoryBalance Goal targets category balance
GoalTargetCategoryBalance Goal = "TB"
// GoalTargetCategoryBalanceByDate Goal targets category balance by date
GoalTargetCategoryBalanceByDate Goal = "TBD"
// GoalMonthlyFunding Goal by monthly funding
GoalMonthlyFunding Goal = "MF"
)
75 changes: 57 additions & 18 deletions api/category/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"gopkg.in/jarcoal/httpmock.v1"

"go.bmvs.io/ynab"
"go.bmvs.io/ynab/api"
"go.bmvs.io/ynab/api/category"
)

Expand Down Expand Up @@ -37,7 +38,12 @@ func TestService_GetCategories(t *testing.T) {
"budgeted": 0,
"activity": 12190,
"balance": 18740,
"deleted": false
"deleted": false,
"goal_type": "TB",
"goal_creation_month": "2018-04-01",
"goal_target": 18740,
"goal_target_month": "2018-05-01",
"goal_percentage_complete": 20
}
]
}
Expand All @@ -54,21 +60,35 @@ func TestService_GetCategories(t *testing.T) {
groups, err := client.Category().GetCategories("aa248caa-eed7-4575-a990-717386438d2c")
assert.NoError(t, err)

var (
expectedGoalTarget int64 = 18740
expectedGoalPercentageComplete uint8 = 20
)
expectedGoalCreationMonth, err := api.DateFromString("2018-04-01")
assert.NoError(t, err)
expectedGoalTargetMonth, err := api.DateFromString("2018-05-01")
assert.NoError(t, err)

expected := &category.GroupWithCategories{
ID: "13419c12-78d3-4818-a5dc-601b2b8a6064",
Name: "Credit Card Payments",
Hidden: false,
Deleted: false,
Categories: []*category.Category{
{
ID: "13419c12-78d3-4a26-82ca-1cde7aa1d6f8",
CategoryGroupID: "13419c12-78d3-4818-a5dc-601b2b8a6064",
Name: "MasterCard",
Hidden: false,
Budgeted: int64(0),
Activity: int64(12190),
Balance: int64(18740),
Deleted: false,
ID: "13419c12-78d3-4a26-82ca-1cde7aa1d6f8",
CategoryGroupID: "13419c12-78d3-4818-a5dc-601b2b8a6064",
Name: "MasterCard",
Hidden: false,
Budgeted: int64(0),
Activity: int64(12190),
Balance: int64(18740),
Deleted: false,
GoalType: category.GoalTargetCategoryBalance.Pointer(),
GoalCreationMonth: &expectedGoalCreationMonth,
GoalTargetMonth: &expectedGoalTargetMonth,
GoalTarget: &expectedGoalTarget,
GoalPercentageComplete: &expectedGoalPercentageComplete,
},
},
}
Expand All @@ -95,7 +115,12 @@ func TestService_GetCategory(t *testing.T) {
"budgeted": 0,
"activity": 12190,
"balance": 18740,
"deleted": false
"deleted": false,
"goal_type": "TB",
"goal_creation_month": "2018-04-01",
"goal_target": 18740,
"goal_target_month": "2018-05-01",
"goal_percentage_complete": 20
}
}
}
Expand All @@ -112,15 +137,29 @@ func TestService_GetCategory(t *testing.T) {
)
assert.NoError(t, err)

var (
expectedGoalTarget int64 = 18740
expectedGoalPercentageComplete uint8 = 20
)
expectedGoalCreationMonth, err := api.DateFromString("2018-04-01")
assert.NoError(t, err)
expectedGoalTargetMonth, err := api.DateFromString("2018-05-01")
assert.NoError(t, err)

expected := &category.Category{
ID: "13419c12-78d3-4a26-82ca-1cde7aa1d6f8",
CategoryGroupID: "13419c12-78d3-4818-a5dc-601b2b8a6064",
Name: "MasterCard",
Hidden: false,
Budgeted: int64(0),
Activity: int64(12190),
Balance: int64(18740),
Deleted: false,
ID: "13419c12-78d3-4a26-82ca-1cde7aa1d6f8",
CategoryGroupID: "13419c12-78d3-4818-a5dc-601b2b8a6064",
Name: "MasterCard",
Hidden: false,
Budgeted: int64(0),
Activity: int64(12190),
Balance: int64(18740),
Deleted: false,
GoalType: category.GoalTargetCategoryBalance.Pointer(),
GoalCreationMonth: &expectedGoalCreationMonth,
GoalTargetMonth: &expectedGoalTargetMonth,
GoalTarget: &expectedGoalTarget,
GoalPercentageComplete: &expectedGoalPercentageComplete,
}
assert.Equal(t, expected, c)
}
18 changes: 18 additions & 0 deletions api/month/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ type Month struct {
Note *string `json:"note"`
ToBeBudgeted *int64 `json:"to_be_budgeted"`
AgeOfMoney *int64 `json:"age_of_money"`

// Income the total amount in transactions categorized to "Inflow: To be Budgeted"
// in the month (milliunits format)
Income *int64 `json:"income"`
// Budgeted the total amount budgeted in the month (milliunits format)
Budgeted *int64 `json:"budgeted"`
// Activity the total amount in transactions in the month, excluding those
// categorized to "Inflow: To be Budgeted" (milliunits format)
Activity *int64 `json:"activity"`
}

// Summary represents the summary of a month for a budget
Expand All @@ -28,4 +37,13 @@ type Summary struct {
Note *string `json:"note"`
ToBeBudgeted *int64 `json:"to_be_budgeted"`
AgeOfMoney *int64 `json:"age_of_money"`

// Income the total amount in transactions categorized to "Inflow: To be Budgeted"
// in the month (milliunits format)
Income *int64 `json:"income"`
// Budgeted the total amount budgeted in the month (milliunits format)
Budgeted *int64 `json:"budgeted"`
// Activity the total amount in transactions in the month, excluding those
// categorized to "Inflow: To be Budgeted" (milliunits format)
Activity *int64 `json:"activity"`
}
22 changes: 20 additions & 2 deletions api/month/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ func TestService_GetMonths(t *testing.T) {
"month": "2017-10-01",
"note": null,
"to_be_budgeted": 0,
"age_of_money": 14
"age_of_money": 14,
"income": 3077330,
"budgeted": 3271990,
"activity": -3128590
}
]
}
Expand All @@ -45,10 +48,16 @@ func TestService_GetMonths(t *testing.T) {
var (
expectedAgeOfMoney int64 = 14
expectedToBeBudgeted int64
expectedIncome int64 = 3077330
expectedBudgeted int64 = 3271990
expectedActivity int64 = -3128590
)
assert.Equal(t, "2017-10-01 00:00:00 +0000 UTC", m.Month.String())
assert.Equal(t, &expectedToBeBudgeted, m.ToBeBudgeted)
assert.Equal(t, &expectedAgeOfMoney, m.AgeOfMoney)
assert.Equal(t, &expectedIncome, m.Income)
assert.Equal(t, &expectedBudgeted, m.Budgeted)
assert.Equal(t, &expectedActivity, m.Activity)
assert.Nil(t, m.Note)
}

Expand All @@ -65,7 +74,10 @@ func TestService_GetMonth(t *testing.T) {
"month": "2017-10-01",
"note": null,
"to_be_budgeted": 0,
"age_of_money": 14
"age_of_money": 14,
"income": 3077330,
"budgeted": 3271990,
"activity": -3128590
}
}
}
Expand All @@ -85,9 +97,15 @@ func TestService_GetMonth(t *testing.T) {
var (
expectedAgeOfMoney int64 = 14
expectedToBeBudgeted int64
expectedIncome int64 = 3077330
expectedBudgeted int64 = 3271990
expectedActivity int64 = -3128590
)
assert.Equal(t, "2017-10-01 00:00:00 +0000 UTC", m.Month.String())
assert.Equal(t, &expectedToBeBudgeted, m.ToBeBudgeted)
assert.Equal(t, &expectedAgeOfMoney, m.AgeOfMoney)
assert.Equal(t, &expectedIncome, m.Income)
assert.Equal(t, &expectedBudgeted, m.Budgeted)
assert.Equal(t, &expectedActivity, m.Activity)
assert.Nil(t, m.Note)
}
16 changes: 8 additions & 8 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,63 +12,63 @@ func ExampleNewClient() {
c.User().GetUser()
}

func ExampleClient_User() {
func ExampleClientServicer_User() {
c := ynab.NewClient("<valid_ynab_access_token>")
s := c.User()
fmt.Println(reflect.TypeOf(s))

// Output: *user.Service
}

func ExampleClient_Account() {
func ExampleClientServicer_Account() {
c := ynab.NewClient("<valid_ynab_access_token>")
s := c.Account()
fmt.Println(reflect.TypeOf(s))

// Output: *account.Service
}

func ExampleClient_Budget() {
func ExampleClientServicer_Budget() {
c := ynab.NewClient("<valid_ynab_access_token>")
s := c.Budget()
fmt.Println(reflect.TypeOf(s))

// Output: *budget.Service
}

func ExampleClient_Category() {
func ExampleClientServicer_Category() {
c := ynab.NewClient("<valid_ynab_access_token>")
s := c.Category()
fmt.Println(reflect.TypeOf(s))

// Output: *category.Service
}

func ExampleClient_Month() {
func ExampleClientServicer_Month() {
c := ynab.NewClient("<valid_ynab_access_token>")
s := c.Month()
fmt.Println(reflect.TypeOf(s))

// Output: *month.Service
}

func ExampleClient_Payee() {
func ExampleClientServicer_Payee() {
c := ynab.NewClient("<valid_ynab_access_token>")
s := c.Payee()
fmt.Println(reflect.TypeOf(s))

// Output: *payee.Service
}

func ExampleClient_Transaction() {
func ExampleClientServicer_Transaction() {
c := ynab.NewClient("<valid_ynab_access_token>")
s := c.Transaction()
fmt.Println(reflect.TypeOf(s))

// Output: *transaction.Service
}

func ExampleClient_RateLimit() {
func ExampleClientServicer_RateLimit() {
c := ynab.NewClient("<valid_ynab_access_token>")
r := c.RateLimit()
fmt.Println(reflect.TypeOf(r))
Expand Down

0 comments on commit 3a21cf9

Please sign in to comment.