Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement multiple package occurences #242

Merged
merged 6 commits into from
Dec 8, 2024
Merged
Prev Previous commit
Next Next commit
feat(#239): cover mapping and validation changes
  • Loading branch information
Jumpy-Squirrel committed Dec 8, 2024
commit 7f9af12f2d1994d149acb20f894630bc0cf426e6
38 changes: 38 additions & 0 deletions internal/web/controller/attendeectl/mapping_test.go
Original file line number Diff line number Diff line change
@@ -20,3 +20,41 @@ func TestMapping(t *testing.T) {
attendeeDtoSource.Id = attendeeDtoResult.Id
require.EqualValues(t, attendeeDtoSource, attendeeDtoResult, "unexpected difference after mapping back and forth")
}

func TestMapping_PackagesClassic(t *testing.T) {
docs.Description("mapping an attendee dto back and forth should result in the same data - packages provided as comma separated list")
attendeeDtoSource := tstCreateValidAttendee()
keepPkgList := attendeeDtoSource.PackagesList
attendeeDtoSource.PackagesList = nil
attendeeEntity := entity.Attendee{}
mapDtoToAttendee(&attendeeDtoSource, &attendeeEntity)

attendeeDtoResult := attendee.AttendeeDto{}
mapAttendeeToDto(&attendeeEntity, &attendeeDtoResult)
// id differences are ok because the field is only mapped one way, so overwrite with actual value
attendeeDtoSource.Id = attendeeDtoResult.Id
// reverse mapping fills the package list, so restore it now
attendeeDtoSource.PackagesList = keepPkgList
require.EqualValues(t, attendeeDtoSource, attendeeDtoResult, "unexpected difference after mapping back and forth")
}

func TestMapping_PackagesAsList(t *testing.T) {
docs.Description("mapping an attendee dto back and forth should result in the same data - packages provided in packages_list field")
attendeeDtoSource := tstCreateValidAttendee()
keepPkgClassic := attendeeDtoSource.Packages
attendeeDtoSource.Packages = ""
attendeeEntity := entity.Attendee{}
mapDtoToAttendee(&attendeeDtoSource, &attendeeEntity)

attendeeDtoResult := attendee.AttendeeDto{}
mapAttendeeToDto(&attendeeEntity, &attendeeDtoResult)
// id differences are ok because the field is only mapped one way, so overwrite with actual value
attendeeDtoSource.Id = attendeeDtoResult.Id
// reverse mapping fills both packages_list and packages, so restore it now
attendeeDtoSource.Packages = keepPkgClassic
require.EqualValues(t, attendeeDtoSource, attendeeDtoResult, "unexpected difference after mapping back and forth")
}

func TestMapping_DuplicatePackage(t *testing.T) {

}
33 changes: 27 additions & 6 deletions internal/web/controller/attendeectl/validation_test.go
Original file line number Diff line number Diff line change
@@ -32,12 +32,16 @@ func tstCreateValidAttendee() attendee.AttendeeDto {
SpokenLanguages: "de,en",
RegistrationLanguage: "en-US",
Flags: "anon,ev",
Packages: "attendance,room-none,sponsor2,stage", // must be sorted for tests to work
Packages: "attendance,mountain-trip,mountain-trip,room-none,sponsor2,stage", // must be sorted for tests to work
PackagesList: []attendee.PackageState{
{
Name: "attendance",
Count: 1,
},
{
Name: "mountain-trip",
Count: 2,
},
{
Name: "room-none",
Count: 1,
@@ -210,18 +214,35 @@ func TestValidateChoiceFieldsAndId(t *testing.T) {
a.Gender = "348trhkuth4uihgkj4h89"
a.Options = "music,awoo"
a.Flags = "hc,noflag"
a.Packages = "helicopterflight,boattour,room-none"
a.Packages = "helicopterflight,boattour,room-none,room-none"
a.PackagesList = []attendee.PackageState{
{
Name: "helicopterflight",
Count: 1,
},
{
Name: "room-none",
Count: 2,
},
}
a.TshirtSize = "micro"
a.Telegram = "iforgotthe_at_atthebeginning"
a.Country = "XX" // not in ISO-3166-1
a.SpokenLanguages = "some_LANG"
a.RegistrationLanguage = "not_a_LANG"

expected := url.Values{
"gender": []string{"optional gender field must be one of male, female, other, notprovided, or it can be left blank, which counts as notprovided"},
"options": []string{"options field must be a comma separated combination of any of anim,art,music,suit"},
"flags": []string{"flags field must be a comma separated combination of any of anon,ev,hc,terms-accepted"},
"packages": []string{"packages field must be a comma separated combination of any of attendance,boat-trip,day-fri,day-sat,day-thu,mountain-trip,room-none,sponsor,sponsor2,stage"},
"gender": []string{"optional gender field must be one of male, female, other, notprovided, or it can be left blank, which counts as notprovided"},
"options": []string{"options field must be a comma separated combination of any of anim,art,music,suit"},
"flags": []string{"flags field must be a comma separated combination of any of anon,ev,hc,terms-accepted"},
"packages": []string{
"package room-none occurs too many times, can occur at most 1 times",
"packages field must be a comma separated combination of any of attendance,boat-trip,day-fri,day-sat,day-thu,mountain-trip,room-none,sponsor,sponsor2,stage",
},
"packages_list": []string{
"package room-none occurs too many times, can occur at most 1 times",
"packages_list can only contain package names attendance,boat-trip,day-fri,day-sat,day-thu,mountain-trip,room-none,sponsor,sponsor2,stage",
},
"registration_language": []string{"registration_language field must be one of en-US or it can be left blank, which counts as en-US"},
"spoken_languages": []string{"spoken_languages field must be a comma separated combination of any of en,de"},
"telegram": []string{"optional telegram field must contain your @username from telegram, or it can be left blank"},
1 change: 1 addition & 0 deletions test/testconfig-base.yaml
Original file line number Diff line number Diff line change
@@ -127,6 +127,7 @@ choices:
description: 'Mountain Trip'
price: 3000
vat_percent: 19
max_count: 2
day-thu:
description: 'Day Guest (Thursday)'
price: 6000