refac: allowed image types and the size limit are a domain rule checked by the use case, not by the persistence layer
This commit is contained in:
1 parent
8a8a24434a
commit
5992c8598b
7 files changed
+249
-17
No files matched your search
@@ -3,21 +3,11 @@ package test
|
||||
import (
|
||||
imageDomain "RenewCMS/internal/domain/image"
|
||||
"RenewCMS/internal/infrastructure/useCases"
|
||||
"errors"
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var errUnsupportedImageContentType = errors.New("the file must be a PNG, JPEG, WEBP, or SVG image")
|
||||
|
||||
var supportedImageContentTypes = map[string]bool{
|
||||
"image/png": true,
|
||||
"image/jpeg": true,
|
||||
"image/webp": true,
|
||||
"image/svg+xml": true,
|
||||
}
|
||||
|
||||
type mockImageRepo struct {
|
||||
images map[uint32]imageDomain.Image
|
||||
nextID uint32
|
||||
@@ -34,9 +24,6 @@ func (m *mockImageRepo) Create(input imageDomain.ImageInput) (imageDomain.Image,
|
||||
if err := m.fail.trigger("Create"); err != nil {
|
||||
return imageDomain.Image{}, err
|
||||
}
|
||||
if !supportedImageContentTypes[input.ContentType] {
|
||||
return imageDomain.Image{}, errUnsupportedImageContentType
|
||||
}
|
||||
if input.Content != nil {
|
||||
_, _ = io.ReadAll(input.Content)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user