Skip to content

Commit 914818d

Browse files
committed
testRunDeleted event emited
1 parent d8372ce commit 914818d

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const initService = async ({
2929
saveImageMock = jest.fn(),
3030
deleteImageMock = jest.fn(),
3131
eventNewTestRunMock = jest.fn(),
32+
eventTestRunDeletedMock = jest.fn(),
3233
eventBuildUpdatedMock = jest.fn(),
3334
eventBuildCreatedMock = jest.fn(),
3435
buildFindOneMock = jest.fn(),
@@ -80,6 +81,7 @@ const initService = async ({
8081
provide: EventsGateway,
8182
useValue: {
8283
newTestRun: eventNewTestRunMock,
84+
testRunDeleted: eventTestRunDeletedMock,
8385
buildUpdated: eventBuildUpdatedMock,
8486
buildCreated: eventBuildCreatedMock,
8587
},
@@ -467,10 +469,7 @@ 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);
472+
const getImageMock = jest.fn().mockReturnValueOnce(baseline).mockReturnValueOnce(image);
474473
const eventNewTestRunMock = jest.fn();
475474
service = await initService({ testRunCreateMock, saveImageMock, getImageMock, eventNewTestRunMock });
476475
const diffResult: DiffResult = {
@@ -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: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,16 @@ export class TestRunsService {
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)