11import { describe , it , expect , vi , beforeEach } from "vitest" ;
22import { formatTaskBranches , outputMergedBranches } from "../output" ;
33import { GitMergedConfig } from "../repo" ;
4+ import * as repoMethods from "../repo" ;
45
56const DEFAULT_CONFIG : GitMergedConfig = {
67 issueUrlFormat : "https://test-instance.org/browse/{{prefix}}{{id}}" ,
@@ -72,7 +73,7 @@ describe("outputMergedBranches", () => {
7273 warnSpy = vi . spyOn ( console , "warn" ) . mockImplementation ( ( ) => { } ) ;
7374 } ) ;
7475
75- it ( "should log the correct branches when there are merged branches" , ( ) => {
76+ it ( "should log the correct branches when there are local merged branches" , ( ) => {
7677 const branches = [ "feat/TOKEN-800_new-feature" , "fix/TOKEN-123_some-fix" ] ;
7778
7879 outputMergedBranches ( branches , "master" , DEFAULT_CONFIG ) ;
@@ -84,13 +85,33 @@ describe("outputMergedBranches", () => {
8485 expect ( infoSpy ) . toHaveBeenNthCalledWith ( 2 , branchOutput . join ( "\n" ) ) ;
8586
8687 const localDelete = `git branch --delete ${ branches . join ( " " ) } ` ;
87- const remoteDelete = `git push origin --delete ${ branches . join ( " " ) } ` ;
88- expect ( infoSpy ) . toHaveBeenNthCalledWith ( 3 , "\nRun the following to delete branches locally and remotely:" ) ;
89- expect ( infoSpy ) . toHaveBeenNthCalledWith ( 4 , `${ localDelete } && ${ remoteDelete } ` ) ;
88+ expect ( infoSpy ) . toHaveBeenNthCalledWith ( 3 , "\nRun the following to delete branches:" ) ;
89+ expect ( infoSpy ) . toHaveBeenNthCalledWith ( 4 , `locally:\n ${ localDelete } ` ) ;
9090 expect ( infoSpy ) . toHaveBeenCalledTimes ( 4 ) ;
9191 expect ( warnSpy ) . not . toHaveBeenCalled ( ) ;
9292 } ) ;
9393
94+ it ( "should log the correct branches when there are remote merged branches" , ( ) => {
95+ const branches = [ "feat/TOKEN-800_new-feature" , "fix/TOKEN-123_some-fix" ] ;
96+ vi . spyOn ( repoMethods , "fetchRemoteBranches" ) . mockReturnValue ( branches ) ;
97+
98+ outputMergedBranches ( branches , "master" , DEFAULT_CONFIG ) ;
99+ expect ( infoSpy ) . toHaveBeenNthCalledWith ( 1 , "Branches merged into 'master':" ) ;
100+ const branchOutput = [
101+ "feat/TOKEN-800_new-feature <https://test-instance.org/browse/TOKEN-800>" ,
102+ "fix/TOKEN-123_some-fix <https://test-instance.org/browse/TOKEN-123>"
103+ ]
104+ expect ( infoSpy ) . toHaveBeenNthCalledWith ( 2 , branchOutput . join ( "\n" ) ) ;
105+
106+ const localDelete = `git branch --delete ${ branches . join ( " " ) } ` ;
107+ const remoteDelete = `git push origin --delete ${ branches . join ( " " ) } ` ;
108+ expect ( infoSpy ) . toHaveBeenNthCalledWith ( 3 , "\nRun the following to delete branches:" ) ;
109+ expect ( infoSpy ) . toHaveBeenNthCalledWith ( 4 , `locally:\n ${ localDelete } ` ) ;
110+ expect ( infoSpy ) . toHaveBeenNthCalledWith ( 5 , `remotely:\n ${ remoteDelete } ` ) ;
111+ expect ( infoSpy ) . toHaveBeenCalledTimes ( 5 ) ;
112+ expect ( warnSpy ) . not . toHaveBeenCalled ( ) ;
113+ } ) ;
114+
94115 it ( "should log a message when no branches are merged" , ( ) => {
95116 outputMergedBranches ( [ ] , "master" , DEFAULT_CONFIG ) ;
96117 expect ( infoSpy ) . toHaveBeenCalledWith ( "No branches merged into 'master'." ) ;
0 commit comments