@@ -262,6 +262,23 @@ describe('Project create', () => {
262
262
. expect ( 422 , done ) ;
263
263
} ) ;
264
264
265
+ it ( 'should return 422 with wrong format estimation field' , ( done ) => {
266
+ const invalidBody = _ . cloneDeep ( body ) ;
267
+ invalidBody . param . estimation = [
268
+ {
269
+
270
+ } ,
271
+ ] ;
272
+ request ( server )
273
+ . post ( '/v4/projects' )
274
+ . set ( {
275
+ Authorization : `Bearer ${ testUtil . jwts . member } ` ,
276
+ } )
277
+ . send ( invalidBody )
278
+ . expect ( 'Content-Type' , / j s o n / )
279
+ . expect ( 422 , done ) ;
280
+ } ) ;
281
+
265
282
it ( 'should return 201 if error to create direct project' , ( done ) => {
266
283
const validBody = _ . cloneDeep ( body ) ;
267
284
validBody . param . templateId = 3 ;
@@ -469,6 +486,143 @@ describe('Project create', () => {
469
486
} ) ;
470
487
} ) ;
471
488
489
+ it ( 'should return 201 if valid user and data (with estimation)' , ( done ) => {
490
+ const validBody = _ . cloneDeep ( body ) ;
491
+ validBody . param . estimation = [
492
+ {
493
+ conditions : '( HAS_DESIGN_DELIVERABLE && HAS_ZEPLIN_APP_ADDON && CA_NEEDED)' ,
494
+ price : 6 ,
495
+ minTime : 2 ,
496
+ maxTime : 2 ,
497
+ metadata : {
498
+ deliverable : 'design' ,
499
+ } ,
500
+ buildingBlockKey : 'ZEPLIN_APP_ADDON_CA' ,
501
+ } ,
502
+ {
503
+ conditions : '( HAS_DESIGN_DELIVERABLE && COMPREHENSIVE_DESIGN && TWO_TARGET_DEVICES'
504
+ + ' && SCREENS_COUNT_SMALL && CA_NEEDED )' ,
505
+ price : 95 ,
506
+ minTime : 14 ,
507
+ maxTime : 14 ,
508
+ metadata : {
509
+ deliverable : 'design' ,
510
+ } ,
511
+ buildingBlockKey : 'SMALL_COMP_DESIGN_TWO_DEVICE_CA' ,
512
+ } ,
513
+ {
514
+ conditions : '( HAS_DEV_DELIVERABLE && (ONLY_ONE_OS_MOBILE || ONLY_ONE_OS_DESKTOP'
515
+ + ' || ONLY_ONE_OS_PROGRESSIVE) && SCREENS_COUNT_SMALL && CA_NEEDED)' ,
516
+ price : 50 ,
517
+ minTime : 35 ,
518
+ maxTime : 35 ,
519
+ metadata : {
520
+ deliverable : 'dev-qa' ,
521
+ } ,
522
+ buildingBlockKey : 'SMALL_DEV_ONE_OS_CA' ,
523
+ } ,
524
+ {
525
+ conditions : '( HAS_DEV_DELIVERABLE && HAS_SSO_INTEGRATION_ADDON && CA_NEEDED)' ,
526
+ price : 80 ,
527
+ minTime : 5 ,
528
+ maxTime : 5 ,
529
+ metadata : {
530
+ deliverable : 'dev-qa' ,
531
+ } ,
532
+ buildingBlockKey : 'HAS_SSO_INTEGRATION_ADDON_CA' ,
533
+ } ,
534
+ {
535
+ conditions : '( HAS_DEV_DELIVERABLE && HAS_CHECKMARX_SCANNING_ADDON && CA_NEEDED)' ,
536
+ price : 4 ,
537
+ minTime : 10 ,
538
+ maxTime : 10 ,
539
+ metadata : {
540
+ deliverable : 'dev-qa' ,
541
+ } ,
542
+ buildingBlockKey : 'HAS_CHECKMARX_SCANNING_ADDON_CA' ,
543
+ } ,
544
+ {
545
+ conditions : '( HAS_DEV_DELIVERABLE && HAS_UNIT_TESTING_ADDON && CA_NEEDED)' ,
546
+ price : 90 ,
547
+ minTime : 12 ,
548
+ maxTime : 12 ,
549
+ metadata : {
550
+ deliverable : 'dev-qa' ,
551
+ } ,
552
+ buildingBlockKey : 'HAS_UNIT_TESTING_ADDON_CA' ,
553
+ } ,
554
+ ] ;
555
+ validBody . param . templateId = 3 ;
556
+ const mockHttpClient = _ . merge ( testUtil . mockHttpClient , {
557
+ post : ( ) => Promise . resolve ( {
558
+ status : 200 ,
559
+ data : {
560
+ id : 'requesterId' ,
561
+ version : 'v3' ,
562
+ result : {
563
+ success : true ,
564
+ status : 200 ,
565
+ content : {
566
+ projectId : 128 ,
567
+ } ,
568
+ } ,
569
+ } ,
570
+ } ) ,
571
+ } ) ;
572
+ sandbox . stub ( util , 'getHttpClient' , ( ) => mockHttpClient ) ;
573
+ request ( server )
574
+ . post ( '/v4/projects' )
575
+ . set ( {
576
+ Authorization : `Bearer ${ testUtil . jwts . member } ` ,
577
+ } )
578
+ . send ( validBody )
579
+ . expect ( 'Content-Type' , / j s o n / )
580
+ . expect ( 201 )
581
+ . end ( ( err , res ) => {
582
+ if ( err ) {
583
+ done ( err ) ;
584
+ } else {
585
+ const resJson = res . body . result . content ;
586
+ should . exist ( resJson ) ;
587
+ should . exist ( resJson . billingAccountId ) ;
588
+ should . exist ( resJson . name ) ;
589
+ resJson . directProjectId . should . be . eql ( 128 ) ;
590
+ resJson . status . should . be . eql ( 'draft' ) ;
591
+ resJson . type . should . be . eql ( body . param . type ) ;
592
+ resJson . version . should . be . eql ( 'v3' ) ;
593
+ resJson . members . should . have . lengthOf ( 1 ) ;
594
+ resJson . members [ 0 ] . role . should . be . eql ( 'customer' ) ;
595
+ resJson . members [ 0 ] . userId . should . be . eql ( 40051331 ) ;
596
+ resJson . members [ 0 ] . projectId . should . be . eql ( resJson . id ) ;
597
+ resJson . members [ 0 ] . isPrimary . should . be . truthy ;
598
+ resJson . bookmarks . should . have . lengthOf ( 1 ) ;
599
+ resJson . bookmarks [ 0 ] . title . should . be . eql ( 'title1' ) ;
600
+ resJson . bookmarks [ 0 ] . address . should . be . eql ( 'http://www.address.com' ) ;
601
+ // Check that activity fields are set
602
+ resJson . lastActivityUserId . should . be . eql ( '40051331' ) ;
603
+ resJson . lastActivityAt . should . be . not . null ;
604
+ server . services . pubsub . publish . calledWith ( 'project.draft-created' ) . should . be . true ;
605
+
606
+ // Check new ProjectEstimation records are created.
607
+ models . ProjectEstimation . findAll ( {
608
+ where : {
609
+ projectId : resJson . id ,
610
+ } ,
611
+ } ) . then ( ( projectEstimations ) => {
612
+ projectEstimations . length . should . be . eql ( 6 ) ;
613
+ projectEstimations [ 0 ] . conditions . should . be . eql (
614
+ '( HAS_DESIGN_DELIVERABLE && HAS_ZEPLIN_APP_ADDON && CA_NEEDED)' ) ;
615
+ projectEstimations [ 0 ] . price . should . be . eql ( 6 ) ;
616
+ projectEstimations [ 0 ] . minTime . should . be . eql ( 2 ) ;
617
+ projectEstimations [ 0 ] . maxTime . should . be . eql ( 2 ) ;
618
+ projectEstimations [ 0 ] . metadata . deliverable . should . be . eql ( 'design' ) ;
619
+ projectEstimations [ 0 ] . buildingBlockKey . should . be . eql ( 'ZEPLIN_APP_ADDON_CA' ) ;
620
+ done ( ) ;
621
+ } ) ;
622
+ }
623
+ } ) ;
624
+ } ) ;
625
+
472
626
xit ( 'should return 201 if valid user and data (using Bearer userId_<userId>)' , ( done ) => {
473
627
const mockHttpClient = _ . merge ( testUtil . mockHttpClient , {
474
628
post : ( ) => Promise . resolve ( {
0 commit comments