Skip to content

Commit

Permalink
fix: mock out auth flow in test (#980)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettladley authored Jun 10, 2024
1 parent 7079479 commit aa99835
Showing 1 changed file with 1 addition and 41 deletions.
42 changes: 1 addition & 41 deletions backend/tests/api/helpers/auth.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package helpers

import (
"fmt"

"github.com/GenerateNU/sac/backend/database"
"github.com/GenerateNU/sac/backend/entities/models"
"github.com/gofiber/fiber/v2"
"github.com/google/uuid"
)

Expand All @@ -25,43 +21,7 @@ func (app *TestApp) Auth(role models.UserRole) {
}

func (app *TestApp) authSuper() {
superUser, superUserErr := database.SuperUser(app.Settings.SuperUser)
if superUserErr != nil {
panic(fmt.Sprintf("Failed to get super user: %v", superUserErr))
}

email := superUser.Email
password := app.Settings.SuperUser.Password

resp, err := app.Send(TestRequest{
Method: fiber.MethodPost,
Path: "/api/v1/auth/login",
Body: &map[string]interface{}{
"email": email,
"password": password.Expose(),
},
})
if err != nil {
panic(fmt.Sprintf("Failed to authenticate super user: %v", err))
}

var accessToken string
var refreshToken string

authHeader := resp.Header.Get("Authorization")
if authHeader != "" {
accessToken = authHeader[len("Bearer "):]
}

if accessToken == "" || refreshToken == "" {
panic("Failed to authenticate super user")
}

app.TestUser = &TestUser{
UUID: database.SuperUserUUID,
Email: email,
AccessToken: accessToken,
}
app.TestUser = nil
}

func (app *TestApp) authStudent() {
Expand Down

0 comments on commit aa99835

Please sign in to comment.