@@ -9,17 +9,25 @@ const Config = require('../../src/Config');
99describe ( 'Base' , function ( ) {
1010 beforeEach ( function ( ) {
1111 const repoConfig = {
12+ getString ( key ) {
13+ const defaultConfig = Config . getConfigDefault ( ) ;
14+ return defaultConfig [ key ] || true ;
15+ } ,
1216 setString ( ) {
1317 return Promise . resolve ( ) ;
1418 }
1519 } ;
1620 this . repo = {
1721 config ( ) {
1822 return Promise . resolve ( repoConfig ) ;
23+ } ,
24+ createBranch ( ) {
25+ return Promise . resolve ( ) ;
26+ } ,
27+ getBranchCommit ( ) {
28+ return Promise . resolve ( { id ( ) { return '12345' ; } } ) ;
1929 }
2030 } ;
21-
22- spyOn ( NodeGit . Branch , 'lookup' ) . and . returnValue ( Promise . resolve ( ) ) ;
2331 } ) ;
2432
2533 it ( 'should be able to require Base' , function ( ) {
@@ -34,6 +42,7 @@ describe('Base', function() {
3442
3543 describe ( 'init' , function ( ) {
3644 it ( 'should throw error if no repository is passed' , function ( done ) {
45+ spyOn ( NodeGit . Branch , 'lookup' ) . and . returnValue ( Promise . resolve ( ) ) ;
3746 return Base . init ( )
3847 . then ( jasmine . fail )
3948 . catch ( ( reason ) => {
@@ -43,6 +52,7 @@ describe('Base', function() {
4352 } ) ;
4453
4554 it ( 'should return new flow object if repository is passed' , function ( done ) {
55+ spyOn ( NodeGit . Branch , 'lookup' ) . and . returnValue ( Promise . resolve ( ) ) ;
4656 const defaultConfig = Config . getConfigDefault ( ) ;
4757 return Base . init ( this . repo , defaultConfig )
4858 . then ( ( flow ) => {
@@ -56,12 +66,57 @@ describe('Base', function() {
5666 done ( ) ;
5767 } ) ;
5868 } ) ;
69+
70+ it ( 'develop branch should exist after initialization' , function ( done ) {
71+ spyOn ( NodeGit . Branch , 'lookup' ) . and . returnValue ( Promise . resolve ( ) ) ;
72+ const defaultConfig = Config . getConfigDefault ( ) ;
73+ return Base . init ( this . repo , defaultConfig )
74+ . then ( ( ) => Base . developBranchExists ( this . repo ) )
75+ . then ( ( exists ) => {
76+ expect ( exists ) . toBeTruthy ( ) ;
77+ done ( ) ;
78+ } ) ;
79+ } ) ;
80+
81+ it ( 'develop branch should not exist after initialization and delete develop branch' , function ( done ) {
82+ const defaultConfig = Config . getConfigDefault ( ) ;
83+ spyOn ( NodeGit . Branch , 'lookup' ) . and . callFake ( ( repo , branchName ) => {
84+ if ( branchName === defaultConfig [ 'gitflow.branch.develop' ] ) {
85+ return Promise . reject ( new Error ( 'Could not find branch' ) ) ;
86+ }
87+ return Promise . resolve ( ) ;
88+ } ) ;
89+ return Base . init ( this . repo , defaultConfig )
90+ . then ( ( ) => Base . developBranchExists ( this . repo ) )
91+ . then ( ( exists ) => {
92+ expect ( exists ) . toBeFalsy ( ) ;
93+ done ( ) ;
94+ } ) ;
95+ } ) ;
96+
97+ it ( 'master branch should not exist after initialization and delete master branch' , function ( done ) {
98+ const defaultConfig = Config . getConfigDefault ( ) ;
99+ spyOn ( NodeGit . Branch , 'lookup' ) . and . callFake ( ( repo , branchName ) => {
100+ if ( branchName === defaultConfig [ 'gitflow.branch.master' ] ) {
101+ return Promise . reject ( new Error ( 'Could not find branch' ) ) ;
102+ }
103+ return Promise . resolve ( ) ;
104+ } ) ;
105+ return Base . masterBranchExists ( this . repo )
106+ . then ( ( exists ) => {
107+ expect ( exists ) . toBeFalsy ( ) ;
108+ done ( ) ;
109+ } ) ;
110+ } ) ;
59111 } ) ;
60112
61113 describe ( 'open' , function ( ) {
114+ beforeEach ( function ( ) {
115+ spyOn ( NodeGit . Branch , 'lookup' ) . and . returnValue ( Promise . resolve ( ) ) ;
116+ } ) ;
117+
62118 it ( 'should throw error if no repository is passed' , function ( done ) {
63119 return Base . open ( )
64- . then ( jasmine . fail )
65120 . catch ( ( reason ) => {
66121 expect ( reason ) . toEqual ( jasmine . any ( Error ) ) ;
67122 done ( ) ;
@@ -72,7 +127,6 @@ describe('Base', function() {
72127 spyOn ( Base , 'isInitialized' ) . and . returnValue ( Promise . resolve ( false ) ) ;
73128
74129 return Base . open ( this . repo )
75- . then ( jasmine . fail )
76130 . catch ( ( reason ) => {
77131 expect ( reason ) . toEqual ( jasmine . any ( Error ) ) ;
78132 done ( ) ;
0 commit comments