@@ -8,12 +8,15 @@ import { TestStatus, TestRun } from '@prisma/client';
88import Pixelmatch from 'pixelmatch' ;
99import { CreateTestRequestDto } from 'src/test/dto/create-test-request.dto' ;
1010import { DiffResult } from './diffResult' ;
11+ import { IgnoreAreaDto } from 'src/test/dto/ignore-area.dto' ;
1112
1213jest . mock ( 'pixelmatch' ) ;
1314
1415const initService = async ( {
16+ testRunDeleteMock = jest . fn ( ) ,
1517 testRunUpdateMock = jest . fn ( ) ,
1618 testRunFindOneMock = jest . fn ( ) ,
19+ testRunFindManyMock = jest . fn ( ) ,
1720 testRunCreateMock = jest . fn ( ) ,
1821 getImageMock = jest . fn ( ) ,
1922 saveImageMock = jest . fn ( ) ,
@@ -26,6 +29,8 @@ const initService = async ({
2629 provide : PrismaService ,
2730 useValue : {
2831 testRun : {
32+ delete : testRunDeleteMock ,
33+ findMany : testRunFindManyMock ,
2934 findOne : testRunFindOneMock ,
3035 create : testRunCreateMock ,
3136 update : testRunUpdateMock ,
@@ -237,67 +242,6 @@ describe('TestRunsService', () => {
237242 } ) ;
238243 } ) ;
239244
240- // it('with deleted baseline', async () => {
241- // const testRun = {
242- // id: 'id',
243- // imageName: 'imageName',
244- // baselineName: 'baselineName',
245- // diffTollerancePercent: 12,
246- // ignoreAreas: '[]',
247- // diffName: null,
248- // };
249- // const testVariation = {
250- // id: '123',
251- // projectId: 'project Id',
252- // name: 'Test name',
253- // baselineName: 'baselineName',
254- // os: 'OS',
255- // browser: 'browser',
256- // viewport: 'viewport',
257- // device: 'device',
258- // ignoreAreas: '[]',
259- // createdAt: new Date(),
260- // updatedAt: new Date(),
261- // };
262- // const createTestRequestDto = initCreateTestRequestDto;
263- // const testRunCreateMock = jest.fn().mockResolvedValueOnce(testRun);
264- // const imageName = 'image name';
265- // const saveImageMock = jest.fn().mockReturnValueOnce(imageName);
266- // const getImageMock = jest.fn().mockReturnValueOnce(null);
267- // service = await initService({ testRunCreateMock, saveImageMock, getImageMock });
268-
269- // await service.create(testVariation, createTestRequestDto);
270-
271- // expect(getImageMock).toHaveBeenCalledWith(testVariation.baselineName);
272- // expect(testRunCreateMock).toHaveBeenCalledWith({
273- // data: {
274- // imageName,
275- // testVariation: {
276- // connect: {
277- // id: testVariation.id,
278- // },
279- // },
280- // build: {
281- // connect: {
282- // id: createTestRequestDto.buildId,
283- // },
284- // },
285- // name: testVariation.name,
286- // browser: testVariation.browser,
287- // device: testVariation.device,
288- // os: testVariation.os,
289- // viewport: testVariation.viewport,
290- // baselineName: testVariation.baselineName,
291- // ignoreAreas: testVariation.ignoreAreas,
292- // diffTollerancePercent: createTestRequestDto.diffTollerancePercent,
293- // diffName: undefined,
294- // pixelMisMatchCount: undefined,
295- // diffPercent: undefined,
296- // status: TestStatus.new,
297- // },
298- // });
299- // });
300-
301245 it ( 'with baseline' , async ( ) => {
302246 const testRun = {
303247 id : 'id' ,
@@ -395,11 +339,11 @@ describe('TestRunsService', () => {
395339 const result = service . getDiff ( baseline , image , 0 , '[]' ) ;
396340
397341 expect ( result ) . toStrictEqual ( {
398- status : null ,
399- diffName : null ,
400- pixelMisMatchCount : null ,
401- diffPercent : null ,
402- isSameDimension : false ,
342+ status : undefined ,
343+ diffName : undefined ,
344+ pixelMisMatchCount : undefined ,
345+ diffPercent : undefined ,
346+ isSameDimension : undefined ,
403347 } ) ;
404348 } ) ;
405349
@@ -418,9 +362,9 @@ describe('TestRunsService', () => {
418362
419363 expect ( result ) . toStrictEqual ( {
420364 status : TestStatus . unresolved ,
421- diffName : null ,
422- pixelMisMatchCount : null ,
423- diffPercent : null ,
365+ diffName : undefined ,
366+ pixelMisMatchCount : undefined ,
367+ diffPercent : undefined ,
424368 isSameDimension : false ,
425369 } ) ;
426370 } ) ;
@@ -441,7 +385,7 @@ describe('TestRunsService', () => {
441385
442386 expect ( result ) . toStrictEqual ( {
443387 status : TestStatus . ok ,
444- diffName : null ,
388+ diffName : undefined ,
445389 pixelMisMatchCount : 0 ,
446390 diffPercent : 0 ,
447391 isSameDimension : true ,
@@ -467,7 +411,7 @@ describe('TestRunsService', () => {
467411 expect ( saveImageMock ) . toHaveBeenCalledTimes ( 0 ) ;
468412 expect ( result ) . toStrictEqual ( {
469413 status : TestStatus . ok ,
470- diffName : null ,
414+ diffName : undefined ,
471415 pixelMisMatchCount,
472416 diffPercent : 1.5 ,
473417 isSameDimension : true ,
@@ -596,4 +540,61 @@ describe('TestRunsService', () => {
596540 } ,
597541 } ) ;
598542 } ) ;
543+
544+ it ( 'findMany' , async ( ) => {
545+ const buildId = 'some id' ;
546+ const testRunFindManyMock = jest . fn ( ) ;
547+ service = await initService ( {
548+ testRunFindManyMock,
549+ } ) ;
550+
551+ await service . findMany ( buildId ) ;
552+
553+ expect ( testRunFindManyMock ) . toHaveBeenCalledWith ( {
554+ where : { buildId } ,
555+ } ) ;
556+ } ) ;
557+
558+ it ( 'delete' , async ( ) => {
559+ const id = 'some id' ;
560+ const testRun = {
561+ diffName : 'diffName' ,
562+ imageName : 'imageName' ,
563+ } ;
564+ const findOneMock = jest . fn ( ) . mockResolvedValueOnce ( testRun ) ;
565+ const deleteImageMock = jest . fn ( ) ;
566+ const testRunDeleteMock = jest . fn ( ) ;
567+ service = await initService ( {
568+ deleteImageMock,
569+ testRunDeleteMock,
570+ } ) ;
571+ service . findOne = findOneMock ;
572+
573+ await service . delete ( id ) ;
574+
575+ expect ( findOneMock ) . toHaveBeenCalledWith ( id ) ;
576+ expect ( deleteImageMock ) . toHaveBeenNthCalledWith ( 1 , testRun . diffName ) ;
577+ expect ( deleteImageMock ) . toHaveBeenNthCalledWith ( 2 , testRun . imageName ) ;
578+ expect ( testRunDeleteMock ) . toHaveBeenCalledWith ( {
579+ where : { id } ,
580+ } ) ;
581+ } ) ;
582+
583+ it ( 'updateIgnoreAreas' , async ( ) => {
584+ const id = 'some id' ;
585+ const ignoreAreas : IgnoreAreaDto [ ] = [ { x : 1 , y : 2 , width : 10 , height : 20 } ] ;
586+ const testRunUpdateMock = jest . fn ( ) ;
587+ service = await initService ( {
588+ testRunUpdateMock,
589+ } ) ;
590+
591+ await service . updateIgnoreAreas ( id , ignoreAreas ) ;
592+
593+ expect ( testRunUpdateMock ) . toHaveBeenCalledWith ( {
594+ where : { id } ,
595+ data : {
596+ ignoreAreas : JSON . stringify ( ignoreAreas ) ,
597+ } ,
598+ } ) ;
599+ } ) ;
599600} ) ;
0 commit comments