@@ -3,38 +3,64 @@ import { formatTaskBranches, outputMergedBranches } from "../output";
33import { GitMergedConfig } from "../repo" ;
44
55const DEFAULT_CONFIG : GitMergedConfig = {
6- issueUrlFormat : "https://test-instance.org" ,
7- issueUrlPrefix : "TOKEN"
6+ issueUrlFormat : "https://test-instance.org/browse/{{prefix}}{{id}} " ,
7+ issueUrlPrefix : [ "TOKEN-" ]
88} ;
99
1010describe ( "formatTaskBranches" , ( ) => {
1111 it ( "should format branches with issue URL correctly" , ( ) => {
1212 const branches = [ "feat/TOKEN-800_new-feature" , "fix/TOKEN-123_some-fix" ] ;
1313 const result = formatTaskBranches ( branches , DEFAULT_CONFIG ) ;
1414 expect ( result ) . toEqual ( [
15- 'feat/TOKEN-800_new-feature <https://test-instance.org/TOKEN-800>' ,
16- 'fix/TOKEN-123_some-fix <https://test-instance.org/TOKEN-123>'
15+ 'feat/TOKEN-800_new-feature <https://test-instance.org/browse/ TOKEN-800>' ,
16+ 'fix/TOKEN-123_some-fix <https://test-instance.org/browse/ TOKEN-123>'
1717 ] ) ;
1818 } ) ;
1919
20- it ( "should not format branches without issue prefix" , ( ) => {
21- const branches = [ "fix/hotfix" , "feature/no-issue" ] ;
22- const result = formatTaskBranches ( branches , DEFAULT_CONFIG ) ;
23- expect ( result ) . toEqual ( branches ) ; // No change, since no matching prefix
20+ it ( "should support multiple issue prefixes" , ( ) => {
21+ const branches = [ "fix/TOKEN-123_fix" , "feat/PROJECT-45_add-feature" ] ;
22+ const config : GitMergedConfig = {
23+ issueUrlFormat : "https://example.com/browse/{{prefix}}{{id}}" ,
24+ issueUrlPrefix : [ "TOKEN-" , "PROJECT-" ]
25+ } ;
26+ const result = formatTaskBranches ( branches , config ) ;
27+ expect ( result ) . toEqual ( [
28+ "fix/TOKEN-123_fix <https://example.com/browse/TOKEN-123>" ,
29+ "feat/PROJECT-45_add-feature <https://example.com/browse/PROJECT-45>"
30+ ] ) ;
2431 } ) ;
2532
26- it ( "should return branches as is if URL format is invalid" , ( ) => {
33+ it ( "should not format branches if issueUrlFormat is not provided" , ( ) => {
34+ const branches = [ "feat/TOKEN-100" ] ;
35+ const config = { issueUrlFormat : DEFAULT_CONFIG . issueUrlFormat } ;
36+ const result = formatTaskBranches ( branches , config ) ;
37+ expect ( result ) . toEqual ( branches ) ;
38+ } ) ;
39+
40+ it ( "should not format branches if issueUrlPrefix is not provided" , ( ) => {
41+ const branches = [ "feat/TOKEN-100" ] ;
42+ const config = { issueUrlPrefix : DEFAULT_CONFIG . issueUrlPrefix } ;
43+ const result = formatTaskBranches ( branches , config ) ;
44+ expect ( result ) . toEqual ( branches ) ;
45+ } ) ;
46+
47+ it ( "should not format branches without valid issueUrlFormat" , ( ) => {
2748 const branches = [ "feat/TOKEN-800_new-feature" ] ;
2849 const config : GitMergedConfig = { ...DEFAULT_CONFIG , issueUrlFormat : "invalid-url" } ;
2950 const result = formatTaskBranches ( branches , config ) ;
3051 expect ( result ) . toEqual ( branches ) ; // Invalid URL, no changes
3152 } ) ;
3253
33- it ( "should return branches as is if issue prefix is invalid" , ( ) => {
34- const branches = [ "feat/TOKEN-800_new-feature" ] ;
35- const config : GitMergedConfig = { ...DEFAULT_CONFIG , issueUrlPrefix : "invalid!prefix" } ;
36- const result = formatTaskBranches ( branches , config ) ;
37- expect ( result ) . toEqual ( branches ) ; // Invalid prefix, no changes
54+ it ( "should not format branches without matching prefix" , ( ) => {
55+ const branches = [ "fix/hotfix" , "feature/no-issue" ] ;
56+ const result = formatTaskBranches ( branches , DEFAULT_CONFIG ) ;
57+ expect ( result ) . toEqual ( branches ) ; // No matching prefix, no changes
58+ } ) ;
59+
60+ it ( "should not format branches when prefix is part of another word" , ( ) => {
61+ const branches = [ "fix/NOTTOKEN-100_bad-branch" ] ;
62+ const result = formatTaskBranches ( branches , DEFAULT_CONFIG ) ;
63+ expect ( result ) . toEqual ( branches ) ; // No matching prefix, prefix must be exact, no changes
3864 } ) ;
3965} ) ;
4066
@@ -46,33 +72,28 @@ describe("outputMergedBranches", () => {
4672 warnSpy = vi . spyOn ( console , "warn" ) . mockImplementation ( ( ) => { } ) ;
4773 } ) ;
4874
49- it ( "should warn when issueUrlFormat is not a valid URL" , ( ) => {
50- const branches = [ "feat/TOKEN-100" ] ;
51- const config = { ...DEFAULT_CONFIG , issueUrlFormat : "invalid-url" } ;
52-
53- outputMergedBranches ( branches , "master" , config ) ;
54- expect ( warnSpy ) . toHaveBeenCalledWith ( "'invalid-url' is not a valid URL. Skipped formatting." ) ;
55- } ) ;
56-
57- it ( "should warn when issueUrlPrefix is not valid" , ( ) => {
58- const branches = [ "feat/TOKEN-100" ] ;
59- const config = { ...DEFAULT_CONFIG , issueUrlPrefix : "invalid!prefix" } ;
60-
61- outputMergedBranches ( branches , "master" , config ) ;
62- expect ( warnSpy ) . toHaveBeenCalledWith ( "'invalid!prefix' is not a valid issue prefix. Skipped formatting." ) ;
63- } ) ;
64-
6575 it ( "should log the correct branches when there are merged branches" , ( ) => {
6676 const branches = [ "feat/TOKEN-800_new-feature" , "fix/TOKEN-123_some-fix" ] ;
6777
6878 outputMergedBranches ( branches , "master" , DEFAULT_CONFIG ) ;
6979 expect ( infoSpy ) . toHaveBeenNthCalledWith ( 1 , "Branches merged into 'master':" ) ;
70- expect ( infoSpy ) . toHaveBeenNthCalledWith ( 2 , "feat/TOKEN-800_new-feature <https://test-instance.org/TOKEN-800>\nfix/TOKEN-123_some-fix <https://test-instance.org/TOKEN-123>" )
80+ const branchOutput = [
81+ "feat/TOKEN-800_new-feature <https://test-instance.org/browse/TOKEN-800>" ,
82+ "fix/TOKEN-123_some-fix <https://test-instance.org/browse/TOKEN-123>"
83+ ]
84+ expect ( infoSpy ) . toHaveBeenNthCalledWith ( 2 , branchOutput . join ( "\n" ) ) ;
7185 } ) ;
7286
7387 it ( "should log a message when no branches are merged" , ( ) => {
7488 outputMergedBranches ( [ ] , "master" , DEFAULT_CONFIG ) ;
75-
7689 expect ( infoSpy ) . toHaveBeenCalledWith ( "No branches merged into 'master'." ) ;
7790 } ) ;
91+
92+ it ( "should warn when issueUrlFormat is not a valid URL" , ( ) => {
93+ const branches = [ "feat/TOKEN-100" ] ;
94+ const config = { ...DEFAULT_CONFIG , issueUrlFormat : "invalid-url" } ;
95+
96+ outputMergedBranches ( branches , "master" , config ) ;
97+ expect ( warnSpy ) . toHaveBeenCalledWith ( "'invalid-url' is not a valid URL. Skipped formatting." ) ;
98+ } ) ;
7899} ) ;
0 commit comments