Skip to content

Commit

Permalink
notification fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Achpochmak committed Dec 18, 2024
1 parent b06f494 commit 1261321
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions internal/gateway/utils/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package utils

import (
"mime/multipart"
"net/http"
"net/http/httptest"
"testing"

"kudago/internal/models"

"github.com/stretchr/testify/assert"
)

func TestGenerateFilename(t *testing.T) {
t.Run("Valid filename generation", func(t *testing.T) {
header := &multipart.FileHeader{
Filename: "test_image.jpg",
}

err := GenerateFilename(header)

assert.NoError(t, err)
assert.Contains(t, header.Filename, "_")

assert.Equal(t, "jpg", getFileExtension(header.Filename))
})

t.Run("Invalid image format", func(t *testing.T) {
header := &multipart.FileHeader{
Filename: "test_document.pdf",
}

err := GenerateFilename(header)

assert.Error(t, err)
assert.Equal(t, models.ErrInvalidImageFormat, err)
})
}

func TestGetPaginationParams(t *testing.T) {
t.Run("Default pagination params", func(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "/items?page=0&limit=30", nil)

params := GetPaginationParams(req)

assert.Equal(t, 0, params.Offset)
assert.Equal(t, 30, params.Limit)
})

t.Run("Custom pagination params", func(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "/items?page=1&limit=10", nil)

params := GetPaginationParams(req)

assert.Equal(t, 10, params.Offset)
assert.Equal(t, 10, params.Limit)
})
}

0 comments on commit 1261321

Please sign in to comment.