@@ -493,7 +493,7 @@ describe('TestRunsService', () => {
493493 expect ( eventTestRunUpdatedMock ) . toHaveBeenCalledWith ( testRun ) ;
494494 } ) ;
495495
496- it ( 'postTestRun' , async ( ) => {
496+ describe ( 'postTestRun' , ( ) => {
497497 const createTestRequestDto : CreateTestRequestDto = {
498498 buildId : 'buildId' ,
499499 projectId : 'projectId' ,
@@ -522,43 +522,97 @@ describe('TestRunsService', () => {
522522 updatedAt : new Date ( ) ,
523523 branchName : 'master' ,
524524 } ;
525- const testRun : TestRun = generateTestRun ( ) ;
526- const projectFindUniqueMock = jest . fn ( ) . mockResolvedValueOnce ( TEST_PROJECT ) ;
527- const testVariationFindMock = jest . fn ( ) . mockResolvedValueOnce ( testVariation ) ;
528- const testRunFindManyMock = jest . fn ( ) . mockResolvedValueOnce ( [ testRun ] ) ;
529- const deleteMock = jest . fn ( ) ;
530- const createMock = jest . fn ( ) . mockResolvedValueOnce ( testRun ) ;
531- const service = await initService ( {
532- projectFindUniqueMock,
533- testVariationFindMock,
534- testRunFindManyMock,
525+
526+ it ( 'default' , async ( ) => {
527+ const testRun : TestRun = generateTestRun ( ) ;
528+ const projectFindUniqueMock = jest . fn ( ) . mockResolvedValueOnce ( TEST_PROJECT ) ;
529+ const testVariationFindMock = jest . fn ( ) . mockResolvedValueOnce ( testVariation ) ;
530+ const testRunFindManyMock = jest . fn ( ) . mockResolvedValueOnce ( [ testRun ] ) ;
531+ const deleteMock = jest . fn ( ) ;
532+ const createMock = jest . fn ( ) . mockResolvedValueOnce ( testRun ) ;
533+ const service = await initService ( {
534+ projectFindUniqueMock,
535+ testVariationFindMock,
536+ testRunFindManyMock,
537+ } ) ;
538+ service . delete = deleteMock ;
539+ service . create = createMock ;
540+ service . calculateDiff = jest . fn ( ) . mockResolvedValueOnce ( testRun ) ;
541+ service [ 'tryAutoApproveByPastBaselines' ] = jest . fn ( ) . mockResolvedValueOnce ( testRun ) ;
542+ service [ 'tryAutoApproveByNewBaselines' ] = jest . fn ( ) . mockResolvedValueOnce ( testRun ) ;
543+ const baselineData : BaselineDataDto = {
544+ ...getTestVariationUniqueData ( createTestRequestDto ) ,
545+ branchName : createTestRequestDto . branchName ,
546+ } ;
547+
548+ await service . postTestRun ( { createTestRequestDto, imageBuffer } ) ;
549+
550+ expect ( testVariationFindMock ) . toHaveBeenCalledWith ( createTestRequestDto ) ;
551+ expect ( testRunFindManyMock ) . toHaveBeenCalledWith ( {
552+ where : {
553+ buildId : createTestRequestDto . buildId ,
554+ ...baselineData ,
555+ NOT : { OR : [ { status : TestStatus . approved } , { status : TestStatus . autoApproved } ] } ,
556+ } ,
557+ } ) ;
558+ expect ( deleteMock ) . toHaveBeenCalledWith ( testRun . id ) ;
559+ expect ( createMock ) . toHaveBeenCalledWith ( { testVariation, createTestRequestDto, imageBuffer } ) ;
560+ expect ( service . calculateDiff ) . toHaveBeenCalledWith ( createTestRequestDto . projectId , testRun ) ;
561+ expect ( service [ 'tryAutoApproveByPastBaselines' ] ) . toHaveBeenCalledWith ( { testVariation, testRun } ) ;
562+ expect ( service [ 'tryAutoApproveByNewBaselines' ] ) . toHaveBeenCalledWith ( { testVariation, testRun } ) ;
563+ expect ( mocked ( TestRunResultDto ) ) . toHaveBeenCalledWith ( testRun , testVariation ) ;
535564 } ) ;
536- service . delete = deleteMock ;
537- service . create = createMock ;
538- service . calculateDiff = jest . fn ( ) . mockResolvedValueOnce ( testRun ) ;
539- service [ 'tryAutoApproveByPastBaselines' ] = jest . fn ( ) . mockResolvedValueOnce ( testRun ) ;
540- service [ 'tryAutoApproveByNewBaselines' ] = jest . fn ( ) . mockResolvedValueOnce ( testRun ) ;
541- const baselineData : BaselineDataDto = {
542- ...getTestVariationUniqueData ( createTestRequestDto ) ,
543- branchName : createTestRequestDto . branchName ,
544- } ;
545565
546- await service . postTestRun ( { createTestRequestDto, imageBuffer } ) ;
566+ it ( 'with baseLineName' , async ( ) => {
567+ const testRun : TestRun = generateTestRun ( ) ;
568+ const projectFindUniqueMock = jest . fn ( ) . mockResolvedValueOnce ( TEST_PROJECT ) ;
569+ const testVariationFindMock = jest . fn ( ) . mockResolvedValueOnce ( testVariation ) ;
570+ const testRunFindManyMock = jest . fn ( ) . mockResolvedValueOnce ( [ testRun ] ) ;
571+ const deleteMock = jest . fn ( ) ;
572+ const createMock = jest . fn ( ) . mockResolvedValueOnce ( testRun ) ;
573+ const service = await initService ( {
574+ projectFindUniqueMock,
575+ testVariationFindMock,
576+ testRunFindManyMock,
577+ } ) ;
578+ service . delete = deleteMock ;
579+ service . create = createMock ;
580+ service . calculateDiff = jest . fn ( ) . mockResolvedValueOnce ( testRun ) ;
581+ service [ 'tryAutoApproveByPastBaselines' ] = jest . fn ( ) . mockResolvedValueOnce ( testRun ) ;
582+ service [ 'tryAutoApproveByNewBaselines' ] = jest . fn ( ) . mockResolvedValueOnce ( testRun ) ;
583+ const baselineData : BaselineDataDto = {
584+ ...getTestVariationUniqueData ( createTestRequestDto ) ,
585+ branchName : createTestRequestDto . branchName ,
586+ } ;
587+ const createTestRunWithBaselineDto : CreateTestRequestDto = {
588+ ...createTestRequestDto ,
589+ baselineBranchName : 'baseline-branch' ,
590+ } ;
547591
548- expect ( testVariationFindMock ) . toHaveBeenCalledWith ( createTestRequestDto ) ;
549- expect ( testRunFindManyMock ) . toHaveBeenCalledWith ( {
550- where : {
551- buildId : createTestRequestDto . buildId ,
552- ...baselineData ,
553- NOT : { OR : [ { status : TestStatus . approved } , { status : TestStatus . autoApproved } ] } ,
554- } ,
592+ await service . postTestRun ( { createTestRequestDto : createTestRunWithBaselineDto , imageBuffer } ) ;
593+
594+ expect ( testVariationFindMock ) . toHaveBeenCalledWith ( {
595+ ...createTestRunWithBaselineDto ,
596+ sourceBranch : createTestRunWithBaselineDto . baselineBranchName ,
597+ } ) ;
598+ expect ( testRunFindManyMock ) . toHaveBeenCalledWith ( {
599+ where : {
600+ buildId : createTestRequestDto . buildId ,
601+ ...baselineData ,
602+ NOT : { OR : [ { status : TestStatus . approved } , { status : TestStatus . autoApproved } ] } ,
603+ } ,
604+ } ) ;
605+ expect ( deleteMock ) . toHaveBeenCalledWith ( testRun . id ) ;
606+ expect ( createMock ) . toHaveBeenCalledWith ( {
607+ testVariation,
608+ createTestRequestDto : createTestRunWithBaselineDto ,
609+ imageBuffer,
610+ } ) ;
611+ expect ( service . calculateDiff ) . toHaveBeenCalledWith ( createTestRequestDto . projectId , testRun ) ;
612+ expect ( service [ 'tryAutoApproveByPastBaselines' ] ) . toHaveBeenCalledWith ( { testVariation, testRun } ) ;
613+ expect ( service [ 'tryAutoApproveByNewBaselines' ] ) . toHaveBeenCalledWith ( { testVariation, testRun } ) ;
614+ expect ( mocked ( TestRunResultDto ) ) . toHaveBeenCalledWith ( testRun , testVariation ) ;
555615 } ) ;
556- expect ( deleteMock ) . toHaveBeenCalledWith ( testRun . id ) ;
557- expect ( createMock ) . toHaveBeenCalledWith ( { testVariation, createTestRequestDto, imageBuffer } ) ;
558- expect ( service . calculateDiff ) . toHaveBeenCalledWith ( createTestRequestDto . projectId , testRun ) ;
559- expect ( service [ 'tryAutoApproveByPastBaselines' ] ) . toHaveBeenCalledWith ( { testVariation, testRun } ) ;
560- expect ( service [ 'tryAutoApproveByNewBaselines' ] ) . toHaveBeenCalledWith ( { testVariation, testRun } ) ;
561- expect ( mocked ( TestRunResultDto ) ) . toHaveBeenCalledWith ( testRun , testVariation ) ;
562616 } ) ;
563617
564618 describe ( 'tryAutoApproveByNewBaselines' , ( ) => {
0 commit comments