@@ -25,6 +25,7 @@ const initModule = async ({
2525 testRunCreateMock = jest . fn ( ) ,
2626 testRunFindMany = jest . fn ( ) ,
2727 testRunDeleteMock = jest . fn ( ) ,
28+ testRuncalCulateDiffMock = jest . fn ( ) ,
2829 $executeRawMock = jest . fn ( ) ,
2930} ) => {
3031 const module : TestingModule = await Test . createTestingModule ( {
@@ -49,6 +50,7 @@ const initModule = async ({
4950 useValue : {
5051 delete : testRunDeleteMock ,
5152 create : testRunCreateMock ,
53+ calculateDiff : testRuncalCulateDiffMock ,
5254 } ,
5355 } ,
5456 {
@@ -369,13 +371,14 @@ describe('TestVariationsService', () => {
369371 } ) ;
370372
371373 it ( 'merge' , async ( ) => {
372- const mergedBranch = 'develop' ;
374+ const fromBranch = 'develop' ;
375+ const targetBranch = 'test' ;
373376 const project : Project = TEST_PROJECT ;
374377 const build : Build = {
375378 id : 'a9385fc1-884d-4f9f-915e-40da0e7773d5' ,
376379 ciBuildId : 'ciBuildId' ,
377380 number : null ,
378- branchName : project . mainBranchName ,
381+ branchName : targetBranch ,
379382 status : null ,
380383 projectId : project . id ,
381384 updatedAt : new Date ( ) ,
@@ -397,7 +400,7 @@ describe('TestVariationsService', () => {
397400 comment : 'some comment' ,
398401 createdAt : new Date ( ) ,
399402 updatedAt : new Date ( ) ,
400- branchName : mergedBranch ,
403+ branchName : fromBranch ,
401404 } ;
402405 const testVariationSecond : TestVariation = {
403406 id : '123' ,
@@ -413,7 +416,7 @@ describe('TestVariationsService', () => {
413416 comment : 'some comment' ,
414417 createdAt : new Date ( ) ,
415418 updatedAt : new Date ( ) ,
416- branchName : mergedBranch ,
419+ branchName : fromBranch ,
417420 } ;
418421 const testVariationNoBaseline : TestVariation = {
419422 id : '123' ,
@@ -429,9 +432,9 @@ describe('TestVariationsService', () => {
429432 comment : 'some comment' ,
430433 createdAt : new Date ( ) ,
431434 updatedAt : new Date ( ) ,
432- branchName : mergedBranch ,
435+ branchName : fromBranch ,
433436 } ;
434- const testVariationMainBranch : TestVariation = {
437+ const testVariationSourceBranch : TestVariation = {
435438 id : '123' ,
436439 projectId : project . id ,
437440 name : 'Test name' ,
@@ -445,9 +448,12 @@ describe('TestVariationsService', () => {
445448 comment : 'some comment' ,
446449 createdAt : new Date ( ) ,
447450 updatedAt : new Date ( ) ,
448- branchName : project . mainBranchName ,
451+ branchName : fromBranch ,
452+ } ;
453+ const testVariationTargetBranch : TestVariation = {
454+ ...testVariationSourceBranch ,
455+ branchName : targetBranch ,
449456 } ;
450- const projectFindUniqueMock = jest . fn ( ) . mockResolvedValueOnce ( project ) ;
451457 const buildFindOrCreateMock = jest . fn ( ) . mockResolvedValueOnce ( build ) ;
452458 const variationFindManyMock = jest
453459 . fn ( )
@@ -459,38 +465,38 @@ describe('TestVariationsService', () => {
459465 const getImageMock = jest . fn ( ) . mockReturnValueOnce ( image ) . mockReturnValueOnce ( image ) . mockReturnValueOnce ( null ) ;
460466 const testRunCreateMock = jest . fn ( ) ;
461467 const buildUpdateMock = jest . fn ( ) ;
468+ const testRuncalCulateDiffMock = jest . fn ( ) ;
462469 const service = await initModule ( {
463- projectFindUniqueMock,
464470 buildFindOrCreateMock,
465471 buildUpdateMock,
466472 testRunCreateMock,
473+ testRuncalCulateDiffMock,
467474 variationFindManyMock,
468475 getImageMock,
469476 } ) ;
470477 service . find = jest
471478 . fn ( )
472- . mockResolvedValueOnce ( testVariationMainBranch )
473- . mockResolvedValueOnce ( testVariationMainBranch ) ;
479+ . mockResolvedValueOnce ( testVariationSourceBranch )
480+ . mockResolvedValueOnce ( testVariationSourceBranch ) ;
481+ service . create = jest
482+ . fn ( )
483+ . mockResolvedValueOnce ( testVariationTargetBranch )
484+ . mockResolvedValueOnce ( testVariationTargetBranch ) ;
474485
475- await service . merge ( project . id , mergedBranch ) ;
486+ await service . merge ( project . id , fromBranch , targetBranch ) ;
476487
477- expect ( projectFindUniqueMock ) . toHaveBeenCalledWith ( { where : { id : project . id } } ) ;
478488 expect ( buildFindOrCreateMock ) . toHaveBeenCalledWith ( {
479- branchName : project . mainBranchName ,
489+ branchName : targetBranch ,
480490 projectId : project . id ,
481491 } ) ;
482- expect ( variationFindManyMock ) . toHaveBeenCalledWith ( {
483- where : { projectId : project . id , branchName : mergedBranch } ,
484- } ) ;
485- expect ( getImageMock ) . toHaveBeenCalledWith ( testVariation . baselineName ) ;
486492 expect ( service . find ) . toHaveBeenNthCalledWith ( 1 , {
487493 name : testVariation . name ,
488494 os : testVariation . os ,
489495 device : testVariation . device ,
490496 browser : testVariation . browser ,
491497 viewport : testVariation . viewport ,
492498 customTags : testVariation . customTags ,
493- branchName : project . mainBranchName ,
499+ branchName : targetBranch ,
494500 projectId : project . id ,
495501 } ) ;
496502 expect ( service . find ) . toHaveBeenNthCalledWith ( 2 , {
@@ -500,14 +506,14 @@ describe('TestVariationsService', () => {
500506 browser : testVariationSecond . browser ,
501507 viewport : testVariationSecond . viewport ,
502508 customTags : testVariationSecond . customTags ,
503- branchName : project . mainBranchName ,
509+ branchName : targetBranch ,
504510 projectId : project . id ,
505511 } ) ;
506-
507512 expect ( testRunCreateMock ) . toHaveBeenNthCalledWith ( 1 , {
508- testVariation : testVariationMainBranch ,
513+ testVariation : testVariationTargetBranch ,
509514 createTestRequestDto : {
510515 ...testVariation ,
516+ branchName : targetBranch ,
511517 buildId : build . id ,
512518 diffTollerancePercent : 0 ,
513519 merge : true ,
@@ -516,9 +522,10 @@ describe('TestVariationsService', () => {
516522 imageBuffer : PNG . sync . write ( image ) ,
517523 } ) ;
518524 expect ( testRunCreateMock ) . toHaveBeenNthCalledWith ( 2 , {
519- testVariation : testVariationMainBranch ,
525+ testVariation : testVariationTargetBranch ,
520526 createTestRequestDto : {
521527 ...testVariationSecond ,
528+ branchName : targetBranch ,
522529 buildId : build . id ,
523530 diffTollerancePercent : 0 ,
524531 merge : true ,
0 commit comments