@@ -4,13 +4,14 @@ import { TestRunsService } from './test-runs.service';
44import { PrismaService } from '../prisma/prisma.service' ;
55import { StaticService } from '../shared/static/static.service' ;
66import { PNG } from 'pngjs' ;
7- import { TestStatus } from '@prisma/client' ;
7+ import { TestStatus , Build , TestRun } from '@prisma/client' ;
88import Pixelmatch from 'pixelmatch' ;
99import { CreateTestRequestDto } from '../test/dto/create-test-request.dto' ;
1010import { DiffResult } from './diffResult' ;
1111import { IgnoreAreaDto } from '../test/dto/ignore-area.dto' ;
1212import { EventsGateway } from '../events/events.gateway' ;
1313import { CommentDto } from '../shared/dto/comment.dto' ;
14+ import { BuildDto } from '../builds/dto/build.dto' ;
1415
1516jest . mock ( 'pixelmatch' ) ;
1617
@@ -24,6 +25,8 @@ const initService = async ({
2425 saveImageMock = jest . fn ( ) ,
2526 deleteImageMock = jest . fn ( ) ,
2627 eventNewTestRunMock = jest . fn ( ) ,
28+ eventBuildUpdatedMock = jest . fn ( ) ,
29+ buildFindOneMock = jest . fn ( ) ,
2730} ) => {
2831 const module : TestingModule = await Test . createTestingModule ( {
2932 providers : [
@@ -38,6 +41,9 @@ const initService = async ({
3841 create : testRunCreateMock ,
3942 update : testRunUpdateMock ,
4043 } ,
44+ build : {
45+ findOne : buildFindOneMock ,
46+ }
4147 } ,
4248 } ,
4349 {
@@ -52,6 +58,7 @@ const initService = async ({
5258 provide : EventsGateway ,
5359 useValue : {
5460 newTestRun : eventNewTestRunMock ,
61+ buildUpdated : eventBuildUpdatedMock
5562 } ,
5663 } ,
5764 ] ,
@@ -80,20 +87,33 @@ describe('TestRunsService', () => {
8087 } ) ;
8188
8289 it ( 'reject' , async ( ) => {
83- const id = 'some id' ;
84- const testRunUpdateMock = jest . fn ( ) ;
90+ const testRun = {
91+ id : 'id' ,
92+ imageName : 'imageName' ,
93+ diffTollerancePercent : 12 ,
94+ status : TestStatus . new ,
95+ buildId : 'buildId' ,
96+ testVariationId : 'testVariationId' ,
97+ updatedAt : new Date ( ) ,
98+ createdAt : new Date ( ) ,
99+ name : 'test run name' ,
100+ ignoreAreas : '[]' ,
101+ } ;
102+ const testRunUpdateMock = jest . fn ( ) . mockResolvedValueOnce ( testRun ) ;
85103 service = await initService ( {
86104 testRunUpdateMock,
87105 } ) ;
106+ service . emitUpdateBuildEvent = jest . fn ( ) ;
88107
89- service . reject ( id ) ;
108+ await service . reject ( testRun . id ) ;
90109
91110 expect ( testRunUpdateMock ) . toHaveBeenCalledWith ( {
92- where : { id } ,
111+ where : { id : testRun . id } ,
93112 data : {
94113 status : TestStatus . failed ,
95114 } ,
96115 } ) ;
116+ expect ( service . emitUpdateBuildEvent ) . toBeCalledWith ( testRun . buildId )
97117 } ) ;
98118
99119 describe ( 'approve' , ( ) => {
@@ -126,6 +146,7 @@ describe('TestRunsService', () => {
126146 getImageMock,
127147 } ) ;
128148 service . findOne = testRunFindOneMock ;
149+ service . emitUpdateBuildEvent = jest . fn ( ) ;
129150
130151 await service . approve ( testRun . id ) ;
131152
@@ -153,6 +174,7 @@ describe('TestRunsService', () => {
153174 } ,
154175 } ,
155176 } ) ;
177+ expect ( service . emitUpdateBuildEvent ) . toBeCalledWith ( testRun . buildId )
156178 } ) ;
157179 } ) ;
158180
@@ -556,4 +578,60 @@ describe('TestRunsService', () => {
556578 } ,
557579 } ) ;
558580 } ) ;
581+
582+ it ( 'emitUpdateBuildEvent' , async ( ) => {
583+ const build : Build & {
584+ testRuns : TestRun [ ] ;
585+ } = {
586+ id : 'a9385fc1-884d-4f9f-915e-40da0e7773d5' ,
587+ number : null ,
588+ branchName : 'develop' ,
589+ status : null ,
590+ projectId : 'e0a37894-6f29-478d-b13e-6182fecc715e' ,
591+ updatedAt : new Date ( ) ,
592+ createdAt : new Date ( ) ,
593+ userId : null ,
594+ testRuns : [
595+ {
596+ id : '10fb5e02-64e0-4cf5-9f17-c00ab3c96658' ,
597+ imageName : '1592423768112.screenshot.png' ,
598+ diffName : null ,
599+ diffPercent : null ,
600+ diffTollerancePercent : 1 ,
601+ pixelMisMatchCount : null ,
602+ status : 'new' ,
603+ buildId : '146e7a8d-89f0-4565-aa2c-e61efabb0afd' ,
604+ testVariationId : '3bc4a5bc-006e-4d43-8e4e-eaa132627fca' ,
605+ updatedAt : new Date ( ) ,
606+ createdAt : new Date ( ) ,
607+ name : 'ss2f77' ,
608+ browser : 'chromium' ,
609+ device : null ,
610+ os : null ,
611+ viewport : '1800x1600' ,
612+ baselineName : null ,
613+ ignoreAreas : '[]' ,
614+ comment : 'some comment' ,
615+ } ,
616+ ] ,
617+ } ;
618+ const buildFindOneMock = jest . fn ( ) . mockResolvedValueOnce ( build )
619+ const eventBuildUpdatedMock = jest . fn ( )
620+ service = await initService ( {
621+ buildFindOneMock,
622+ eventBuildUpdatedMock,
623+ } ) ;
624+
625+ await service . emitUpdateBuildEvent ( build . id )
626+
627+ expect ( buildFindOneMock ) . toHaveBeenCalledWith ( {
628+ where : {
629+ id : build . id
630+ } ,
631+ include : {
632+ testRuns : true
633+ }
634+ } )
635+ expect ( eventBuildUpdatedMock ) . toHaveBeenCalledWith ( new BuildDto ( build ) )
636+ } )
559637} ) ;
0 commit comments