@@ -208,15 +208,16 @@ func (s *AccountRepoSuite) TestList() {
208208
209209func (s * AccountRepoSuite ) TestListWithFilters () {
210210 tests := []struct {
211- name string
212- setup func (client * dbent.Client )
213- platform string
214- accType string
215- status string
216- search string
217- groupID int64
218- wantCount int
219- validate func (accounts []service.Account )
211+ name string
212+ setup func (client * dbent.Client )
213+ platform string
214+ accType string
215+ status string
216+ search string
217+ groupID int64
218+ privacyMode string
219+ wantCount int
220+ validate func (accounts []service.Account )
220221 }{
221222 {
222223 name : "filter_by_platform" ,
@@ -281,6 +282,32 @@ func (s *AccountRepoSuite) TestListWithFilters() {
281282 s .Require ().Empty (accounts [0 ].GroupIDs )
282283 },
283284 },
285+ {
286+ name : "filter_by_privacy_mode" ,
287+ setup : func (client * dbent.Client ) {
288+ mustCreateAccount (s .T (), client , & service.Account {Name : "privacy-ok" , Extra : map [string ]any {"privacy_mode" : service .PrivacyModeTrainingOff }})
289+ mustCreateAccount (s .T (), client , & service.Account {Name : "privacy-fail" , Extra : map [string ]any {"privacy_mode" : service .PrivacyModeFailed }})
290+ },
291+ privacyMode : service .PrivacyModeTrainingOff ,
292+ wantCount : 1 ,
293+ validate : func (accounts []service.Account ) {
294+ s .Require ().Equal ("privacy-ok" , accounts [0 ].Name )
295+ },
296+ },
297+ {
298+ name : "filter_by_privacy_mode_unset" ,
299+ setup : func (client * dbent.Client ) {
300+ mustCreateAccount (s .T (), client , & service.Account {Name : "privacy-unset" , Extra : nil })
301+ mustCreateAccount (s .T (), client , & service.Account {Name : "privacy-empty" , Extra : map [string ]any {"privacy_mode" : "" }})
302+ mustCreateAccount (s .T (), client , & service.Account {Name : "privacy-set" , Extra : map [string ]any {"privacy_mode" : service .PrivacyModeTrainingOff }})
303+ },
304+ privacyMode : service .AccountPrivacyModeUnsetFilter ,
305+ wantCount : 2 ,
306+ validate : func (accounts []service.Account ) {
307+ names := []string {accounts [0 ].Name , accounts [1 ].Name }
308+ s .ElementsMatch ([]string {"privacy-unset" , "privacy-empty" }, names )
309+ },
310+ },
284311 }
285312
286313 for _ , tt := range tests {
@@ -293,7 +320,7 @@ func (s *AccountRepoSuite) TestListWithFilters() {
293320
294321 tt .setup (client )
295322
296- accounts , _ , err := repo .ListWithFilters (ctx , pagination.PaginationParams {Page : 1 , PageSize : 10 }, tt .platform , tt .accType , tt .status , tt .search , tt .groupID )
323+ accounts , _ , err := repo .ListWithFilters (ctx , pagination.PaginationParams {Page : 1 , PageSize : 10 }, tt .platform , tt .accType , tt .status , tt .search , tt .groupID , tt . privacyMode )
297324 s .Require ().NoError (err )
298325 s .Require ().Len (accounts , tt .wantCount )
299326 if tt .validate != nil {
@@ -360,7 +387,7 @@ func (s *AccountRepoSuite) TestPreload_And_VirtualFields() {
360387 s .Require ().Len (got .Groups , 1 , "expected Groups to be populated" )
361388 s .Require ().Equal (group .ID , got .Groups [0 ].ID )
362389
363- accounts , page , err := s .repo .ListWithFilters (s .ctx , pagination.PaginationParams {Page : 1 , PageSize : 10 }, "" , "" , "" , "acc" , 0 )
390+ accounts , page , err := s .repo .ListWithFilters (s .ctx , pagination.PaginationParams {Page : 1 , PageSize : 10 }, "" , "" , "" , "acc" , 0 , "" )
364391 s .Require ().NoError (err , "ListWithFilters" )
365392 s .Require ().Equal (int64 (1 ), page .Total )
366393 s .Require ().Len (accounts , 1 )
0 commit comments