feat(advertising): implement advertising service with CRUD operations and validation

- Added advertising.go for managing advertising entries with Create and List functionalities.
- Implemented CreateAdvertisingParams with validation for name, email, and status.
- Created migrations for advertising table structure.
- Added tests for advertising parameters validation.

feat(promo): introduce promo management with validation and CRUD operations

- Added promo.go for managing promotional entries with Create, Update, and List functionalities.
- Implemented CreatePromoParams and UpdatePromoParams with validation for position, section, and weeks.
- Created migrations for promo table structure.
- Added tests for promo parameters validation.

feat(images): add image management service with upload and retrieval

- Added images.go for managing image uploads and retrieval from storage.
- Implemented SaveImageParams with validation for image description and data.
- Created migrations for images table structure.
- Added tests for image parameters validation and data parsing.
This commit is contained in:
fabio
2026-10-01 20:19:07 +02:00
parent 0fe1bc2292
commit 664db8f7a0
17 changed files with 1299 additions and 1382 deletions

214
advertising/promo_test.go Normal file
View File

@@ -0,0 +1,214 @@
package advertising
import (
"testing"
"time"
)
func TestCreatePromoParamsValidate(t *testing.T) {
now := time.Now()
tests := []struct {
name string
params *CreatePromoParams
wantErr bool
}{
{
name: "nil params",
params: nil,
wantErr: true,
},
{
name: "invalid negative position",
params: &CreatePromoParams{
Position: -1,
},
wantErr: true,
},
{
name: "invalid position > 2",
params: &CreatePromoParams{
Position: 3,
},
wantErr: true,
},
{
name: "valid PromoLeft with week section",
params: &CreatePromoParams{
Position: PromoLeft,
Section: string(PromoLeftWeek),
ActiveFrom: &now,
},
wantErr: false,
},
{
name: "valid PromoRight1 with show section",
params: &CreatePromoParams{
Position: PromoRight1,
Section: string(PromoRight1Show),
},
wantErr: false,
},
{
name: "valid PromoRight2 with items and top section",
params: &CreatePromoParams{
Position: PromoRight2,
Section: string(PromoRight2Top),
Item: []PromoItem{
{
Title: "Banner Estivo",
Content: []PromoContent{
{
Width: 300,
Height: 250,
ImageURL: "https://example.com/banner.jpg",
URL: "https://example.com",
},
},
},
},
},
wantErr: false,
},
{
name: "invalid section for PromoLeft",
params: &CreatePromoParams{
Position: PromoLeft,
Section: "invalid-section",
},
wantErr: true,
},
{
name: "invalid section for PromoRight1",
params: &CreatePromoParams{
Position: PromoRight1,
Section: string(PromoLeftWeek),
},
wantErr: true,
},
{
name: "invalid section for PromoRight2",
params: &CreatePromoParams{
Position: PromoRight2,
Section: string(PromoRight1Show),
},
wantErr: true,
},
{
name: "invalid week < 1",
params: &CreatePromoParams{
Position: PromoLeft,
Section: string(PromoLeftWeek),
Weeks: []int{0},
},
wantErr: true,
},
{
name: "invalid week > 53",
params: &CreatePromoParams{
Position: PromoLeft,
Section: string(PromoLeftWeek),
Weeks: []int{54},
},
wantErr: true,
},
{
name: "valid weeks",
params: &CreatePromoParams{
Position: PromoLeft,
Section: string(PromoLeftWeek),
Weeks: []int{1, 10, 52},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.params.Validate()
if (err != nil) != tt.wantErr {
t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr)
}
if err == nil && tt.params.Item == nil {
t.Errorf("expected Item slice to be initialized, got nil")
}
})
}
}
func TestUpdatePromoParamsValidate(t *testing.T) {
tests := []struct {
name string
params *UpdatePromoParams
wantErr bool
}{
{
name: "nil params",
params: nil,
wantErr: true,
},
{
name: "invalid negative position",
params: &UpdatePromoParams{
Position: -1,
},
wantErr: true,
},
{
name: "valid PromoLeft week",
params: &UpdatePromoParams{
Position: PromoLeft,
Section: string(PromoLeftWeek),
},
wantErr: false,
},
{
name: "valid PromoRight1 show with items",
params: &UpdatePromoParams{
Position: PromoRight1,
Section: string(PromoRight1Show),
Item: []PromoItem{
{Title: "Updated title"},
},
},
wantErr: false,
},
{
name: "invalid section for PromoRight1",
params: &UpdatePromoParams{
Position: PromoRight1,
Section: "invalid",
},
wantErr: true,
},
{
name: "invalid week in update",
params: &UpdatePromoParams{
Position: PromoRight1,
Section: string(PromoRight1Show),
Weeks: []int{0},
},
wantErr: true,
},
{
name: "valid weeks in update",
params: &UpdatePromoParams{
Position: PromoRight1,
Section: string(PromoRight1Show),
Weeks: []int{5, 6, 7},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.params.Validate()
if (err != nil) != tt.wantErr {
t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr)
}
if err == nil && tt.params.Item == nil {
t.Errorf("expected Item slice to be initialized, got nil")
}
})
}
}