Skip to content
This repository was archived by the owner on Oct 31, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pkg/internal/myownsanity/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,16 @@ func SliceContains(slice []string, item string) bool {

return false
}

// StringPEqual will compare whether or not two string pointers are equal. If one or the other is nil then it will
// return false. Otherwise it will compare their values as strings not as pointers.
func StringPEqual(a, b *string) bool {
if a == nil && b != nil {
return false
}
if a != nil && b == nil {
return false
}

return *a == *b
}
22 changes: 22 additions & 0 deletions pkg/internal/myownsanity/strings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,25 @@ func TestSliceContains(t *testing.T) {
assert.True(t, SliceContains(data, "Item #1"), "should contain item #1")
assert.False(t, SliceContains(data, "Item #3"), "should contain item #3")
}

func TestStringPEqual(t *testing.T) {
{
var a, b string = "a", "b"
assert.False(t, StringPEqual(&a, &b), "should not be equal")
}

{
var a, b string = "a", "a"
assert.True(t, StringPEqual(&a, &b), "should be equal")
}

{
a := "a"
assert.False(t, StringPEqual(&a, nil), "should not be equal")
}

{
b := "b"
assert.False(t, StringPEqual(nil, &b), "should not be equal")
}
}
6 changes: 4 additions & 2 deletions pkg/internal/platypus/transaction.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package platypus

import (
"time"

"github.com/monetr/rest-api/pkg/util"
"github.com/pkg/errors"
"github.com/plaid/plaid-go/plaid"
"time"
)

type Transaction interface {
Expand Down Expand Up @@ -83,7 +85,7 @@ func (p PlaidTransaction) GetDate() time.Time {
}

func (p PlaidTransaction) GetDateLocal(timezone *time.Location) time.Time {
return p.Date.In(timezone)
return util.InLocal(p.Date, timezone)
}

func (p PlaidTransaction) GetISOCurrencyCode() string {
Expand Down
46 changes: 46 additions & 0 deletions pkg/internal/platypus/transaction_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package platypus

import (
"testing"
"time"

"github.com/brianvoe/gofakeit/v6"
"github.com/stretchr/testify/assert"
)

func TestPlaidTransaction_GetDates(t *testing.T) {
transaction := PlaidTransaction{
Amount: 128,
BankAccountId: gofakeit.Generate("?????"),
Category: []string{
"Bank Fee",
},
Date: time.Date(2021, 9, 16, 0, 0, 0, 0, time.UTC),
ISOCurrencyCode: "USD",
UnofficialCurrencyCode: "USD",
IsPending: false,
MerchantName: "Arby's",
Name: "Arby's",
OriginalDescription: "ARBYS",
PendingTransactionId: nil,
TransactionId: gofakeit.Generate("??????????"),
}

timezone, err := time.LoadLocation("America/Chicago")
assert.NoError(t, err, "must retrieve timezone")
assert.NotNil(t, timezone, "timezone cannot be nil")

t.Run("GetDate", func(t *testing.T) {
assert.Equal(t,
"2021-09-16T00:00:00Z", transaction.GetDate().Format(time.RFC3339Nano),
"should match value without transforming timezone",
)
})

t.Run("GetDateLocal", func(t *testing.T) {
assert.Equal(t,
"2021-09-16T00:00:00-05:00", transaction.GetDateLocal(timezone).Format(time.RFC3339Nano),
"should match value when transforming timezone",
)
})
}
7 changes: 4 additions & 3 deletions pkg/jobs/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package jobs

import (
"context"
"time"

"github.com/getsentry/sentry-go"
"github.com/monetr/rest-api/pkg/internal/myownsanity"
"github.com/monetr/rest-api/pkg/internal/platypus"
"github.com/monetr/rest-api/pkg/models"
"github.com/monetr/rest-api/pkg/repository"
"github.com/sirupsen/logrus"
"time"
)

func (j *jobManagerBase) upsertTransactions(
Expand Down Expand Up @@ -93,8 +95,7 @@ func (j *jobManagerBase) upsertTransactions(
shouldUpdate = true
}

// This won't work quite right, I need to compare the values, not the pointers.
if existingTransaction.PendingPlaidTransactionId != plaidTransaction.GetPendingTransactionId() {
if !myownsanity.StringPEqual(existingTransaction.PendingPlaidTransactionId, plaidTransaction.GetPendingTransactionId()) {
shouldUpdate = true
}

Expand Down