Skip to content
This repository has been archived by the owner on Oct 31, 2021. It is now read-only.

Commit

Permalink
Code review changes for Plaid V1.
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotcourant committed Sep 11, 2021
1 parent 6580f57 commit 73c2c5a
Show file tree
Hide file tree
Showing 19 changed files with 235 additions and 45 deletions.
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ require (
github.com/spf13/viper v1.8.1
github.com/stretchr/testify v1.7.0
github.com/stripe/stripe-go/v72 v72.64.1
github.com/swaggo/swag v1.7.1
github.com/teambition/rrule-go v1.7.2
github.com/vmihailenco/msgpack/v5 v5.3.4
github.com/xlzd/gotp v0.0.0-20181030022105-c8557ba2c119
Expand Down Expand Up @@ -83,7 +84,6 @@ require (
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/google/go-querystring v1.0.0 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
github.com/gorilla/css v1.0.0 // indirect
Expand Down Expand Up @@ -154,7 +154,6 @@ require (
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/mod v0.4.2 // indirect
golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420 // indirect
Expand Down
26 changes: 24 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3
github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/Joker/hpp v1.0.0 h1:65+iuJYdRXv/XyN62C1uEmmOx3432rNG/rKlX6V7Kkc=
github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKzY=
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
github.com/MicahParks/keyfunc v0.4.0 h1:+4Gj1EJXy09j6e+S+O9jNNdAOxc6Sra6KWCgbLSkL6E=
github.com/MicahParks/keyfunc v0.4.0/go.mod h1:zLNyBGSzTMF3hq4XLLsZsKvxKe0tqHYSfXoFmv9w9g4=
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
Expand All @@ -66,13 +68,18 @@ github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 h1:YoJbenK9C67SkzkDfmQuVln04ygHj3vjZfd9FL+GmQQ=
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo=
github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI=
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398 h1:WDC6ySpJzbxGWFh4aMxFFC28wwGp5pEuoTtvA4q/qQ4=
github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqRtAwp2Xwc6WNPJEufxJ7fx3npB4UV/JOLmbu5I0=
github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk=
github.com/acomagu/bufpipe v1.0.3/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4=
github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU=
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
Expand Down Expand Up @@ -148,6 +155,7 @@ github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -229,6 +237,16 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8=
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY=
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
github.com/go-openapi/jsonreference v0.19.5 h1:1WJP/wi4OjB4iV8KVbH73rQaoialJrqv8gitZLxGLtM=
github.com/go-openapi/jsonreference v0.19.5/go.mod h1:RdybgQwPxbL4UEjuAruzK1x3nE69AqPYEJeo/TWfEeg=
github.com/go-openapi/spec v0.20.3 h1:uH9RQ6vdyPSs2pSy9fL8QPspDF2AMIMPtmK5coSSjtQ=
github.com/go-openapi/spec v0.20.3/go.mod h1:gG4F8wdEDN+YPBMVnzE85Rbhf+Th2DTvA9nFPQ5AYEg=
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-openapi/swag v0.19.14 h1:gm3vOOXfiuw5i9p5N9xJvfjvuofpyvLA9Wr6QfK5Fng=
github.com/go-openapi/swag v0.19.14/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
github.com/go-pg/migrations/v8 v8.1.0 h1:bc1wQwFoWRKvLdluXCRFRkeaw9xDU4qJ63uCAagh66w=
github.com/go-pg/migrations/v8 v8.1.0/go.mod h1:o+CN1u572XHphEHZyK6tqyg2GDkRvL2bIoLNyGIewus=
github.com/go-pg/pg/v10 v10.4.0/go.mod h1:BfgPoQnD2wXNd986RYEHzikqv9iE875PrFaZ9vXvtNM=
Expand Down Expand Up @@ -428,6 +446,7 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
Expand Down Expand Up @@ -490,6 +509,8 @@ github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls=
github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
Expand Down Expand Up @@ -692,6 +713,8 @@ github.com/stripe/stripe-go/v72 v72.64.1 h1:LsT6QVC8xF4X/Kp8xsNYqvubE3vuXn4/dhOF
github.com/stripe/stripe-go/v72 v72.64.1/go.mod h1:QwqJQtduHubZht9mek5sds9CtQcKFdsykV9ZepRWwo0=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/swaggo/swag v1.7.1 h1:gY9ZakXlNWg/i/v5bQBic7VMZ4teq4m89lpiao74p/s=
github.com/swaggo/swag v1.7.1/go.mod h1:gAiHxNTb9cIpNmA/VEGUP+CyZMCP/EW7mdtc8Bny+p8=
github.com/tdewolff/minify/v2 v2.9.10 h1:p+ifTTl+JMFFLDYNAm7nxQ9XuCG10HTW00wlPAZ7aoE=
github.com/tdewolff/minify/v2 v2.9.10/go.mod h1:U1Nc+/YBSB0FPEarqcgkYH3Ep4DNyyIbOyl5P4eWMuo=
github.com/tdewolff/parse/v2 v2.5.5 h1:b7ICJa4I/54JQGEGgTte8DiyJPKcC5g8V773QMzkeUM=
Expand All @@ -710,6 +733,7 @@ github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVM
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
Expand Down Expand Up @@ -1151,8 +1175,6 @@ google.golang.org/genproto v0.0.0-20210402141018-6c239bbf2bb1/go.mod h1:9lPAdzaE
google.golang.org/genproto v0.0.0-20210429181445-86c259c2b4ab/go.mod h1:P3QM42oQyzQSnHPnZ/vqoCdDmzH28fzWByN9asMeM8A=
google.golang.org/genproto v0.0.0-20210517163617-5e0236093d7a/go.mod h1:P3QM42oQyzQSnHPnZ/vqoCdDmzH28fzWByN9asMeM8A=
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0=
google.golang.org/genproto v0.0.0-20210903162649-d08c68adba83 h1:3V2dxSZpz4zozWWUq36vUxXEKnSYitEH2LdsAx+RUmg=
google.golang.org/genproto v0.0.0-20210903162649-d08c68adba83/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY=
google.golang.org/genproto v0.0.0-20210909211513-a8c4777a87af h1:aLMMXFYqw01RA6XJim5uaN+afqNNjc9P8HPAbnpnc5s=
google.golang.org/genproto v0.0.0-20210909211513-a8c4777a87af/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY=
google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
Expand Down
4 changes: 4 additions & 0 deletions minikube/vault/auth.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ resource "vault_auth_backend" "userpass" {
type = "userpass"
}

// monetr-user is just a basic user-password authentication for the API. This is to be used when trying to debug
// permissions or trying to dignose issues outside of Kubernetes. As it is easier to provision access using a
// username and password than it is to try to use the Kubernetes authentication, outside kube.
// The user is "monetr", the password is "password".
resource "vault_generic_endpoint" "monetr-user" {
depends_on = [vault_auth_backend.userpass]
path = "auth/userpass/users/monetr"
Expand Down
5 changes: 4 additions & 1 deletion minikube/vault/rest-api-service.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
data "vault_policy_document" "rest-api-policy" {
// There are two rules here because I still have no idea what I'm doing when it comes to trying to provision this
// stuff. I'm getting permissions errors for both paths so this is likely to change in the future. But again this
// is only used for local development against vault.
rule {
path = "${vault_mount.plaid-client-secrets.path}/*"
capabilities = [
Expand Down Expand Up @@ -40,4 +43,4 @@ resource "vault_kubernetes_auth_backend_role" "rest-api" {
token_policies = [
vault_policy.rest-api-service-policy.name,
]
}
}
6 changes: 5 additions & 1 deletion pkg/config/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ type Plaid struct {

WebhooksEnabled bool
WebhooksDomain string
OAuthDomain string
// OAuthDomain is used to specify the domain name that the user will be brought to upon returning to monetr after
// authenticating to a bank that requires OAuth. This will typically be a UI domain name and should not include a
// protocol or a path. The protocol is auto inserted as `https` as it is the only protocol supported. The path is
// currently hard coded until a need for different paths arises?
OAuthDomain string
}

type CORS struct {
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/links.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package controller

import (
"fmt"
"net/http"
"strings"
"time"

"github.com/getsentry/sentry-go"
"github.com/kataras/iris/v12"
"github.com/monetr/rest-api/pkg/crumbs"
"github.com/monetr/rest-api/pkg/models"
"github.com/monetr/rest-api/pkg/swag"
"github.com/sirupsen/logrus"
"net/http"
"strings"
"time"
)

func (c *Controller) linksController(p iris.Party) {
Expand Down Expand Up @@ -271,7 +272,6 @@ func (c *Controller) deleteLink(ctx iris.Context) {

client, err := c.plaid.NewClient(c.getContext(ctx), link, accessToken)
if err != nil {
// ERROR THINGS
c.wrapAndReturnError(ctx, err, http.StatusInternalServerError, "failed to create plaid client")
return
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/controller/plaid.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package controller
import (
"context"
"fmt"
"net/http"
"strconv"
"time"

"github.com/getsentry/sentry-go"
"github.com/kataras/iris/v12"
"github.com/monetr/rest-api/pkg/crumbs"
Expand All @@ -11,9 +15,6 @@ import (
"github.com/monetr/rest-api/pkg/models"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"net/http"
"strconv"
"time"

"github.com/kataras/iris/v12/core/router"
)
Expand Down Expand Up @@ -428,10 +429,9 @@ func (c *Controller) plaidTokenCallback(ctx iris.Context) {
Mask: plaidAccount.GetMask(),
PlaidName: plaidAccount.GetName(),
PlaidOfficialName: plaidAccount.GetOfficialName(),
// THIS MIGHT BREAK SOMETHING.
//Type: models.BankAccountType(plaidAccount.Type),
//SubType: models.BankAccountSubType(plaidAccount.Subtype),
LastUpdated: now,
Type: models.BankAccountType(plaidAccount.GetType()),
SubType: models.BankAccountSubType(plaidAccount.GetSubType()),
LastUpdated: now,
}
}
if err = repo.CreateBankAccounts(c.getContext(ctx), accounts...); err != nil {
Expand Down
7 changes: 5 additions & 2 deletions pkg/internal/mock_http_helper/responder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package mock_http_helper

import (
"encoding/json"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
"io/ioutil"
"net/http"
"testing"

"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
)

func TestNewHttpMockJsonResponder(t *testing.T) {
Expand All @@ -25,6 +26,7 @@ func TestNewHttpMockJsonResponder(t *testing.T) {
response, err := http.Get(url)
assert.NoError(t, err, "http get request must succeed")
assert.Equal(t, http.StatusOK, response.StatusCode, "status code must be 200")
assert.Equal(t, "application/json", response.Header.Get("Content-Type"), "content type should always be json")

body, err := ioutil.ReadAll(response.Body)
assert.NoError(t, err, "must be able to read the response body")
Expand All @@ -36,4 +38,5 @@ func TestNewHttpMockJsonResponder(t *testing.T) {

assert.EqualValues(t, 123, result["value"], "value must match")
assert.Len(t, result, 1, "must only have one key")

}
13 changes: 7 additions & 6 deletions pkg/internal/mock_plaid/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ package mock_plaid
import (
"encoding/json"
"fmt"
"net/http"
"strings"
"testing"

"github.com/brianvoe/gofakeit/v6"
"github.com/monetr/rest-api/pkg/internal/mock_http_helper"
"github.com/monetr/rest-api/pkg/internal/myownsanity"
"github.com/monetr/rest-api/pkg/internal/testutils"
"github.com/plaid/plaid-go/plaid"
"github.com/stretchr/testify/require"
"net/http"
"strings"
"testing"
)

func BankAccountFixture(t *testing.T) plaid.AccountBase {
Expand Down Expand Up @@ -82,8 +83,8 @@ func MockGetAccountsExtended(t *testing.T, plaidData *testutils.MockPlaidData) {
func(t *testing.T, request *http.Request) (interface{}, int) {
accessToken := ValidatePlaidAuthentication(t, request, RequireAccessToken)
var getAccountsRequest struct {
Options struct {
AccountIds []string `json:"account_ids"`
Options struct {
AccountIds []string `json:"account_ids"`
} `json:"options"`
}
require.NoError(t, json.NewDecoder(request.Body).Decode(&getAccountsRequest), "must decode request")
Expand All @@ -99,7 +100,7 @@ func MockGetAccountsExtended(t *testing.T, plaidData *testutils.MockPlaidData) {
for _, accountId := range getAccountsRequest.Options.AccountIds {
account, ok := accounts[accountId]
if !ok {
panic("bad account id handling not yet implemented")
panic("bad account id handling not yet implemented")
}

response.Accounts = append(response.Accounts, account)
Expand Down
10 changes: 9 additions & 1 deletion pkg/internal/mock_plaid/accounts_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package mock_plaid

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestBankAccountFixture(t *testing.T) {
account := BankAccountFixture(t)
assert.NotEmpty(t, account, "account must not be empty")
assert.NotEmpty(t, account.GetAccountId(), "bank account ID must not be empty")

balances := account.GetBalances()
assert.NotEmpty(t, balances, "balances must not be empty")
assert.NotZero(t, balances.GetAvailable(), "available must not be zero")
assert.NotZero(t, balances.GetCurrent(), "available must not be zero")
assert.LessOrEqual(t, balances.GetAvailable(), balances.GetCurrent(), "available must always be less than or equal to current")
}
11 changes: 8 additions & 3 deletions pkg/internal/mock_plaid/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package mock_plaid

import (
"encoding/json"
"net/http"
"testing"
"time"

"github.com/brianvoe/gofakeit/v6"
"github.com/monetr/rest-api/pkg/internal/mock_http_helper"
"github.com/plaid/plaid-go/plaid"
"github.com/stretchr/testify/require"
"net/http"
"testing"
"time"
)

func MockCreateLinkToken(t *testing.T) {
Expand All @@ -22,6 +23,10 @@ func MockCreateLinkToken(t *testing.T) {
require.NotEmpty(t, createLinkTokenRequest.ClientName, "client name is required")
require.NotEmpty(t, createLinkTokenRequest.Language, "language is required")

if createLinkTokenRequest.AccessToken != nil {
require.Empty(t, createLinkTokenRequest.Products, "products array must be empty when updating a link")
}

return plaid.LinkTokenCreateResponse{
LinkToken: gofakeit.UUID(),
Expiration: time.Now().Add(30 * time.Second),
Expand Down
16 changes: 16 additions & 0 deletions pkg/internal/mock_plaid/plaid_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package mock_plaid

import (
"net/http"
"testing"

"github.com/stretchr/testify/assert"
)

func TestPlaidHeaders(t *testing.T) {
assert.NotPanics(t, func() {
headers := PlaidHeaders(t, nil, nil, http.StatusOK)
assert.NotEmpty(t, headers, "headers should not be empty")
assert.Contains(t, headers, "X-Request-Id", "should contain the X-Request-Id header")
}, "this method must not panic if we pass a nil request and response")
}
Loading

0 comments on commit 73c2c5a

Please sign in to comment.