11/**
22 * Tests for create.js
33 */
4+ import _ from 'lodash' ;
45import chai from 'chai' ;
56import request from 'supertest' ;
67
@@ -15,6 +16,10 @@ describe('CREATE project type', () => {
1516 . then ( ( ) => models . ProjectType . create ( {
1617 key : 'key1' ,
1718 displayName : 'displayName 1' ,
19+ icon : 'http://example.com/icon1.ico' ,
20+ question : 'question 1' ,
21+ info : 'info 1' ,
22+ aliases : [ 'key-1' , 'key_1' ] ,
1823 createdBy : 1 ,
1924 updatedBy : 1 ,
2025 } ) ) . then ( ( ) => Promise . resolve ( ) ) ,
@@ -26,6 +31,10 @@ describe('CREATE project type', () => {
2631 param : {
2732 key : 'app_dev' ,
2833 displayName : 'Application Development' ,
34+ icon : 'prod-cat-app-icon' ,
35+ info : 'Application Development Info' ,
36+ question : 'What kind of devlopment you need?' ,
37+ aliases : [ 'key-1' , 'key_1' ] ,
2938 } ,
3039 } ;
3140
@@ -67,11 +76,8 @@ describe('CREATE project type', () => {
6776 } ) ;
6877
6978 it ( 'should return 422 for missing key' , ( done ) => {
70- const invalidBody = {
71- param : {
72- displayName : 'displayName' ,
73- } ,
74- } ;
79+ const invalidBody = _ . cloneDeep ( body ) ;
80+ delete invalidBody . param . key ;
7581
7682 request ( server )
7783 . post ( '/v4/projectTypes' )
@@ -84,11 +90,50 @@ describe('CREATE project type', () => {
8490 } ) ;
8591
8692 it ( 'should return 422 for missing displayName' , ( done ) => {
87- const invalidBody = {
88- param : {
89- key : 'key' ,
90- } ,
91- } ;
93+ const invalidBody = _ . cloneDeep ( body ) ;
94+ delete invalidBody . param . displayName ;
95+
96+ request ( server )
97+ . post ( '/v4/projectTypes' )
98+ . set ( {
99+ Authorization : `Bearer ${ testUtil . jwts . admin } ` ,
100+ } )
101+ . send ( invalidBody )
102+ . expect ( 'Content-Type' , / j s o n / )
103+ . expect ( 422 , done ) ;
104+ } ) ;
105+
106+ it ( 'should return 422 for missing icon' , ( done ) => {
107+ const invalidBody = _ . cloneDeep ( body ) ;
108+ delete invalidBody . param . icon ;
109+
110+ request ( server )
111+ . post ( '/v4/projectTypes' )
112+ . set ( {
113+ Authorization : `Bearer ${ testUtil . jwts . admin } ` ,
114+ } )
115+ . send ( invalidBody )
116+ . expect ( 'Content-Type' , / j s o n / )
117+ . expect ( 422 , done ) ;
118+ } ) ;
119+
120+ it ( 'should return 422 for missing question' , ( done ) => {
121+ const invalidBody = _ . cloneDeep ( body ) ;
122+ delete invalidBody . param . question ;
123+
124+ request ( server )
125+ . post ( '/v4/projectTypes' )
126+ . set ( {
127+ Authorization : `Bearer ${ testUtil . jwts . admin } ` ,
128+ } )
129+ . send ( invalidBody )
130+ . expect ( 'Content-Type' , / j s o n / )
131+ . expect ( 422 , done ) ;
132+ } ) ;
133+
134+ it ( 'should return 422 for missing info' , ( done ) => {
135+ const invalidBody = _ . cloneDeep ( body ) ;
136+ delete invalidBody . param . info ;
92137
93138 request ( server )
94139 . post ( '/v4/projectTypes' )
@@ -101,12 +146,8 @@ describe('CREATE project type', () => {
101146 } ) ;
102147
103148 it ( 'should return 422 for duplicated key' , ( done ) => {
104- const invalidBody = {
105- param : {
106- key : 'key1' ,
107- displayName : 'displayName' ,
108- } ,
109- } ;
149+ const invalidBody = _ . cloneDeep ( body ) ;
150+ invalidBody . param . key = 'key1' ;
110151
111152 request ( server )
112153 . post ( '/v4/projectTypes' )
@@ -131,6 +172,10 @@ describe('CREATE project type', () => {
131172 const resJson = res . body . result . content ;
132173 resJson . key . should . be . eql ( body . param . key ) ;
133174 resJson . displayName . should . be . eql ( body . param . displayName ) ;
175+ resJson . icon . should . be . eql ( body . param . icon ) ;
176+ resJson . info . should . be . eql ( body . param . info ) ;
177+ resJson . question . should . be . eql ( body . param . question ) ;
178+ resJson . aliases . should . be . eql ( body . param . aliases ) ;
134179
135180 resJson . createdBy . should . be . eql ( 40051333 ) ; // admin
136181 should . exist ( resJson . createdAt ) ;
@@ -154,6 +199,12 @@ describe('CREATE project type', () => {
154199 . expect ( 201 )
155200 . end ( ( err , res ) => {
156201 const resJson = res . body . result . content ;
202+ resJson . key . should . be . eql ( body . param . key ) ;
203+ resJson . displayName . should . be . eql ( body . param . displayName ) ;
204+ resJson . icon . should . be . eql ( body . param . icon ) ;
205+ resJson . info . should . be . eql ( body . param . info ) ;
206+ resJson . question . should . be . eql ( body . param . question ) ;
207+ resJson . aliases . should . be . eql ( body . param . aliases ) ;
157208 resJson . createdBy . should . be . eql ( 40051336 ) ; // connect admin
158209 resJson . updatedBy . should . be . eql ( 40051336 ) ; // connect admin
159210 done ( ) ;
0 commit comments