Skip to content

Commit

Permalink
chore: fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vinit717 committed Oct 4, 2024
1 parent 5a5b49b commit 8f58692
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions tests/integration/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ import (
func (suite *AppTestSuite) TestCreateTinyURLSuccess() {
// Setup the router and route for creating a tiny URL
router := gin.Default()

router.Use(func(ctx *gin.Context) {
ctx.Set("userID", int64(1))
ctx.Next()
})

router.POST("/v1/tinyurl", func(ctx *gin.Context) {
controller.CreateTinyURL(ctx, suite.db)
})
Expand Down Expand Up @@ -81,14 +87,19 @@ func (suite *AppTestSuite) TestCreateTinyURLEmptyOriginalURL() {
// TestCreateTinyURLCustomShortURL tests the creation of a tiny URL with a custom short URL and expects a successful response.
func (suite *AppTestSuite) TestCreateTinyURLCustomShortURL() {
router := gin.Default()

router.Use(func(ctx *gin.Context) {
ctx.Set("userID", int64(1))
ctx.Next()
})

router.POST("/v1/tinyurl", func(ctx *gin.Context) {
controller.CreateTinyURL(ctx, suite.db)
})

requestBody := map[string]interface{}{
"OriginalUrl": "https://example.com",
"ShortUrl": "short",
"UserId": 1,
}
requestJSON, _ := json.Marshal(requestBody)
req, _ := http.NewRequest("POST", "/v1/tinyurl", bytes.NewBuffer(requestJSON))
Expand All @@ -102,14 +113,19 @@ func (suite *AppTestSuite) TestCreateTinyURLCustomShortURL() {

func (suite *AppTestSuite) TestCreateTinyURLCustomShortURLExists() {
router := gin.Default()

router.Use(func(ctx *gin.Context) {
ctx.Set("userID", int64(1))
ctx.Next()
})

router.POST("/v1/tinyurl", func(ctx *gin.Context) {
controller.CreateTinyURL(ctx, suite.db)
})

requestBody := map[string]interface{}{
"OriginalUrl": "https://rds.com",
"ShortUrl": "37fff",
"UserId": 1,
}
requestJSON, _ := json.Marshal(requestBody)
req, _ := http.NewRequest("POST", "/v1/tinyurl", bytes.NewBuffer(requestJSON))
Expand All @@ -123,6 +139,12 @@ func (suite *AppTestSuite) TestCreateTinyURLCustomShortURLExists() {

func (suite *AppTestSuite) TestCreateTinyURLExistingOriginalURL() {
router := gin.Default()

router.Use(func(ctx *gin.Context) {
ctx.Set("userID", int64(1))
ctx.Next()
})

router.POST("/v1/tinyurl", func(ctx *gin.Context) {
controller.CreateTinyURL(ctx, suite.db)
})
Expand All @@ -131,7 +153,6 @@ func (suite *AppTestSuite) TestCreateTinyURLExistingOriginalURL() {

requestBody := map[string]interface{}{
"OriginalUrl": existingOriginalURL,
"UserId": 1,
}
requestJSON, _ := json.Marshal(requestBody)
req, _ := http.NewRequest("POST", "/v1/tinyurl", bytes.NewBuffer(requestJSON))
Expand Down

0 comments on commit 8f58692

Please sign in to comment.