Skip to content

Commit dfecf5b

Browse files
committed
updateComment added
1 parent aeadaaa commit dfecf5b

File tree

6 files changed

+236
-175
lines changed

6 files changed

+236
-175
lines changed

src/test-runs/test-runs.controller.ts

Lines changed: 60 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,56 +8,64 @@ import { IgnoreAreaDto } from '../test/dto/ignore-area.dto';
88
@ApiTags('test-runs')
99
@Controller('test-runs')
1010
export class TestRunsController {
11-
constructor(private testRunsService: TestRunsService) { }
12-
13-
@Get()
14-
@ApiQuery({ name: 'buildId', required: true })
15-
@ApiBearerAuth()
16-
@UseGuards(JwtAuthGuard)
17-
get(@Query('buildId', new ParseUUIDPipe()) buildId: string): Promise<TestRun[]> {
18-
return this.testRunsService.findMany(buildId);
19-
}
20-
21-
@Get('recalculateDiff/:id')
22-
@ApiParam({ name: 'id', required: true })
23-
@ApiBearerAuth()
24-
@UseGuards(JwtAuthGuard)
25-
recalculateDiff(@Param('id', new ParseUUIDPipe()) id: string): Promise<TestRun> {
26-
return this.testRunsService.recalculateDiff(id);
27-
}
28-
29-
@Get('approve/:id')
30-
@ApiParam({ name: 'id', required: true })
31-
@ApiBearerAuth()
32-
@UseGuards(JwtAuthGuard)
33-
approveTestRun(@Param('id', new ParseUUIDPipe()) id: string): Promise<TestRun> {
34-
return this.testRunsService.approve(id);
35-
}
36-
37-
@Get('reject/:id')
38-
@ApiParam({ name: 'id', required: true })
39-
@ApiBearerAuth()
40-
@UseGuards(JwtAuthGuard)
41-
rejectTestRun(@Param('id', new ParseUUIDPipe()) id: string): Promise<TestRun> {
42-
return this.testRunsService.reject(id);
43-
}
44-
45-
@Delete('/:id')
46-
@ApiParam({ name: 'id', required: true })
47-
@ApiBearerAuth()
48-
@UseGuards(JwtAuthGuard)
49-
deleteTestRun(@Param('id', new ParseUUIDPipe()) id: string): Promise<TestRun> {
50-
return this.testRunsService.delete(id);
51-
}
52-
53-
@Put('ignoreArea/:testRunId')
54-
@ApiParam({ name: 'testRunId', required: true })
55-
@ApiBearerAuth()
56-
@UseGuards(JwtAuthGuard)
57-
updateIgnoreAreas(
58-
@Param('testRunId', new ParseUUIDPipe()) testRunId: string,
59-
@Body() ignoreAreas: IgnoreAreaDto[],
60-
): Promise<TestRun> {
61-
return this.testRunsService.updateIgnoreAreas(testRunId, ignoreAreas);
62-
}
11+
constructor(private testRunsService: TestRunsService) {}
12+
13+
@Get()
14+
@ApiQuery({ name: 'buildId', required: true })
15+
@ApiBearerAuth()
16+
@UseGuards(JwtAuthGuard)
17+
get(@Query('buildId', new ParseUUIDPipe()) buildId: string): Promise<TestRun[]> {
18+
return this.testRunsService.findMany(buildId);
19+
}
20+
21+
@Get('recalculateDiff/:id')
22+
@ApiParam({ name: 'id', required: true })
23+
@ApiBearerAuth()
24+
@UseGuards(JwtAuthGuard)
25+
recalculateDiff(@Param('id', new ParseUUIDPipe()) id: string): Promise<TestRun> {
26+
return this.testRunsService.recalculateDiff(id);
27+
}
28+
29+
@Get('approve/:id')
30+
@ApiParam({ name: 'id', required: true })
31+
@ApiBearerAuth()
32+
@UseGuards(JwtAuthGuard)
33+
approveTestRun(@Param('id', new ParseUUIDPipe()) id: string): Promise<TestRun> {
34+
return this.testRunsService.approve(id);
35+
}
36+
37+
@Get('reject/:id')
38+
@ApiParam({ name: 'id', required: true })
39+
@ApiBearerAuth()
40+
@UseGuards(JwtAuthGuard)
41+
rejectTestRun(@Param('id', new ParseUUIDPipe()) id: string): Promise<TestRun> {
42+
return this.testRunsService.reject(id);
43+
}
44+
45+
@Delete('/:id')
46+
@ApiParam({ name: 'id', required: true })
47+
@ApiBearerAuth()
48+
@UseGuards(JwtAuthGuard)
49+
deleteTestRun(@Param('id', new ParseUUIDPipe()) id: string): Promise<TestRun> {
50+
return this.testRunsService.delete(id);
51+
}
52+
53+
@Put('ignoreArea/:testRunId')
54+
@ApiParam({ name: 'testRunId', required: true })
55+
@ApiBearerAuth()
56+
@UseGuards(JwtAuthGuard)
57+
updateIgnoreAreas(
58+
@Param('testRunId', new ParseUUIDPipe()) testRunId: string,
59+
@Body() ignoreAreas: IgnoreAreaDto[]
60+
): Promise<TestRun> {
61+
return this.testRunsService.updateIgnoreAreas(testRunId, ignoreAreas);
62+
}
63+
64+
@Put('comment/:testRunId')
65+
@ApiParam({ name: 'testRunId', required: true })
66+
@ApiBearerAuth()
67+
@UseGuards(JwtAuthGuard)
68+
updateComment(@Param('testRunId', new ParseUUIDPipe()) testRunId: string, @Body() comment: string): Promise<TestRun> {
69+
return this.testRunsService.updateComment(testRunId, comment);
70+
}
6371
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,4 +535,22 @@ describe('TestRunsService', () => {
535535
},
536536
});
537537
});
538+
539+
it('updateComment', async () => {
540+
const id = 'some id';
541+
const comment = 'random comment';
542+
const testRunUpdateMock = jest.fn();
543+
service = await initService({
544+
testRunUpdateMock,
545+
});
546+
547+
await service.updateComment(id, comment);
548+
549+
expect(testRunUpdateMock).toHaveBeenCalledWith({
550+
where: { id },
551+
data: {
552+
comment,
553+
},
554+
});
555+
});
538556
});

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,7 @@ export class TestRunsService {
134134
const baseline = this.staticService.getImage(testRun.baselineName);
135135
const image = this.staticService.getImage(imageName);
136136

137-
const diffResult = this.getDiff(
138-
baseline,
139-
image,
140-
testRun.diffTollerancePercent,
141-
testVariation.ignoreAreas
142-
);
137+
const diffResult = this.getDiff(baseline, image, testRun.diffTollerancePercent, testVariation.ignoreAreas);
143138

144139
const testRunWithResult = await this.saveDiffResult(testRun.id, diffResult);
145140
this.eventsGateway.newTestRun(testRunWithResult);
@@ -165,6 +160,15 @@ export class TestRunsService {
165160
});
166161
}
167162

