-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: adding tests for comments and refactoring responsibles
- Loading branch information
1 parent
e2e6a04
commit 851fc05
Showing
8 changed files
with
363 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
package api | ||
|
||
import "github.com/gin-gonic/gin" | ||
import ( | ||
"gcstatus/internal/resources" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
// Helper to respond with error | ||
func RespondWithError(c *gin.Context, statusCode int, message string) { | ||
c.JSON(statusCode, gin.H{"message": message}) | ||
c.JSON(statusCode, resources.Response{ | ||
Data: gin.H{"message": message}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package test_mocks | ||
|
||
import ( | ||
"gcstatus/internal/domain" | ||
"testing" | ||
|
||
"gorm.io/gorm" | ||
) | ||
|
||
func CreateDummyComment(t *testing.T, dbConn *gorm.DB, overrides *domain.Commentable) (*domain.Commentable, error) { | ||
|
||
defaultComment := domain.Commentable{ | ||
Comment: "Testing comment", | ||
CommentableID: 1, | ||
CommentableType: "games", | ||
} | ||
|
||
if overrides != nil { | ||
if overrides.Comment != "" { | ||
defaultComment.Comment = overrides.Comment | ||
} | ||
if overrides.CommentableID != 0 { | ||
defaultComment.CommentableID = overrides.CommentableID | ||
} | ||
if overrides.CommentableType != "" { | ||
defaultComment.CommentableType = overrides.CommentableType | ||
} | ||
if overrides.User.ID != 0 { | ||
defaultComment.User = overrides.User | ||
} else { | ||
user, err := CreateDummyUser(t, dbConn, &overrides.User) | ||
if err != nil { | ||
t.Fatalf("failed to create dummy user for comment: %+v", err) | ||
} | ||
|
||
defaultComment.User = *user | ||
} | ||
} | ||
|
||
if err := dbConn.Create(&defaultComment).Error; err != nil { | ||
return nil, err | ||
} | ||
|
||
return &defaultComment, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.