Skip to content

Commit

Permalink
Merge pull request #46 from becoded/test-invoice
Browse files Browse the repository at this point in the history
Add tests for invoices
  • Loading branch information
becoded authored Oct 29, 2023
2 parents a5643a5 + 15ddef7 commit e04f095
Show file tree
Hide file tree
Showing 24 changed files with 1,467 additions and 6 deletions.
8 changes: 6 additions & 2 deletions harvest/date.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Date struct {
time.Time
}

func (t Date) String() string {
func (t *Date) String() string {
return t.Time.Format("2006-01-02")
}

Expand All @@ -30,13 +30,17 @@ func (t *Date) UnmarshalJSON(data []byte) (err error) {
return nil
}

func (t *Date) MarshalJSON() ([]byte, error) {
return []byte(t.Time.Format("\"2006-01-02\"")), nil
}

func (t *Date) EncodeValues(key string, v *url.Values) error {
v.Add(key, t.String())

return nil
}

// Equal reports whether t and u are equal based on time.Equal.
func (t Date) Equal(u Date) bool {
func (t *Date) Equal(u Date) bool {
return t.Time.Equal(u.Time)
}
16 changes: 15 additions & 1 deletion harvest/invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ type Invoice struct {
Notes *string `json:"notes,omitempty"`
// The currency code associated with this invoice.
Currency *string `json:"currency,omitempty"`
// The current state of the invoice: draft, open, paid, or closed.
State *string `json:"state,omitempty"`
// Start of the period during which time entries and expenses were added to this invoice.
PeriodStart *Date `json:"period_start,omitempty"`
// End of the period during which time entries and expenses were added to this invoice.
Expand All @@ -62,6 +64,10 @@ type Invoice struct {
IssueDate *Date `json:"issue_date,omitempty"`
// Date the invoice is due.
DueDate *Date `json:"due_date,omitempty"`
// The timeframe in which the invoice should be paid. Options: upon receipt, net 15, net 30, net 45, net 60, or custom.
PaymentTerm *string `json:"payment_term,omitempty"`
// The list of payment options enabled for the invoice. Options: [ach, credit_card, paypal]
PaymentOptions *[]string `json:"payment_options,omitempty"`
// Date and time the invoice was sent.
SentAt *time.Time `json:"sent_at,omitempty"`
// Date and time the invoice was paid.
Expand Down Expand Up @@ -150,10 +156,18 @@ type InvoiceCreateRequest struct {
IssueDate *Date `json:"issue_date,omitempty"`
// optional Date the invoice is due. Defaults to the issue_date.
DueDate *Date `json:"due_date,omitempty"`
// The timeframe in which the invoice should be paid. Defaults to custom.
// Options: upon receipt, net 15, net 30, net 45, net 60, or custom.
PaymentTerm *string `json:"payment_term,omitempty"`
// The payment options available to pay the invoice.
// Your account must be configured with the appropriate options under
// Settings > Integrations > Online payment to assign them.
// Options: [ach, credit_card, paypal]
PaymentOptions *[]string `json:"payment_options,omitempty"`
// optional Array of line item parameters
LineItems *[]InvoiceLineItemRequest `json:"line_items,omitempty"`
// optional An line items import object
LineItemsImport *[]InvoiceLineItemImportRequest `json:"line_items_import,omitempty"`
LineItemsImport *InvoiceLineItemImportRequest `json:"line_items_import,omitempty"`
}

type InvoiceLineItemRequest struct {
Expand Down
Loading

0 comments on commit e04f095

Please sign in to comment.