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.") } }