post_images.kind is image or video. A post can keep one video alongside up to four images. Reviewed-on: #21 Co-authored-by: codegirl-007 <s.raide@gmail.com>
This commit was merged in pull request #21.
This commit is contained in:
@@ -338,6 +338,36 @@ func TestMemoryPostImages(t *testing.T) {
|
||||
if err := mem.CreatePost(ctx, tooMany); !errors.Is(err, ErrInvalidPost) {
|
||||
t.Fatalf("five-image create error = %v, want ErrInvalidPost", err)
|
||||
}
|
||||
|
||||
withVideo := &Post{
|
||||
AuthorID: homeowner.ID,
|
||||
Title: "With video",
|
||||
Body: "Four photos and a clip.",
|
||||
Images: append(validPostImages(4), PostImage{
|
||||
ID: "clip-1",
|
||||
ObjectKey: "posts/clip-1.mp4",
|
||||
PublicURL: "https://cdn.example/clip-1.mp4",
|
||||
Kind: MediaKindVideo,
|
||||
}),
|
||||
}
|
||||
if err := mem.CreatePost(ctx, withVideo); err != nil {
|
||||
t.Fatalf("four images and one video: %v", err)
|
||||
}
|
||||
if withVideo.Images[4].Kind != MediaKindVideo || withVideo.Images[4].Position != 4 {
|
||||
t.Fatalf("video not stored: %+v", withVideo.Images[4])
|
||||
}
|
||||
twoVideos := &Post{
|
||||
AuthorID: homeowner.ID,
|
||||
Title: "Two clips",
|
||||
Body: "Not allowed.",
|
||||
Images: []PostImage{
|
||||
{ObjectKey: "posts/a.mp4", PublicURL: "https://cdn.example/a.mp4", Kind: MediaKindVideo},
|
||||
{ObjectKey: "posts/b.mp4", PublicURL: "https://cdn.example/b.mp4", Kind: MediaKindVideo},
|
||||
},
|
||||
}
|
||||
if err := mem.CreatePost(ctx, twoVideos); !errors.Is(err, ErrInvalidPost) {
|
||||
t.Fatalf("two-video create error = %v, want ErrInvalidPost", err)
|
||||
}
|
||||
}
|
||||
|
||||
func validPostImages(count int) []PostImage {
|
||||
|
||||
Reference in New Issue
Block a user