@@ -51,7 +51,7 @@ func TestGetProfileStats(t *testing.T) {
5151 },
5252 }
5353
54- uc := usecase .NewProfileStatsUseCase (mockRepo , 10 )
54+ uc := usecase .NewProfileStatsUseCase (mockRepo , 10 , "" )
5555 stats , err := uc .GetProfileStats (context .Background ())
5656
5757 if err != nil {
@@ -66,3 +66,172 @@ func TestGetProfileStats(t *testing.T) {
6666 t .Errorf ("Expected total bytes 1500, got: %d" , stats .TotalBytes )
6767 }
6868}
69+
70+ func TestExcludeLanguages (t * testing.T ) {
71+ mockRepo := & MockGitHubRepository {
72+ Username : "testuser" ,
73+ UserProfile : & domain.UserProfile {
74+ Username : "testuser" ,
75+ CreatedAt : time .Date (2020 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
76+ },
77+ LanguageStats : map [string ]int {
78+ "Go" : 1000 ,
79+ "Java" : 500 ,
80+ "SCSS" : 300 ,
81+ "HTML" : 200 ,
82+ "CSS" : 100 ,
83+ },
84+ Commits : []domain.Commit {
85+ {Date : time .Date (2023 , 11 , 12 , 10 , 0 , 0 , 0 , time .UTC )},
86+ },
87+ }
88+
89+ // Test excluding SCSS and HTML (case-insensitive)
90+ uc := usecase .NewProfileStatsUseCase (mockRepo , 10 , "scss,html" )
91+ stats , err := uc .GetProfileStats (context .Background ())
92+
93+ if err != nil {
94+ t .Fatalf ("Expected no error, got: %v" , err )
95+ }
96+
97+ // Check that SCSS and HTML are not in the languages list
98+ for _ , lang := range stats .Languages {
99+ if lang .Language == "SCSS" || lang .Language == "HTML" {
100+ t .Errorf ("Expected %s to be excluded, but it's in the results" , lang .Language )
101+ }
102+ }
103+
104+ // Check that other languages are present
105+ expectedLanguages := map [string ]bool {"Go" : false , "Java" : false , "CSS" : false }
106+ for _ , lang := range stats .Languages {
107+ if _ , ok := expectedLanguages [lang .Language ]; ok {
108+ expectedLanguages [lang .Language ] = true
109+ }
110+ }
111+
112+ for lang , found := range expectedLanguages {
113+ if ! found {
114+ t .Errorf ("Expected %s to be in the results, but it's missing" , lang )
115+ }
116+ }
117+
118+ // Total bytes should be 1600 (1000 + 500 + 100), excluding SCSS (300) and HTML (200)
119+ if stats .TotalBytes != 2100 {
120+ t .Errorf ("Expected total bytes 2100 (original total), got: %d" , stats .TotalBytes )
121+ }
122+
123+ // Check that percentages add up to ~100%
124+ totalPercentage := 0.0
125+ for _ , lang := range stats .Languages {
126+ totalPercentage += lang .Percentage
127+ }
128+ if totalPercentage < 99.9 || totalPercentage > 100.1 {
129+ t .Errorf ("Expected total percentage to be ~100%%, got: %.2f%%" , totalPercentage )
130+ }
131+ }
132+
133+ func TestExcludeLanguagesCaseInsensitive (t * testing.T ) {
134+ mockRepo := & MockGitHubRepository {
135+ Username : "testuser" ,
136+ UserProfile : & domain.UserProfile {
137+ Username : "testuser" ,
138+ CreatedAt : time .Date (2020 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
139+ },
140+ LanguageStats : map [string ]int {
141+ "Go" : 1000 ,
142+ "SCSS" : 500 ,
143+ },
144+ Commits : []domain.Commit {
145+ {Date : time .Date (2023 , 11 , 12 , 10 , 0 , 0 , 0 , time .UTC )},
146+ },
147+ }
148+
149+ // Test case-insensitive matching (lowercase input, uppercase language)
150+ uc := usecase .NewProfileStatsUseCase (mockRepo , 10 , "scss" )
151+ stats , err := uc .GetProfileStats (context .Background ())
152+
153+ if err != nil {
154+ t .Fatalf ("Expected no error, got: %v" , err )
155+ }
156+
157+ // SCSS should be excluded
158+ for _ , lang := range stats .Languages {
159+ if lang .Language == "SCSS" {
160+ t .Errorf ("Expected SCSS to be excluded (case-insensitive), but it's in the results" )
161+ }
162+ }
163+
164+ // Only Go should remain
165+ if len (stats .Languages ) != 1 {
166+ t .Errorf ("Expected 1 language, got: %d" , len (stats .Languages ))
167+ }
168+
169+ if stats .Languages [0 ].Language != "Go" {
170+ t .Errorf ("Expected Go to be the only language, got: %s" , stats .Languages [0 ].Language )
171+ }
172+ }
173+
174+ func TestExcludeLanguagesWithSpaces (t * testing.T ) {
175+ mockRepo := & MockGitHubRepository {
176+ Username : "testuser" ,
177+ UserProfile : & domain.UserProfile {
178+ Username : "testuser" ,
179+ CreatedAt : time .Date (2020 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
180+ },
181+ LanguageStats : map [string ]int {
182+ "Go" : 1000 ,
183+ "Java" : 500 ,
184+ "HTML" : 200 ,
185+ },
186+ Commits : []domain.Commit {
187+ {Date : time .Date (2023 , 11 , 12 , 10 , 0 , 0 , 0 , time .UTC )},
188+ },
189+ }
190+
191+ // Test with spaces around commas
192+ uc := usecase .NewProfileStatsUseCase (mockRepo , 10 , "html , java " )
193+ stats , err := uc .GetProfileStats (context .Background ())
194+
195+ if err != nil {
196+ t .Fatalf ("Expected no error, got: %v" , err )
197+ }
198+
199+ // Only Go should remain
200+ if len (stats .Languages ) != 1 {
201+ t .Errorf ("Expected 1 language, got: %d" , len (stats .Languages ))
202+ }
203+
204+ if stats .Languages [0 ].Language != "Go" {
205+ t .Errorf ("Expected Go to be the only language, got: %s" , stats .Languages [0 ].Language )
206+ }
207+ }
208+
209+ func TestNoExcludeLanguages (t * testing.T ) {
210+ mockRepo := & MockGitHubRepository {
211+ Username : "testuser" ,
212+ UserProfile : & domain.UserProfile {
213+ Username : "testuser" ,
214+ CreatedAt : time .Date (2020 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
215+ },
216+ LanguageStats : map [string ]int {
217+ "Go" : 1000 ,
218+ "Java" : 500 ,
219+ },
220+ Commits : []domain.Commit {
221+ {Date : time .Date (2023 , 11 , 12 , 10 , 0 , 0 , 0 , time .UTC )},
222+ },
223+ }
224+
225+ // Test with empty exclude string
226+ uc := usecase .NewProfileStatsUseCase (mockRepo , 10 , "" )
227+ stats , err := uc .GetProfileStats (context .Background ())
228+
229+ if err != nil {
230+ t .Fatalf ("Expected no error, got: %v" , err )
231+ }
232+
233+ // All languages should be present
234+ if len (stats .Languages ) != 2 {
235+ t .Errorf ("Expected 2 languages, got: %d" , len (stats .Languages ))
236+ }
237+ }
0 commit comments