feat: update page list show

This commit is contained in:
yanghao05
2025-04-08 15:35:58 +08:00
parent 7d28dff65b
commit cf8bb5f192
13 changed files with 280 additions and 102 deletions

View File

@@ -3,6 +3,8 @@ package models
import (
"context"
"fmt"
"math"
"math/rand"
"testing"
"time"
@@ -54,6 +56,60 @@ func (s *MediasTestSuite) Test_countByCondition() {
})
}
func (s *MediasTestSuite) Test_BatchCreate() {
Convey("Create", s.T(), func() {
Convey("valid media", func() {
database.Truncate(context.Background(), db, table.Medias.TableName())
models := []*model.Medias{
{
Name: "test 01",
CreatedAt: time.Now(),
MimeType: "video/mp4",
Size: rand.Int63n(math.MaxInt64), // Random size
Path: "path/to/media.mp4",
},
{
Name: "test 02",
CreatedAt: time.Now(),
MimeType: "audio/mp3",
Size: rand.Int63n(math.MaxInt64), // Random size
Path: "path/to/media.mp3",
},
{
Name: "test 03",
CreatedAt: time.Now(),
MimeType: "application/pdf",
Size: rand.Int63n(math.MaxInt64), // Random size
Path: "path/to/media.pdf",
},
{
Name: "test 04",
CreatedAt: time.Now(),
MimeType: "image/jpeg",
Size: rand.Int63n(math.MaxInt64), // Random size
Path: "path/to/media.jpeg",
},
{
Name: "test 05",
CreatedAt: time.Now(),
MimeType: "application/zip",
Size: rand.Int63n(math.MaxInt64), // Random size
Path: "path/to/media.zip",
},
}
count := 10
for i := 0; i < count; i++ {
err := Medias.BatchCreate(context.Background(), models)
Convey("Create should not return an error: "+fmt.Sprintf("%d", i), func() {
So(err, ShouldBeNil)
})
}
})
})
}
func (s *MediasTestSuite) Test_Create() {
Convey("Create", s.T(), func() {
Convey("valid media", func() {
@@ -132,3 +188,26 @@ func (s *MediasTestSuite) Test_Page() {
})
})
}
// Test ConvertFileTypeByMimeType
func (s *MediasTestSuite) Test_ConvertFileTypeByMimeType() {
Convey("ConvertFileTypeByMimeType", s.T(), func() {
Convey("image", func() {
mimeType := "image/jpeg"
fileType := Medias.ConvertFileTypeByMimeType(mimeType)
So(fileType, ShouldEqual, MediaTypeImage)
})
Convey("video", func() {
mimeType := "video/mp4"
fileType := Medias.ConvertFileTypeByMimeType(mimeType)
So(fileType, ShouldEqual, MediaTypeVideo)
})
Convey("invalid mime type", func() {
mimeType := "invalid/type"
fileType := Medias.ConvertFileTypeByMimeType(mimeType)
So(fileType, ShouldEqual, MediaTypeUnknown)
})
})
}