@@ -3,7 +3,6 @@ import emoji from 'node-emoji';
33
44import { AddAction } from '../../actions/add.action' ;
55import * as projectBuilder from '../../core/project/builder/project.builder' ;
6- import * as projectQuestionsBuilder from '../../core/project/builder/questions.builder' ;
76import { ProjectRepository } from '../../core/project/persistence/repository' ;
87import { Project } from '../../core/project/project.entity' ;
98import { OpenVSCode } from '../../core/project/tasks/open-editor/vscode.task' ;
@@ -15,29 +14,58 @@ jest.mock('../../core/project/builder/questions.builder');
1514const buildProject = projectBuilder . buildProject as jest . MockedFunction <
1615 typeof projectBuilder . buildProject
1716> ;
18- const buildProjectQuestions = projectQuestionsBuilder . buildProjectQuestions as jest . MockedFunction <
19- typeof projectQuestionsBuilder . buildProjectQuestions
20- > ;
2117
2218describe ( 'Add action' , ( ) => {
2319 describe ( 'Setup' , ( ) => {
24- it ( 'should return a function calling handle with inputs' , ( ) => {
25- const action = new AddAction ( { } as ProjectRepository ) ;
26- action . handle = jest . fn ( ) ;
27- const setup = action . setup ( ) ;
20+ describe ( 'When occurr some error handling action' , ( ) => {
21+ it ( 'should exit process with code 1' , async ( ) => {
22+ global . process . exit = jest . fn ( ) as any ;
23+ const action = new AddAction ( { } as ProjectRepository ) ;
24+ action . handle = jest . fn ( ) . mockRejectedValue ( new Error ( ) ) ;
25+
26+ const setup = action . setup ( ) ;
27+
28+ const path = '/var/www/html' ;
29+ const alias = 'fun' ;
30+
31+ const command = { path } ;
32+
33+ await setup ( alias , command ) ;
34+
35+ expect ( action . handle ) . toHaveBeenCalledTimes ( 1 ) ;
36+ expect ( action . handle ) . toHaveBeenCalledWith ( [
37+ { name : 'alias' , value : alias } ,
38+ { name : 'path' , value : path } ,
39+ ] ) ;
40+
41+ expect ( process . exit ) . toHaveBeenCalledTimes ( 1 ) ;
42+ expect ( process . exit ) . toHaveBeenCalledWith ( 1 ) ;
43+ } ) ;
44+ } ) ;
45+
46+ describe ( 'When handle with success' , ( ) => {
47+ it ( 'should return a function calling handle with inputs' , ( ) => {
48+ global . process . exit = jest . fn ( ) as any ;
49+
50+ const action = new AddAction ( { } as ProjectRepository ) ;
51+ action . handle = jest . fn ( ) ;
52+ const setup = action . setup ( ) ;
53+
54+ const path = '/var/www/html' ;
55+ const alias = 'fun' ;
2856
29- const path = '/var/www/html' ;
30- const alias = 'fun' ;
57+ const command = { path } ;
3158
32- const command = { path } ;
59+ setup ( alias , command ) ;
3360
34- setup ( alias , command ) ;
61+ expect ( action . handle ) . toHaveBeenCalledTimes ( 1 ) ;
62+ expect ( action . handle ) . toHaveBeenCalledWith ( [
63+ { name : 'alias' , value : alias } ,
64+ { name : 'path' , value : path } ,
65+ ] ) ;
3566
36- expect ( action . handle ) . toHaveBeenCalledTimes ( 1 ) ;
37- expect ( action . handle ) . toHaveBeenCalledWith ( [
38- { name : 'alias' , value : alias } ,
39- { name : 'path' , value : path } ,
40- ] ) ;
67+ expect ( process . exit ) . not . toHaveBeenCalled ( ) ;
68+ } ) ;
4169 } ) ;
4270 } ) ;
4371
@@ -133,14 +161,12 @@ describe('Add action', () => {
133161
134162 describe ( 'When project not exists' , ( ) => {
135163 const path = `${ __dirname } /../fixtures` ;
136- const questions = [ 'fake-questions' ] ;
137164 let action : AddAction ;
138165
139166 describe ( 'When persist project with success' , ( ) => {
140167 let project : Project ;
141168 beforeAll ( async ( ) => {
142169 global . console . log = jest . fn ( ) ;
143- buildProjectQuestions . mockReturnValue ( questions ) ;
144170
145171 repositoryMock . create . mockResolvedValue ( true ) ;
146172
@@ -160,16 +186,8 @@ describe('Add action', () => {
160186 project = projectDefinitionsFactory ( ) ;
161187 } ) ;
162188
163- it ( 'should build questions with project alias' , ( ) => {
164- expect ( buildProjectQuestions ) . toHaveBeenCalled ( ) ;
165- } ) ;
166-
167189 it ( 'should build project with build project questions' , ( ) => {
168- expect ( buildProject ) . toHaveBeenCalledWith (
169- alias ,
170- path ,
171- questions ,
172- ) ;
190+ expect ( buildProject ) . toHaveBeenCalledWith ( alias , path ) ;
173191 } ) ;
174192
175193 it ( 'should persist the built project' , ( ) => {
0 commit comments