@@ -223,4 +223,89 @@ describe('Handler Functions', () => {
223223 expect ( result ) . toHaveProperty ( 'staleFiles' ) ;
224224 } ) ;
225225 } ) ;
226+
227+ describe ( 'handleGetConventionalCommits' , ( ) => {
228+ let conventionalRepo : string ;
229+
230+ beforeAll ( ( ) => {
231+ conventionalRepo = join ( tmpdir ( ) , `conventional-test-${ Date . now ( ) } ` ) ;
232+ mkdirSync ( conventionalRepo , { recursive : true } ) ;
233+
234+ execSync ( 'git init' , { cwd : conventionalRepo } ) ;
235+ execSync ( 'git config user.email "test@example.com"' , { cwd : conventionalRepo } ) ;
236+ execSync ( 'git config user.name "Test User"' , { cwd : conventionalRepo } ) ;
237+
238+ writeFileSync ( join ( conventionalRepo , 'file1.txt' ) , 'content1\n' ) ;
239+ execSync ( 'git add .' , { cwd : conventionalRepo } ) ;
240+ execSync ( 'git commit -m "feat(core): add new feature"' , { cwd : conventionalRepo } ) ;
241+
242+ writeFileSync ( join ( conventionalRepo , 'file2.txt' ) , 'content2\n' ) ;
243+ execSync ( 'git add .' , { cwd : conventionalRepo } ) ;
244+ execSync ( 'git commit -m "fix: resolve bug"' , { cwd : conventionalRepo } ) ;
245+
246+ writeFileSync ( join ( conventionalRepo , 'file3.txt' ) , 'content3\n' ) ;
247+ execSync ( 'git add .' , { cwd : conventionalRepo } ) ;
248+ execSync ( 'git commit -m "feat!: breaking change"' , { cwd : conventionalRepo } ) ;
249+
250+ execSync ( 'git tag v1.0.0' , { cwd : conventionalRepo } ) ;
251+ } ) ;
252+
253+ it ( 'should analyze conventional commits' , ( ) => {
254+ const result = handlers . handleGetConventionalCommits ( {
255+ repo_path : conventionalRepo ,
256+ since : testDate ,
257+ } ) ;
258+
259+ expect ( result ) . toHaveProperty ( 'totalCommits' ) ;
260+ expect ( result ) . toHaveProperty ( 'conventionalCommits' ) ;
261+ expect ( result ) . toHaveProperty ( 'conventionalPercentage' ) ;
262+ expect ( result ) . toHaveProperty ( 'commitTypes' ) ;
263+ expect ( result ) . toHaveProperty ( 'topScopes' ) ;
264+ expect ( result ) . toHaveProperty ( 'breakingChanges' ) ;
265+ expect ( result ) . toHaveProperty ( 'recentReleases' ) ;
266+ expect ( result ) . toHaveProperty ( 'releaseFrequency' ) ;
267+
268+ expect ( result . totalCommits ) . toBe ( 3 ) ;
269+ expect ( result . conventionalCommits ) . toBe ( 3 ) ;
270+ expect ( result . conventionalPercentage ) . toBe ( '100.0%' ) ;
271+ expect ( result . breakingChanges ) . toBe ( 1 ) ;
272+ } ) ;
273+
274+ it ( 'should identify commit types' , ( ) => {
275+ const result = handlers . handleGetConventionalCommits ( {
276+ repo_path : conventionalRepo ,
277+ since : testDate ,
278+ } ) ;
279+
280+ expect ( Array . isArray ( result . commitTypes ) ) . toBe ( true ) ;
281+ const types = result . commitTypes . map ( ( t : any ) => t . type ) ;
282+ expect ( types ) . toContain ( 'feat' ) ;
283+ expect ( types ) . toContain ( 'fix' ) ;
284+ } ) ;
285+
286+ it ( 'should identify scopes' , ( ) => {
287+ const result = handlers . handleGetConventionalCommits ( {
288+ repo_path : conventionalRepo ,
289+ since : testDate ,
290+ } ) ;
291+
292+ expect ( Array . isArray ( result . topScopes ) ) . toBe ( true ) ;
293+ if ( result . topScopes . length > 0 ) {
294+ expect ( result . topScopes [ 0 ] ) . toHaveProperty ( 'scope' ) ;
295+ expect ( result . topScopes [ 0 ] ) . toHaveProperty ( 'count' ) ;
296+ }
297+ } ) ;
298+
299+ it ( 'should list releases' , ( ) => {
300+ const result = handlers . handleGetConventionalCommits ( {
301+ repo_path : conventionalRepo ,
302+ since : testDate ,
303+ } ) ;
304+
305+ expect ( Array . isArray ( result . recentReleases ) ) . toBe ( true ) ;
306+ expect ( result . recentReleases . length ) . toBeGreaterThan ( 0 ) ;
307+ expect ( result . recentReleases [ 0 ] ) . toHaveProperty ( 'tag' ) ;
308+ expect ( result . recentReleases [ 0 ] ) . toHaveProperty ( 'date' ) ;
309+ } ) ;
310+ } ) ;
226311} ) ;
0 commit comments