fix: pass filename in get category

This commit is contained in:
divyam234 2024-04-21 18:52:08 +05:30
parent a7734821a1
commit ddc1691ac0
2 changed files with 54 additions and 1 deletions

View file

@ -0,0 +1,53 @@
//gen test suite
package category
import (
"testing"
)
func TestGetCategory(t *testing.T) {
tests := []struct {
name string
fileName string
want Category
}{
{
name: "Document",
fileName: "file.doc",
want: Document,
},
{
name: "Image",
fileName: "file.jpg",
want: Image,
},
{
name: "Video",
fileName: "file.mp4",
want: Video,
},
{
name: "Audio",
fileName: "file.mp3",
want: Audio,
},
{
name: "Archive",
fileName: "file.zip",
want: Archive,
},
{
name: "Other",
fileName: "file",
want: Other,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GetCategory(tt.fileName); got != tt.want {
t.Errorf("GetCategory() = %v, want %v", got, tt.want)
}
})
}
}

View file

@ -79,7 +79,7 @@ func (fs *FileService) CreateFile(c *gin.Context, userId int64, fileIn *schemas.
}
fileDB.ChannelID = &channelId
fileDB.MimeType = fileIn.MimeType
fileDB.Category = string(category.GetCategory(fileIn.MimeType))
fileDB.Category = string(category.GetCategory(fileIn.Name))
parts := models.Parts{}
for _, part := range fileIn.Parts {
parts = append(parts, models.Part{