- 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.
93 lines
2.0 KiB
Go
93 lines
2.0 KiB
Go
package advertising
|
|
|
|
import "testing"
|
|
|
|
func TestCreateAdvertisingParamsValidate(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
params *CreateAdvertisingParams
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "nil params",
|
|
params: nil,
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "empty email",
|
|
params: &CreateAdvertisingParams{
|
|
Nome: "Azienda Rossi",
|
|
Email: "",
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "invalid email format",
|
|
params: &CreateAdvertisingParams{
|
|
Nome: "Azienda Rossi",
|
|
Email: "invalid-email-address",
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "email missing domain dot",
|
|
params: &CreateAdvertisingParams{
|
|
Nome: "Azienda Rossi",
|
|
Email: "test@domain",
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "empty name",
|
|
params: &CreateAdvertisingParams{
|
|
Nome: " ",
|
|
Email: "azienda@rossi.it",
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "invalid status",
|
|
params: &CreateAdvertisingParams{
|
|
Nome: "Azienda Rossi",
|
|
Email: "azienda@rossi.it",
|
|
Status: "pending",
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "valid with default active status",
|
|
params: &CreateAdvertisingParams{
|
|
Nome: " Azienda Rossi ",
|
|
Email: " AZIENDA@rossi.it ",
|
|
},
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "valid with explicit inactive status",
|
|
params: &CreateAdvertisingParams{
|
|
Nome: "Azienda Bianchi",
|
|
Email: "info@bianchi.com",
|
|
Status: StatusInactive,
|
|
},
|
|
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 {
|
|
if tt.params.Status != StatusActive && tt.params.Status != StatusInactive {
|
|
t.Errorf("expected Status to be active or inactive, got %s", tt.params.Status)
|
|
}
|
|
if tt.params.Email != "azienda@rossi.it" && tt.params.Email != "info@bianchi.com" {
|
|
t.Errorf("expected email to be normalized, got %s", tt.params.Email)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|