Skip to content

Commit

Permalink
Checking if integration test work
Browse files Browse the repository at this point in the history
Signed-off-by: William <[email protected]>
  • Loading branch information
kwesidev committed Sep 22, 2023
1 parent 55bbd27 commit a581389
Showing 1 changed file with 44 additions and 18 deletions.
62 changes: 44 additions & 18 deletions internal/services/auth_service_test.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,51 @@
package services

import (
"database/sql"
"log"
"os"
"testing"

"github.com/kwesidev/authserver/internal/models"
"github.com/kwesidev/authserver/internal/utilities"
_ "github.com/lib/pq"
)

// func TestValidLogin(t *testing.T) {
// db, err := utilities.GetMainDatabaseConnection(utilities.DatabaseConfig{
// Host: "localhost",
// Userame: "postgres",
// Password: "root",
// Database: "apiauth",
// Port: "5432",
// })
// if err != nil {
// t.Error("Connection to database failed: ", err)
// return
// }
// authService := NewAuthService(db)
// _, err = authService.Login("jackie", "password", "", "")
var db *sql.DB

func setUp() {
var err error
db, err = utilities.GetMainDatabaseConnection(utilities.DatabaseConfig{
Host: os.Getenv("PG_HOST"),
Username: os.Getenv("PG_USER"),
Password: os.Getenv("PG_PASSWORD"),
Database: os.Getenv("PG_DB"),
Port: os.Getenv("PG_PORT"),
})
if err != nil {
log.Fatal("Failed to connect to database")
return
}
userService := NewUserService(db)
_, err = userService.Register(models.UserRegistrationRequest{
Username: "john.doe",
Password: "password_2030333",
EmailAddress: "johndoe@localhost",
FirstName: "john",
LastName: "doe",
CellNumber: "0731482947",
})

// if err != nil {
// t.Error("Failed to authenticate")
// }
// }
}
func TestMain(m *testing.M) {
setUp()
code := m.Run()
os.Exit(code)
}
func TestLogin(t *testing.T) {
authService := NewAuthService(db)
_, err := authService.Login("john.doe", "password_2030333", "", "")
if err != nil {
t.Error("Failed to authenticate")
}
}

0 comments on commit a581389

Please sign in to comment.