fix(05): WR-04 default File.IsPublic to true without trapping false
This commit is contained in:
@@ -55,6 +55,7 @@ CREATE TABLE attach_lifecycle_owners (
|
||||
if err := gdb.Create(&owner).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
isPublic := true
|
||||
file := attach.File{
|
||||
DiskName: "abc123xyz.jpg",
|
||||
FileName: "cover.jpg",
|
||||
@@ -63,7 +64,7 @@ CREATE TABLE attach_lifecycle_owners (
|
||||
Field: "photos",
|
||||
AttachmentID: strconv.FormatUint(uint64(owner.ID), 10),
|
||||
AttachmentType: owner.MorphName(),
|
||||
IsPublic: true,
|
||||
IsPublic: &isPublic,
|
||||
}
|
||||
if err := gdb.Create(&file).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -139,6 +140,51 @@ CREATE TABLE attach_lifecycle_owners (
|
||||
assertBlob(t, ctx, bucket, thumbKey, false)
|
||||
}
|
||||
|
||||
func TestFileCreateDefaultsIsPublic(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("requires testcontainers postgres")
|
||||
}
|
||||
gdb := attachGorm(t)
|
||||
if err := lagoon.Migrate(gdb, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
file := attach.File{
|
||||
DiskName: "abc123xyz.jpg",
|
||||
FileName: "cover.jpg",
|
||||
FileSize: 1,
|
||||
ContentType: "image/jpeg",
|
||||
}
|
||||
if err := gdb.Create(&file).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var got attach.File
|
||||
if err := gdb.First(&got, file.ID).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !got.Public() {
|
||||
t.Fatalf("Create without IsPublic stored %v, want true", got.IsPublic)
|
||||
}
|
||||
|
||||
priv := false
|
||||
hidden := attach.File{
|
||||
DiskName: "def456uvw.jpg",
|
||||
FileName: "secret.jpg",
|
||||
FileSize: 1,
|
||||
ContentType: "image/jpeg",
|
||||
IsPublic: &priv,
|
||||
}
|
||||
if err := gdb.Create(&hidden).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var gotHidden attach.File
|
||||
if err := gdb.First(&gotHidden, hidden.ID).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if gotHidden.Public() {
|
||||
t.Fatal("explicit is_public=false must persist")
|
||||
}
|
||||
}
|
||||
|
||||
func assertFileRow(t *testing.T, gdb *gorm.DB, id uint, want bool) {
|
||||
t.Helper()
|
||||
var n int64
|
||||
|
||||
Reference in New Issue
Block a user