From 5d292b2a31afa1bae196cfe2adff7dffc16929c5 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Wed, 9 Feb 2022 21:57:50 +0000 Subject: [PATCH] Add first test --- http/account_test.go | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 http/account_test.go diff --git a/http/account_test.go b/http/account_test.go new file mode 100644 index 0000000..0069268 --- /dev/null +++ b/http/account_test.go @@ -0,0 +1,46 @@ +package http + +import ( + "encoding/json" + "net/http" + "net/http/httptest" + "testing" + + "git.javil.eu/jacob1123/budgeteer/bcrypt" + "git.javil.eu/jacob1123/budgeteer/jwt" + "git.javil.eu/jacob1123/budgeteer/postgres" + "github.com/gin-gonic/gin" +) + +func TestListTimezonesHandler(t *testing.T) { + db, err := postgres.Connect("postgres://budgeteer_test:budgeteer_test@localhost:5432/budgeteer_test") + if err != nil { + t.Errorf("could not connect to db: %s", err) + return + } + + h := Handler{ + Service: db, + TokenVerifier: &jwt.TokenVerifier{}, + CredentialsVerifier: &bcrypt.Verifier{}, + } + + rr := httptest.NewRecorder() + c, engine := gin.CreateTestContext(rr) + h.LoadRoutes(engine) + + c.Request, err = http.NewRequest(http.MethodGet, "/account/accountid/transactions", nil) + if rr.Code != http.StatusOK { + t.Errorf("handler returned wrong status code: got %v want %v", rr.Code, http.StatusOK) + } + + var response TransactionsResponse + err = json.NewDecoder(rr.Body).Decode(&response) + if err != nil { + t.Error(err.Error()) + t.Error("Error retreiving list of transactions.") + } + if len(response.Transactions) == 0 { + t.Error("Did not get any transactions.") + } +}