From 532df38cd43a4ec778d463106b1091215a7e19d7 Mon Sep 17 00:00:00 2001 From: ze0s <43699394+zze0s@users.noreply.github.com> Date: Thu, 20 Oct 2022 17:39:08 +0200 Subject: [PATCH] fix(filters): except categories (#510) fix(filters): except categories check --- internal/domain/filter.go | 6 ++-- internal/domain/filter_test.go | 52 ++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/internal/domain/filter.go b/internal/domain/filter.go index b74045f..2a52fa3 100644 --- a/internal/domain/filter.go +++ b/internal/domain/filter.go @@ -341,7 +341,7 @@ func (f Filter) CheckFilter(r *Release) ([]string, bool) { if r.Category != "" { categories = append(categories, r.Category) } - if !contains(r.Category, f.MatchCategories) && !containsAny(r.Categories, f.MatchCategories) { + if !contains(r.Category, f.MatchCategories) && !containsAny(categories, f.MatchCategories) { r.addRejectionF("category not matching. got: %v want: %v", strings.Join(categories, ","), f.MatchCategories) } } @@ -352,8 +352,8 @@ func (f Filter) CheckFilter(r *Release) ([]string, bool) { if r.Category != "" { categories = append(categories, r.Category) } - if !contains(r.Category, f.ExceptCategories) && !containsAny(r.Categories, f.ExceptCategories) { - r.addRejectionF("category unwanted. got: %v want: %v", strings.Join(categories, ","), f.ExceptCategories) + if contains(r.Category, f.ExceptCategories) && containsAny(categories, f.ExceptCategories) { + r.addRejectionF("category unwanted. got: %v unwanted: %v", strings.Join(categories, ","), f.ExceptCategories) } } diff --git a/internal/domain/filter_test.go b/internal/domain/filter_test.go index eaecda2..bef921c 100644 --- a/internal/domain/filter_test.go +++ b/internal/domain/filter_test.go @@ -226,6 +226,58 @@ func TestFilter_CheckFilter(t *testing.T) { }, want: true, }, + { + name: "movie_except_category_1", + fields: &Release{ + TorrentName: "That Movie 2020 2160p BluRay DD5.1 x264-GROUP1", + Category: "Movies", + Freeleech: true, + Size: uint64(30000000001), // 30GB + }, + args: args{ + filter: Filter{ + Enabled: true, + ExceptCategories: "*movies*", + Freeleech: true, + MinSize: "10 GB", + MaxSize: "40GB", + Resolutions: []string{"1080p", "2160p"}, + Sources: []string{"BluRay"}, + Codecs: []string{"x264"}, + Years: "2015,2018-2022", + MatchReleaseGroups: "GROUP1,BADGROUP", + Shows: "*Movie*, good story, bad movie", + }, + rejections: []string{"category unwanted. got: Movies unwanted: *movies*"}, + }, + want: false, + }, + { + name: "movie_except_category_1", + fields: &Release{ + TorrentName: "That Movie 2020 2160p BluRay DD5.1 x264-GROUP1", + Category: "Movies", + Freeleech: true, + Size: uint64(30000000001), // 30GB + }, + args: args{ + filter: Filter{ + Enabled: true, + ExceptCategories: "*tv*", + Freeleech: true, + MinSize: "10 GB", + MaxSize: "40GB", + Resolutions: []string{"1080p", "2160p"}, + Sources: []string{"BluRay"}, + Codecs: []string{"x264"}, + Years: "2015,2018-2022", + MatchReleaseGroups: "GROUP1,BADGROUP", + Shows: "*Movie*, good story, bad movie", + }, + rejections: nil, + }, + want: true, + }, { name: "movie_bad_category", fields: &Release{