Files
warpbox-dev/backend/libs/jobs/cleanup_test.go
Daniel Legt 74ede000b4 feat: implement configurable background jobs and toggle flags
Introduce environment variables to globally and individually control background jobs:
- `WARPBOX_JOBS_ENABLED` to toggle all background workers.
- `WARPBOX_CLEANUP_ENABLED` to toggle the expired box cleanup job.
- `WARPBOX_THUMBNAIL_ENABLED` to toggle the thumbnail generation job.

Refactor background tasks into a dedicated `backend/libs/jobs` package, allowing jobs to be registered, scheduled, and conditionally run based on the new configuration flags. Additionally, update the default maximum upload size in `.env.example` to 16GB and document the new settings in the README.
2026-05-29 22:25:59 +03:00

51 lines
1.1 KiB
Go

package jobs
import (
"testing"
"time"
"warpbox.dev/backend/libs/services"
)
func TestShouldDeleteBox(t *testing.T) {
now := time.Date(2026, 5, 29, 12, 0, 0, 0, time.UTC)
tests := map[string]struct {
box services.Box
want bool
}{
"expired": {
box: services.Box{ExpiresAt: now.Add(-time.Second)},
want: true,
},
"expires now": {
box: services.Box{ExpiresAt: now},
want: true,
},
"download limit reached": {
box: services.Box{ExpiresAt: now.Add(time.Hour), MaxDownloads: 3, DownloadCount: 3},
want: true,
},
"download limit exceeded": {
box: services.Box{ExpiresAt: now.Add(time.Hour), MaxDownloads: 3, DownloadCount: 4},
want: true,
},
"active unlimited": {
box: services.Box{ExpiresAt: now.Add(time.Hour)},
want: false,
},
"active under limit": {
box: services.Box{ExpiresAt: now.Add(time.Hour), MaxDownloads: 3, DownloadCount: 2},
want: false,
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
if got := shouldDeleteBox(tt.box, now); got != tt.want {
t.Fatalf("shouldDeleteBox() = %v, want %v", got, tt.want)
}
})
}
}