fix(05): WR-04 default File.IsPublic to true without trapping false

This commit is contained in:
Jakub Zych
2026-09-19 15:34:50 +02:00
parent fb12b2237d
commit c12e6576f6
3 changed files with 99 additions and 16 deletions

View File

@@ -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