Skip to content

Commit f070308

Browse files
committed
CommentDto added
1 parent dfecf5b commit f070308

File tree

7 files changed

+34
-19
lines changed

7 files changed

+34
-19
lines changed

src/shared/dto/comment.dto.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { ApiProperty } from '@nestjs/swagger';
2+
import { IsString } from 'class-validator';
3+
4+
export class CommentDto {
5+
@ApiProperty()
6+
@IsString()
7+
comment: string;
8+
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { JwtAuthGuard } from '../auth/guards/auth.guard';
44
import { TestRun } from '@prisma/client';
55
import { TestRunsService } from './test-runs.service';
66
import { IgnoreAreaDto } from '../test/dto/ignore-area.dto';
7+
import { CommentDto } from '../shared/dto/comment.dto';
78

89
@ApiTags('test-runs')
910
@Controller('test-runs')
@@ -65,7 +66,7 @@ export class TestRunsController {
6566
@ApiParam({ name: 'testRunId', required: true })
6667
@ApiBearerAuth()
6768
@UseGuards(JwtAuthGuard)
68-
updateComment(@Param('testRunId', new ParseUUIDPipe()) testRunId: string, @Body() comment: string): Promise<TestRun> {
69-
return this.testRunsService.updateComment(testRunId, comment);
69+
updateComment(@Param('testRunId', new ParseUUIDPipe()) id: string, @Body() body: CommentDto): Promise<TestRun> {
70+
return this.testRunsService.updateComment(id, body);
7071
}
7172
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { CreateTestRequestDto } from '../test/dto/create-test-request.dto';
1010
import { DiffResult } from './diffResult';
1111
import { IgnoreAreaDto } from '../test/dto/ignore-area.dto';
1212
import { EventsGateway } from '../events/events.gateway';
13+
import { CommentDto } from '../shared/dto/comment.dto';
1314

1415
jest.mock('pixelmatch');
1516

@@ -538,18 +539,20 @@ describe('TestRunsService', () => {
538539

539540
it('updateComment', async () => {
540541
const id = 'some id';
541-
const comment = 'random comment';
542+
const commentDto: CommentDto = {
543+
comment: 'random comment',
544+
};
542545
const testRunUpdateMock = jest.fn();
543546
service = await initService({
544547
testRunUpdateMock,
545548
});
546549

547-
await service.updateComment(id, comment);
550+
await service.updateComment(id, commentDto);
548551

549552
expect(testRunUpdateMock).toHaveBeenCalledWith({
550553
where: { id },
551554
data: {
552-
comment,
555+
comment: commentDto.comment,
553556
},
554557
});
555558
});

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { PrismaService } from '../prisma/prisma.service';
88
import { TestRun, TestStatus, TestVariation } from '@prisma/client';
99
import { DiffResult } from './diffResult';
1010
import { EventsGateway } from '../events/events.gateway';
11+
import { CommentDto } from 'src/shared/dto/comment.dto';
1112

1213
@Injectable()
1314
export class TestRunsService {
@@ -160,11 +161,11 @@ export class TestRunsService {
160161
});
161162
}
162163

163-
async updateComment(id: string, comment: string): Promise<TestRun> {
164+
async updateComment(id: string, commentDto: CommentDto): Promise<TestRun> {
164165
return this.prismaService.testRun.update({
165166
where: { id },
166167
data: {
167-
comment,
168+
comment: commentDto.comment,
168169
},
169170
});
170171
}

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { TestVariation, Baseline } from '@prisma/client';
55
import { JwtAuthGuard } from '../auth/guards/auth.guard';
66
import { PrismaService } from '../prisma/prisma.service';
77
import { IgnoreAreaDto } from '../test/dto/ignore-area.dto';
8+
import { CommentDto } from '../shared/dto/comment.dto';
89

910
@ApiTags('test-variations')
1011
@Controller('test-variations')
@@ -40,14 +41,11 @@ export class TestVariationsController {
4041
return this.testVariations.updateIgnoreAreas(variationId, ignoreAreas);
4142
}
4243

43-
@Put('comment/:testRunId')
44-
@ApiParam({ name: 'testRunId', required: true })
44+
@Put('comment/:id')
45+
@ApiParam({ name: 'id', required: true })
4546
@ApiBearerAuth()
4647
@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);
48+
updateComment(@Param('id', new ParseUUIDPipe()) id: string, @Body() body: CommentDto): Promise<TestVariation> {
49+
return this.testVariations.updateComment(id, body);
5250
}
5351
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { CreateTestRequestDto } from '../test/dto/create-test-request.dto';
55
import { StaticService } from '../shared/static/static.service';
66
import { IgnoreAreaDto } from 'src/test/dto/ignore-area.dto';
77
import { TestVariation, Baseline } from '@prisma/client';
8+
import { CommentDto } from '../shared/dto/comment.dto';
89

910
const initModule = async ({
1011
imageDeleteMock = jest.fn(),
@@ -237,18 +238,20 @@ describe('TestVariationsService', () => {
237238

238239
it('updateComment', async () => {
239240
const id = 'some id';
240-
const comment = 'random comment';
241+
const commentDto: CommentDto = {
242+
comment: 'random comment',
243+
};
241244
const variationUpdateMock = jest.fn();
242245
service = await initModule({
243246
variationUpdateMock,
244247
});
245248

246-
await service.updateComment(id, comment);
249+
await service.updateComment(id, commentDto);
247250

248251
expect(variationUpdateMock).toHaveBeenCalledWith({
249252
where: { id },
250253
data: {
251-
comment,
254+
comment: commentDto.comment,
252255
},
253256
});
254257
});

src/test-variations/test-variations.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { IgnoreAreaDto } from '../test/dto/ignore-area.dto';
44
import { PrismaService } from '../prisma/prisma.service';
55
import { TestVariation, Baseline } from '@prisma/client';
66
import { StaticService } from '../shared/static/static.service';
7+
import { CommentDto } from '../shared/dto/comment.dto';
78

89
@Injectable()
910
export class TestVariationsService {
@@ -61,11 +62,11 @@ export class TestVariationsService {
6162
});
6263
}
6364

64-
async updateComment(id: string, comment: string): Promise<TestVariation> {
65+
async updateComment(id: string, commentDto: CommentDto): Promise<TestVariation> {
6566
return this.prismaService.testVariation.update({
6667
where: { id },
6768
data: {
68-
comment,
69+
comment: commentDto.comment,
6970
},
7071
});
7172
}

0 commit comments

Comments
 (0)