diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..93a727a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,26 @@ +name: CI + +on: + pull_request: + branches: [main] + push: + branches: [main] + +jobs: + test: + name: Run tests + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + cache: true + + - name: Download dependencies + run: go mod download + + - name: Run tests + run: go test ./test/... -v -count=1 diff --git a/handlers/admin_post.go b/handlers/admin_post.go index 99f6a56..3d0f266 100644 --- a/handlers/admin_post.go +++ b/handlers/admin_post.go @@ -113,7 +113,7 @@ func (h* AdminHandler) GetAEPosts (c *gin.Context) { if strings.Contains(string(admin.Position), "Civil") { postType = "Civil" } else { - postType = "Electical" + postType = "Electrical" } var facultyPosts []models.FacultyPost @@ -188,7 +188,7 @@ func (h* AdminHandler) GetJEPosts (c *gin.Context) { if strings.Contains(string(admin.Position), "Civil") { postType = "Civil" } else { - postType = "Electical" + postType = "Electrical" } var facultyPosts []models.FacultyPost diff --git a/handlers/centrehead_auth.go b/handlers/centrehead_auth.go index b8e83c6..671a827 100644 --- a/handlers/centrehead_auth.go +++ b/handlers/centrehead_auth.go @@ -16,7 +16,7 @@ import ( // CentreHeadSignup registers the head of adminstrations. // On success, sends a verification email with a JWT token link. -func (h *AuthHandler) CentreHeadSignup (c *gin.Context) { +func (h *AuthHandler) CentreHeadSignup(c *gin.Context) { var inputs models.CentreHeadSignup if err := c.ShouldBindJSON(&inputs); err != nil { @@ -73,7 +73,7 @@ func (h *AuthHandler) CentreHeadSignup (c *gin.Context) { // CentreHeadLogin authenticates the head of administrations using email and password. // On success, signs a JWT and stores it in an httpOnly cookie. -func (h *AuthHandler) CentreHeadLogin (c *gin.Context) { +func (h *AuthHandler) CentreHeadLogin(c *gin.Context) { var inputs models.CentreHeadLogin if err := c.ShouldBindJSON(&inputs); err != nil { @@ -88,7 +88,7 @@ func (h *AuthHandler) CentreHeadLogin (c *gin.Context) { c.JSON(404, gin.H{"error": "user not found"}) return } - c.JSON(404, gin.H{"error": "internal server error"}) + c.JSON(500, gin.H{"error": "internal server error"}) return } @@ -99,7 +99,7 @@ func (h *AuthHandler) CentreHeadLogin (c *gin.Context) { err := bcrypt.CompareHashAndPassword([]byte(head.Password), []byte(inputs.Password)) if err != nil { - c.JSON(403, gin.H{"error": "incorrect password"}) + c.JSON(401, gin.H{"error": "incorrect password"}) return } diff --git a/services/email.go b/services/email.go index ae4a6a6..761f63a 100644 --- a/services/email.go +++ b/services/email.go @@ -103,7 +103,7 @@ func SendPasswordResetMail(userID uint, email, role string) error { err = SendMail(email, "Reset cms account password", mail) if err != nil { - return nil + return err } log.Printf("Password reset link sent to %s", email) return nil diff --git a/test/centrehead_auth_test.go b/test/centrehead_auth_test.go index a6aac94..e9808bd 100644 --- a/test/centrehead_auth_test.go +++ b/test/centrehead_auth_test.go @@ -93,7 +93,7 @@ func TestCentreHeadLogin_WrongPassword(t *testing.T) { "email": ch.Email, "password": "nope", }) - assertStatus(t, rec, 403) + assertStatus(t, rec, 401) } // --- CentreHeadForgetPassword -----------------------------------------------