From d8372ce0ff77e725845a035eebde3187a2123b39 Mon Sep 17 00:00:00 2001 From: Pavel Strunkin Date: Thu, 27 Aug 2020 22:14:24 +0200 Subject: [PATCH 1/3] Update events.gateway.ts testRunDeleted added --- src/shared/events/events.gateway.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/shared/events/events.gateway.ts b/src/shared/events/events.gateway.ts index 3d9c7b89..08e783e0 100644 --- a/src/shared/events/events.gateway.ts +++ b/src/shared/events/events.gateway.ts @@ -23,4 +23,9 @@ export class EventsGateway { newTestRun(testRun: TestRun): void { this.server.emit('testRun_created', testRun); } + + + testRunDeleted(testRun: TestRun): void { + this.server.emit('testRun_deleted', testRun); + } } From 914818d1593c704430ebd36a10fc991e4ff97aaa Mon Sep 17 00:00:00 2001 From: Pavel Strunkin Date: Thu, 27 Aug 2020 22:25:00 +0200 Subject: [PATCH 2/3] testRunDeleted event emited --- src/test-runs/test-runs.service.spec.ts | 15 +++++++-------- src/test-runs/test-runs.service.ts | 15 ++++++++++----- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/test-runs/test-runs.service.spec.ts b/src/test-runs/test-runs.service.spec.ts index 55cd534a..b12e1170 100644 --- a/src/test-runs/test-runs.service.spec.ts +++ b/src/test-runs/test-runs.service.spec.ts @@ -29,6 +29,7 @@ const initService = async ({ saveImageMock = jest.fn(), deleteImageMock = jest.fn(), eventNewTestRunMock = jest.fn(), + eventTestRunDeletedMock = jest.fn(), eventBuildUpdatedMock = jest.fn(), eventBuildCreatedMock = jest.fn(), buildFindOneMock = jest.fn(), @@ -80,6 +81,7 @@ const initService = async ({ provide: EventsGateway, useValue: { newTestRun: eventNewTestRunMock, + testRunDeleted: eventTestRunDeletedMock, buildUpdated: eventBuildUpdatedMock, buildCreated: eventBuildCreatedMock, }, @@ -467,10 +469,7 @@ describe('TestRunsService', () => { const saveImageMock = jest.fn().mockReturnValueOnce(imageName); const image = 'image'; const baseline = 'baseline'; - const getImageMock = jest - .fn() - .mockReturnValueOnce(baseline) - .mockReturnValueOnce(image); + const getImageMock = jest.fn().mockReturnValueOnce(baseline).mockReturnValueOnce(image); const eventNewTestRunMock = jest.fn(); service = await initService({ testRunCreateMock, saveImageMock, getImageMock, eventNewTestRunMock }); const diffResult: DiffResult = { @@ -665,10 +664,7 @@ describe('TestRunsService', () => { const testRunUpdateMock = jest.fn(); const baselineMock = 'baseline image'; const imageeMock = 'image'; - const getImageMock = jest - .fn() - .mockReturnValueOnce(baselineMock) - .mockReturnValueOnce(imageeMock); + const getImageMock = jest.fn().mockReturnValueOnce(baselineMock).mockReturnValueOnce(imageeMock); const deleteImageMock = jest.fn(); const diffResult = { id: 'test', @@ -770,9 +766,11 @@ describe('TestRunsService', () => { const findOneMock = jest.fn().mockResolvedValueOnce(testRun); const deleteImageMock = jest.fn(); const testRunDeleteMock = jest.fn(); + const eventTestRunDeletedMock = jest.fn(); service = await initService({ deleteImageMock, testRunDeleteMock, + eventTestRunDeletedMock, }); service.findOne = findOneMock; @@ -784,6 +782,7 @@ describe('TestRunsService', () => { expect(testRunDeleteMock).toHaveBeenCalledWith({ where: { id }, }); + expect(eventTestRunDeletedMock).toHaveBeenCalledWith(testRun); }); it('updateIgnoreAreas', async () => { diff --git a/src/test-runs/test-runs.service.ts b/src/test-runs/test-runs.service.ts index 5b95c7c8..bc9dc30e 100644 --- a/src/test-runs/test-runs.service.ts +++ b/src/test-runs/test-runs.service.ts @@ -237,11 +237,16 @@ export class TestRunsService { async delete(id: string): Promise { const testRun = await this.findOne(id); - Promise.all([this.staticService.deleteImage(testRun.diffName), this.staticService.deleteImage(testRun.imageName)]); + await Promise.all([ + this.staticService.deleteImage(testRun.diffName), + this.staticService.deleteImage(testRun.imageName), + this.prismaService.testRun.delete({ + where: { id }, + }), + ]); - return this.prismaService.testRun.delete({ - where: { id }, - }); + this.eventsGateway.testRunDeleted(testRun); + return testRun; } async updateIgnoreAreas(id: string, ignoreAreas: IgnoreAreaDto[]): Promise { @@ -310,7 +315,7 @@ export class TestRunsService { } private applyIgnoreAreas(image: PNG, ignoreAreas: IgnoreAreaDto[]): Buffer { - ignoreAreas.forEach(area => { + ignoreAreas.forEach((area) => { for (let y = area.y; y < area.y + area.height; y++) { for (let x = area.x; x < area.x + area.width; x++) { const k = 4 * (image.width * y + x); From 64ad0b6640d02e3d5d2251d60187f984c69e0f39 Mon Sep 17 00:00:00 2001 From: Pavel Strunkin Date: Thu, 27 Aug 2020 23:09:07 +0200 Subject: [PATCH 3/3] newTestRun renamed into testRunCreated --- src/shared/events/events.gateway.ts | 2 +- src/test-runs/test-runs.service.spec.ts | 10 +++++----- src/test-runs/test-runs.service.ts | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/shared/events/events.gateway.ts b/src/shared/events/events.gateway.ts index 08e783e0..d309b22a 100644 --- a/src/shared/events/events.gateway.ts +++ b/src/shared/events/events.gateway.ts @@ -20,7 +20,7 @@ export class EventsGateway { this.server.emit('build_updated', build); } - newTestRun(testRun: TestRun): void { + testRunCreated(testRun: TestRun): void { this.server.emit('testRun_created', testRun); } diff --git a/src/test-runs/test-runs.service.spec.ts b/src/test-runs/test-runs.service.spec.ts index b12e1170..d405032d 100644 --- a/src/test-runs/test-runs.service.spec.ts +++ b/src/test-runs/test-runs.service.spec.ts @@ -28,7 +28,7 @@ const initService = async ({ getImageMock = jest.fn(), saveImageMock = jest.fn(), deleteImageMock = jest.fn(), - eventNewTestRunMock = jest.fn(), + eventTestRunCreatedMock = jest.fn(), eventTestRunDeletedMock = jest.fn(), eventBuildUpdatedMock = jest.fn(), eventBuildCreatedMock = jest.fn(), @@ -80,7 +80,7 @@ const initService = async ({ { provide: EventsGateway, useValue: { - newTestRun: eventNewTestRunMock, + testRunCreated: eventTestRunCreatedMock, testRunDeleted: eventTestRunDeletedMock, buildUpdated: eventBuildUpdatedMock, buildCreated: eventBuildCreatedMock, @@ -470,8 +470,8 @@ describe('TestRunsService', () => { const image = 'image'; const baseline = 'baseline'; const getImageMock = jest.fn().mockReturnValueOnce(baseline).mockReturnValueOnce(image); - const eventNewTestRunMock = jest.fn(); - service = await initService({ testRunCreateMock, saveImageMock, getImageMock, eventNewTestRunMock }); + const eventTestRunCreatedMock = jest.fn(); + service = await initService({ testRunCreateMock, saveImageMock, getImageMock, eventTestRunCreatedMock }); const diffResult: DiffResult = { status: TestStatus.unresolved, diffName: 'diff image name', @@ -525,7 +525,7 @@ describe('TestRunsService', () => { }); expect(getDiffMock).toHaveBeenCalledWith(baseline, image, testRun.diffTollerancePercent, testRun.ignoreAreas); expect(saveDiffResultMock).toHaveBeenCalledWith(testRun.id, diffResult); - expect(eventNewTestRunMock).toHaveBeenCalledWith(testRunWithResult); + expect(eventTestRunCreatedMock).toHaveBeenCalledWith(testRunWithResult); expect(result).toBe(testRunWithResult); }); diff --git a/src/test-runs/test-runs.service.ts b/src/test-runs/test-runs.service.ts index bc9dc30e..e1b6bc8a 100644 --- a/src/test-runs/test-runs.service.ts +++ b/src/test-runs/test-runs.service.ts @@ -230,7 +230,7 @@ export class TestRunsService { const diffResult = this.getDiff(baseline, image, testRun.diffTollerancePercent, testVariation.ignoreAreas); const testRunWithResult = await this.saveDiffResult(testRun.id, diffResult); - this.eventsGateway.newTestRun(testRunWithResult); + this.eventsGateway.testRunCreated(testRunWithResult); return testRunWithResult; }