@@ -25,6 +25,8 @@ afterAll(() => {
2525 disableVerboseLogging ( ) ;
2626} ) ;
2727
28+ const gitUrl = "https://github.com/CatalystCode/spk.git" ;
29+
2830const mockValues : ICommandOptions = {
2931 buildScriptUrl : "buildScriptUrl" ,
3032 devopsProject : "azDoProject" ,
@@ -41,13 +43,22 @@ const mockMissingValues: ICommandOptions = {
4143 devopsProject : undefined ,
4244 orgName : undefined ,
4345 personalAccessToken : undefined ,
44- pipelineName : undefined ,
45- repoName : undefined ,
46- repoUrl : undefined ,
46+ pipelineName : "pipelineName" ,
47+ repoName : "repoName" ,
48+ repoUrl : "" ,
4749 yamlFileBranch : ""
4850} ;
4951
50- const gitUrl = "https://github.com/CatalystCode/spk.git" ;
52+ const nullValues : ICommandOptions = {
53+ buildScriptUrl : undefined ,
54+ devopsProject : undefined ,
55+ orgName : undefined ,
56+ personalAccessToken : undefined ,
57+ pipelineName : "pipelineName" ,
58+ repoName : "repoName" ,
59+ repoUrl : "https://github.com" ,
60+ yamlFileBranch : ""
61+ } ;
5162
5263describe ( "test valid function" , ( ) => {
5364 it ( "negative test" , async ( ) => {
@@ -71,13 +82,14 @@ describe("test fetchValidateValues function", () => {
7182 }
7283 } ) ;
7384 it ( "SPK Config's azure_devops do not have value" , ( ) => {
74- const values = fetchValidateValues ( mockValues , gitUrl , {
75- azure_devops : { }
76- } ) ;
77- expect ( values ) . toEqual ( mockValues ) ;
85+ expect ( ( ) => {
86+ fetchValidateValues ( mockMissingValues , gitUrl , {
87+ azure_devops : { }
88+ } ) ;
89+ } ) . toThrow ( `Repo url not defined` ) ;
7890 } ) ;
7991 it ( "SPK Config's azure_devops do not have value and command line does not have values" , ( ) => {
80- const values = fetchValidateValues ( mockMissingValues , gitUrl , {
92+ const values = fetchValidateValues ( nullValues , gitUrl , {
8193 azure_devops : { }
8294 } ) ;
8395 expect ( values ) . toBeNull ( ) ;
@@ -106,6 +118,30 @@ describe("installLifecyclePipeline and execute tests", () => {
106118 expect ( exitFn ) . toBeCalledTimes ( 1 ) ;
107119 expect ( exitFn . mock . calls ) . toEqual ( [ [ 0 ] ] ) ;
108120 } ) ;
121+ it ( "test execute function: missing repo url and pipeline name" , async ( ) => {
122+ const exitFn = jest . fn ( ) ;
123+ await execute ( mockMissingValues , "" , exitFn ) ;
124+ expect ( exitFn ) . toBeCalledTimes ( 1 ) ;
125+ expect ( exitFn . mock . calls ) . toEqual ( [ [ 1 ] ] ) ;
126+ } ) ;
127+ it ( "test execute function: github repos not supported" , async ( ) => {
128+ const exitFn = jest . fn ( ) ;
129+ await execute ( nullValues , "" , exitFn ) ;
130+ expect ( exitFn ) . toBeCalledTimes ( 1 ) ;
131+ expect ( exitFn . mock . calls ) . toEqual ( [ [ 1 ] ] ) ;
132+ } ) ;
133+ it ( "test execute function: missing repo url and pipeline name" , async ( ) => {
134+ const exitFn = jest . fn ( ) ;
135+ await execute ( mockMissingValues , "" , exitFn ) ;
136+ expect ( exitFn ) . toBeCalledTimes ( 1 ) ;
137+ expect ( exitFn . mock . calls ) . toEqual ( [ [ 1 ] ] ) ;
138+ } ) ;
139+ it ( "test execute function: github repos not supported" , async ( ) => {
140+ const exitFn = jest . fn ( ) ;
141+ await execute ( nullValues , "" , exitFn ) ;
142+ expect ( exitFn ) . toBeCalledTimes ( 1 ) ;
143+ expect ( exitFn . mock . calls ) . toEqual ( [ [ 1 ] ] ) ;
144+ } ) ;
109145 it ( "should create a pipeline" , async ( ) => {
110146 ( createPipelineForDefinition as jest . Mock ) . mockReturnValue ( { id : 10 } ) ;
111147 try {
0 commit comments