163+
async updateComment(id: string, comment: string): Promise<TestRun> {
164+
return this.prismaService.testRun.update({
165+
where: { id },
166+
data: {
167+
comment,
168+
},
169+
});
170+
}
171+
168172
getDiff(baseline: PNG, image: PNG, diffTollerancePercent: number, ignoreAreas: string): DiffResult {
169173
const result: DiffResult = {
170174
status: undefined,

src/test-variations/test-variations.controller.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,23 @@ import { IgnoreAreaDto } from '../test/dto/ignore-area.dto';
99
@ApiTags('test-variations')
1010
@Controller('test-variations')
1111
export class TestVariationsController {
12-
constructor(private testVariations: TestVariationsService, private prismaService: PrismaService) { }
12+
constructor(private testVariations: TestVariationsService, private prismaService: PrismaService) {}
1313

1414
@Get()
1515
@ApiQuery({ name: 'projectId', required: true })
1616
@ApiBearerAuth()
1717
@UseGuards(JwtAuthGuard)
18-
getList(
19-
@Query('projectId', new ParseUUIDPipe()) projectId,
20-
): Promise<TestVariation[]> {
18+
getList(@Query('projectId', new ParseUUIDPipe()) projectId): Promise<TestVariation[]> {
2119
return this.prismaService.testVariation.findMany({
22-
where: { projectId }
20+
where: { projectId },
2321
});
2422
}
2523

2624
@Get(':id')
2725
@ApiQuery({ name: 'id', required: true })
2826
@ApiBearerAuth()
2927
@UseGuards(JwtAuthGuard)
30-
getDetails(
31-
@Param('id', new ParseUUIDPipe()) id,
32-
): Promise<TestVariation & { baselines: Baseline[] }> {
28+
getDetails(@Param('id', new ParseUUIDPipe()) id): Promise<TestVariation & { baselines: Baseline[] }> {
3329
return this.testVariations.getDetails(id);
3430
}
3531

@@ -39,8 +35,19 @@ export class TestVariationsController {
3935
@UseGuards(JwtAuthGuard)
4036
updateIgnoreAreas(
4137
@Param('variationId', new ParseUUIDPipe()) variationId: string,
42-
@Body() ignoreAreas: IgnoreAreaDto[],
38+
@Body() ignoreAreas: IgnoreAreaDto[]
4339
): Promise<TestVariation> {
4440
return this.testVariations.updateIgnoreAreas(variationId, ignoreAreas);
4541
}
42+
43+
@Put('comment/:testRunId')
44+
@ApiParam({ name: 'testRunId', required: true })
45+
@ApiBearerAuth()
46+
@UseGuards(JwtAuthGuard)
47+
updateComment(
48+
@Param('testRunId', new ParseUUIDPipe()) testRunId: string,
49+
@Body() comment: string
50+
): Promise<TestVariation> {
51+
return this.testVariations.updateComment(testRunId, comment);
52+
}
4653
}

0 commit comments

Comments
 (0)