Merge pull request #13 from GoncaloRodri/feature/unit-tests
test: unit tests — 70.3% coverage
This commit is contained in:
commit
722559519e
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"embed"
|
"embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -150,8 +151,37 @@ func render(w http.ResponseWriter, tmpl *template.Template, data interface{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type storeIface interface {
|
||||||
|
getAccounts(ctx context.Context, userID string) ([]Account, error)
|
||||||
|
getAccount(ctx context.Context, id string) (*Account, error)
|
||||||
|
createAccount(ctx context.Context, a *Account) error
|
||||||
|
deleteAccount(ctx context.Context, id, userID string) error
|
||||||
|
getCategories(ctx context.Context, userID string) ([]Category, error)
|
||||||
|
createCategory(ctx context.Context, c *Category) error
|
||||||
|
updateCategory(ctx context.Context, c *Category) error
|
||||||
|
deleteCategory(ctx context.Context, id, userID string) error
|
||||||
|
getTransactions(ctx context.Context, userID string, filter bson.M) ([]Transaction, error)
|
||||||
|
getTransaction(ctx context.Context, id, userID string) (*Transaction, error)
|
||||||
|
createTransactions(ctx context.Context, txns []Transaction) error
|
||||||
|
updateTransaction(ctx context.Context, id, userID string, update bson.M) error
|
||||||
|
deleteTransaction(ctx context.Context, id, userID string) error
|
||||||
|
aggregateTransactions(ctx context.Context, userID string, pipeline bson.A) ([]bson.M, error)
|
||||||
|
getTrades(ctx context.Context, userID string) ([]Trade, error)
|
||||||
|
createTrades(ctx context.Context, trades []Trade) error
|
||||||
|
deleteTrade(ctx context.Context, id, userID string) error
|
||||||
|
getPermissions(ctx context.Context, ownerID string) ([]Permission, error)
|
||||||
|
getGrantedViewers(ctx context.Context, viewerID string) ([]Permission, error)
|
||||||
|
createPermission(ctx context.Context, p *Permission) error
|
||||||
|
deletePermission(ctx context.Context, ownerID, viewerID string) error
|
||||||
|
getGoals(ctx context.Context, userID string) ([]Goal, error)
|
||||||
|
createGoal(ctx context.Context, g *Goal) error
|
||||||
|
updateGoal(ctx context.Context, id, userID string, update bson.M) error
|
||||||
|
deleteGoal(ctx context.Context, id, userID string) error
|
||||||
|
seedCategories(ctx context.Context, userID string) error
|
||||||
|
}
|
||||||
|
|
||||||
type Handler struct {
|
type Handler struct {
|
||||||
store *Store
|
store storeIface
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHandler(store *Store) *Handler {
|
func NewHandler(store *Store) *Handler {
|
||||||
|
|||||||
1605
apps/finance/services/api/main/handler_test.go
Normal file
1605
apps/finance/services/api/main/handler_test.go
Normal file
File diff suppressed because it is too large
Load Diff
@ -176,6 +176,27 @@ func TestTopMerchants(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTickerStoreResolve(t *testing.T) {
|
||||||
|
ts := &tickerStore{mappings: []TickerMapping{
|
||||||
|
{ISIN: "IE00B3WJKG14", Ticker: "VWCE.DE"},
|
||||||
|
{ISIN: "US0378331005", Ticker: "AAPL"},
|
||||||
|
}}
|
||||||
|
tests := []struct {
|
||||||
|
isin string
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{"IE00B3WJKG14", "VWCE.DE"},
|
||||||
|
{"US0378331005", "AAPL"},
|
||||||
|
{"XX0000000000", ""},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
got := ts.resolve(tt.isin)
|
||||||
|
if got != tt.want {
|
||||||
|
t.Errorf("resolve(%q) = %q, want %q", tt.isin, got, tt.want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestAutoCategorize(t *testing.T) {
|
func TestAutoCategorize(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
desc string
|
desc string
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user