@@ -4,7 +4,7 @@ import { PrismaService } from '../prisma/prisma.service';
44import { CreateTestRequestDto } from '../test-runs/dto/create-test-request.dto' ;
55import { StaticService } from '../shared/static/static.service' ;
66import { IgnoreAreaDto } from '../test-runs/dto/ignore-area.dto' ;
7- import { TestVariation , Baseline , Project , Build } from '@prisma/client' ;
7+ import { TestVariation , Baseline , Project , Build , TestRun } from '@prisma/client' ;
88import { CommentDto } from '../shared/dto/comment.dto' ;
99import { convertBaselineDataToQuery } from '../shared/dto/baseline-data.dto' ;
1010import { PNG } from 'pngjs' ;
@@ -23,6 +23,8 @@ const initModule = async ({
2323 projectFindOneMock = jest . fn ( ) ,
2424 buildCreateMock = jest . fn ( ) ,
2525 testRunCreateMock = jest . fn ( ) ,
26+ testRunFindMany = jest . fn ( ) ,
27+ testRunDeleteMock = jest . fn ( ) ,
2628} ) => {
2729 const module : TestingModule = await Test . createTestingModule ( {
2830 providers : [
@@ -43,6 +45,7 @@ const initModule = async ({
4345 {
4446 provide : TestRunsService ,
4547 useValue : {
48+ delete : testRunDeleteMock ,
4649 create : testRunCreateMock ,
4750 } ,
4851 } ,
@@ -62,6 +65,9 @@ const initModule = async ({
6265 project : {
6366 findOne : projectFindOneMock ,
6467 } ,
68+ testRun : {
69+ findMany : testRunFindMany ,
70+ } ,
6571 } ,
6672 } ,
6773 ] ,
@@ -300,59 +306,6 @@ describe('TestVariationsService', () => {
300306 } ) ;
301307 } ) ;
302308
303- describe ( 'remove' , ( ) => {
304- it ( 'can remove' , async ( ) => {
305- const id = 'test id' ;
306- const variation : TestVariation & {
307- baselines : Baseline [ ] ;
308- } = {
309- id,
310- projectId : 'project Id' ,
311- name : 'Test name' ,
312- baselineName : 'baselineName' ,
313- os : 'OS' ,
314- browser : 'browser' ,
315- viewport : 'viewport' ,
316- device : 'device' ,
317- ignoreAreas : '[]' ,
318- comment : 'some comment' ,
319- branchName : 'develop' ,
320- createdAt : new Date ( ) ,
321- updatedAt : new Date ( ) ,
322- baselines : [
323- {
324- id : 'baseline id 1' ,
325- baselineName : 'image name 1' ,
326- testVariationId : id ,
327- testRunId : 'test run id 1' ,
328- createdAt : new Date ( ) ,
329- updatedAt : new Date ( ) ,
330- } ,
331- ] ,
332- } ;
333- const variationFindOneMock = jest . fn ( ) ;
334- const variationDeleteMock = jest . fn ( ) ;
335- const imageDeleteMock = jest . fn ( ) ;
336- const baselineDeleteMock = jest . fn ( ) ;
337- service = await initModule ( {
338- variationFindOneMock : variationFindOneMock . mockResolvedValueOnce ( variation ) ,
339- variationDeleteMock,
340- imageDeleteMock,
341- baselineDeleteMock,
342- } ) ;
343-
344- await service . remove ( id ) ;
345-
346- expect ( imageDeleteMock ) . toHaveBeenCalledWith ( variation . baselines [ 0 ] . baselineName ) ;
347- expect ( baselineDeleteMock ) . toHaveBeenCalledWith ( {
348- where : { id : variation . baselines [ 0 ] . id } ,
349- } ) ;
350- expect ( variationDeleteMock ) . toHaveBeenCalledWith ( {
351- where : { id : variation . id } ,
352- } ) ;
353- } ) ;
354- } ) ;
355-
356309 it ( 'updateComment' , async ( ) => {
357310 const id = 'some id' ;
358311 const commentDto : CommentDto = {
@@ -517,4 +470,110 @@ describe('TestVariationsService', () => {
517470 } ) ;
518471 expect ( testRunCreateMock ) . toHaveBeenCalledTimes ( 2 ) ;
519472 } ) ;
473+
474+ it ( 'delete' , async ( ) => {
475+ const testRunId = 'test run id' ;
476+ const testVariationId = 'test variation id' ;
477+ const testRun : TestRun = {
478+ id : testRunId ,
479+ imageName : '1592423768112.screenshot.png' ,
480+ diffName : null ,
481+ diffPercent : null ,
482+ diffTollerancePercent : 1 ,
483+ pixelMisMatchCount : null ,
484+ status : 'new' ,
485+ buildId : '146e7a8d-89f0-4565-aa2c-e61efabb0afd' ,
486+ testVariationId : testVariationId ,
487+ updatedAt : new Date ( ) ,
488+ createdAt : new Date ( ) ,
489+ name : 'ss2f77' ,
490+ browser : 'chromium' ,
491+ device : null ,
492+ os : null ,
493+ viewport : '1800x1600' ,
494+ baselineName : null ,
495+ ignoreAreas : '[]' ,
496+ comment : 'some comment' ,
497+ baselineBranchName : 'master' ,
498+ branchName : 'develop' ,
499+ merge : false ,
500+ } ;
501+ const variation : TestVariation & {
502+ baselines : Baseline [ ] ;
503+ } = {
504+ id : testVariationId ,
505+ projectId : 'project Id' ,
506+ name : 'Test name' ,
507+ baselineName : 'baselineName' ,
508+ os : 'OS' ,
509+ browser : 'browser' ,
510+ viewport : 'viewport' ,
511+ device : 'device' ,
512+ ignoreAreas : '[]' ,
513+ comment : 'some comment' ,
514+ branchName : 'develop' ,
515+ createdAt : new Date ( ) ,
516+ updatedAt : new Date ( ) ,
517+ baselines : [
518+ {
519+ id : 'baseline id 1' ,
520+ baselineName : 'image name 1' ,
521+ testVariationId : testVariationId ,
522+ testRunId : 'test run id 1' ,
523+ createdAt : new Date ( ) ,
524+ updatedAt : new Date ( ) ,
525+ } ,
526+ ] ,
527+ } ;
528+
529+ const variationDeleteMock = jest . fn ( ) ;
530+ const testRunFindMany = jest . fn ( ) . mockResolvedValueOnce ( [ testRun ] ) ;
531+ const testRunDeleteMock = jest . fn ( ) ;
532+ const getDetailsMock = jest . fn ( ) . mockResolvedValueOnce ( variation ) ;
533+ const deleteBaselineMock = jest . fn ( ) . mockResolvedValueOnce ( variation . baselines [ 0 ] ) ;
534+ const service = await initModule ( {
535+ variationDeleteMock,
536+ testRunFindMany,
537+ testRunDeleteMock,
538+ } ) ;
539+ service . getDetails = getDetailsMock ;
540+ service . deleteBaseline = deleteBaselineMock ;
541+
542+ await service . delete ( testVariationId ) ;
543+
544+ expect ( service . getDetails ) . toHaveBeenCalledWith ( testVariationId ) ;
545+ expect ( testRunFindMany ) . toHaveBeenCalledWith ( {
546+ where : { testVariationId } ,
547+ } ) ;
548+ expect ( testRunDeleteMock ) . toHaveBeenCalledWith ( testRunId ) ;
549+ expect ( service . deleteBaseline ) . toHaveBeenCalledWith ( variation . baselines [ 0 ] ) ;
550+ expect ( variationDeleteMock ) . toHaveBeenCalledWith ( {
551+ where : { id : testVariationId } ,
552+ } ) ;
553+ } ) ;
554+
555+ it ( 'deleteBaseline' , async ( ) => {
556+ const baseline : Baseline = {
557+ id : 'baseline id 1' ,
558+ baselineName : 'image name 1' ,
559+ testVariationId : 'test variation id' ,
560+ testRunId : 'test run id 1' ,
561+ createdAt : new Date ( ) ,
562+ updatedAt : new Date ( ) ,
563+ } ;
564+
565+ const baselineDeleteMock = jest . fn ( ) ;
566+ const imageDeleteMock = jest . fn ( ) ;
567+ const service = await initModule ( {
568+ baselineDeleteMock,
569+ imageDeleteMock,
570+ } ) ;
571+
572+ await service . deleteBaseline ( baseline ) ;
573+
574+ expect ( imageDeleteMock ) . toHaveBeenCalledWith ( baseline . baselineName ) ;
575+ expect ( baselineDeleteMock ) . toHaveBeenCalledWith ( {
576+ where : { id : baseline . id } ,
577+ } ) ;
578+ } ) ;
520579} ) ;
0 commit comments