Skip to content

Commit b67a2c1

Browse files
authored
Merge pull request #54 from Visual-Regression-Tracker/99-delete-retry
99 delete retry
2 parents 23bfff8 + 64ad0b6 commit b67a2c1

File tree

3 files changed

+29
-20
lines changed

3 files changed

+29
-20
lines changed

src/shared/events/events.gateway.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ export class EventsGateway {
2020
this.server.emit('build_updated', build);
2121
}
2222

23-
newTestRun(testRun: TestRun): void {
23+
testRunCreated(testRun: TestRun): void {
2424
this.server.emit('testRun_created', testRun);
2525
}
26+
27+
28+
testRunDeleted(testRun: TestRun): void {
29+
this.server.emit('testRun_deleted', testRun);
30+
}
2631
}

src/test-runs/test-runs.service.spec.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ const initService = async ({
2828
getImageMock = jest.fn(),
2929
saveImageMock = jest.fn(),
3030
deleteImageMock = jest.fn(),
31-
eventNewTestRunMock = jest.fn(),
31+
eventTestRunCreatedMock = jest.fn(),
32+
eventTestRunDeletedMock = jest.fn(),
3233
eventBuildUpdatedMock = jest.fn(),
3334
eventBuildCreatedMock = jest.fn(),
3435
buildFindOneMock = jest.fn(),
@@ -79,7 +80,8 @@ const initService = async ({
7980
{
8081
provide: EventsGateway,
8182
useValue: {
82-
newTestRun: eventNewTestRunMock,
83+
testRunCreated: eventTestRunCreatedMock,
84+
testRunDeleted: eventTestRunDeletedMock,
8385
buildUpdated: eventBuildUpdatedMock,
8486
buildCreated: eventBuildCreatedMock,
8587
},
@@ -467,12 +469,9 @@ describe('TestRunsService', () => {
467469
const saveImageMock = jest.fn().mockReturnValueOnce(imageName);
468470
const image = 'image';
469471
const baseline = 'baseline';
470-
const getImageMock = jest
471-
.fn()
472-
.mockReturnValueOnce(baseline)
473-
.mockReturnValueOnce(image);
474-
const eventNewTestRunMock = jest.fn();
475-
service = await initService({ testRunCreateMock, saveImageMock, getImageMock, eventNewTestRunMock });
472+
const getImageMock = jest.fn().mockReturnValueOnce(baseline).mockReturnValueOnce(image);
473+
const eventTestRunCreatedMock = jest.fn();
474+
service = await initService({ testRunCreateMock, saveImageMock, getImageMock, eventTestRunCreatedMock });
476475
const diffResult: DiffResult = {
477476
status: TestStatus.unresolved,
478477
diffName: 'diff image name',
@@ -526,7 +525,7 @@ describe('TestRunsService', () => {
526525
});
527526
expect(getDiffMock).toHaveBeenCalledWith(baseline, image, testRun.diffTollerancePercent, testRun.ignoreAreas);
528527
expect(saveDiffResultMock).toHaveBeenCalledWith(testRun.id, diffResult);
529-
expect(eventNewTestRunMock).toHaveBeenCalledWith(testRunWithResult);
528+
expect(eventTestRunCreatedMock).toHaveBeenCalledWith(testRunWithResult);
530529
expect(result).toBe(testRunWithResult);
531530
});
532531

@@ -665,10 +664,7 @@ describe('TestRunsService', () => {
665664
const testRunUpdateMock = jest.fn();
666665
const baselineMock = 'baseline image';
667666
const imageeMock = 'image';
668-
const getImageMock = jest
669-
.fn()
670-
.mockReturnValueOnce(baselineMock)
671-
.mockReturnValueOnce(imageeMock);
667+
const getImageMock = jest.fn().mockReturnValueOnce(baselineMock).mockReturnValueOnce(imageeMock);
672668
const deleteImageMock = jest.fn();
673669
const diffResult = {
674670
id: 'test',
@@ -770,9 +766,11 @@ describe('TestRunsService', () => {
770766
const findOneMock = jest.fn().mockResolvedValueOnce(testRun);
771767
const deleteImageMock = jest.fn();
772768
const testRunDeleteMock = jest.fn();
769+
const eventTestRunDeletedMock = jest.fn();
773770
service = await initService({
774771
deleteImageMock,
775772
testRunDeleteMock,
773+
eventTestRunDeletedMock,
776774
});
777775
service.findOne = findOneMock;
778776

@@ -784,6 +782,7 @@ describe('TestRunsService', () => {
784782
expect(testRunDeleteMock).toHaveBeenCalledWith({
785783
where: { id },
786784
});
785+
expect(eventTestRunDeletedMock).toHaveBeenCalledWith(testRun);
787786
});
788787

789788
it('updateIgnoreAreas', async () => {

src/test-runs/test-runs.service.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,18 +230,23 @@ export class TestRunsService {
230230
const diffResult = this.getDiff(baseline, image, testRun.diffTollerancePercent, testVariation.ignoreAreas);
231231

232232
const testRunWithResult = await this.saveDiffResult(testRun.id, diffResult);
233-
this.eventsGateway.newTestRun(testRunWithResult);
233+
this.eventsGateway.testRunCreated(testRunWithResult);
234234
return testRunWithResult;
235235
}
236236

237237
async delete(id: string): Promise<TestRun> {
238238
const testRun = await this.findOne(id);
239239

240-
Promise.all([this.staticService.deleteImage(testRun.diffName), this.staticService.deleteImage(testRun.imageName)]);
240+
await Promise.all([
241+
this.staticService.deleteImage(testRun.diffName),
242+
this.staticService.deleteImage(testRun.imageName),
243+
this.prismaService.testRun.delete({
244+
where: { id },
245+
}),
246+
]);
241247

242-
return this.prismaService.testRun.delete({
243-
where: { id },
244-
});
248+
this.eventsGateway.testRunDeleted(testRun);
249+
return testRun;
245250
}
246251

247252
async updateIgnoreAreas(id: string, ignoreAreas: IgnoreAreaDto[]): Promise<TestRun> {
@@ -310,7 +315,7 @@ export class TestRunsService {
310315
}
311316

312317
private applyIgnoreAreas(image: PNG, ignoreAreas: IgnoreAreaDto[]): Buffer {
313-
ignoreAreas.forEach(area => {
318+
ignoreAreas.forEach((area) => {
314319
for (let y = area.y; y < area.y + area.height; y++) {
315320
for (let x = area.x; x < area.x + area.width; x++) {
316321
const k = 4 * (image.width * y + x);

0 commit comments

Comments
 (0)