Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions src/test-runs/test-runs.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,19 @@ import { CommentDto } from '../shared/dto/comment.dto';
import { TestRunResultDto } from './dto/testRunResult.dto';
import { ApiGuard } from '../auth/guards/api.guard';
import { CreateTestRequestDto } from './dto/create-test-request.dto';
import { PaginatedTestRunDto } from './dto/testRun-paginated.dto';
import { TestRunDto } from './dto/testRun.dto';

@ApiTags('test-runs')
@Controller('test-runs')
export class TestRunsController {
constructor(private testRunsService: TestRunsService) {}

@Get()
@ApiOkResponse({ type: PaginatedTestRunDto })
@ApiOkResponse({ type: [TestRunDto] })
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
get(
@Query('buildId', new ParseUUIDPipe()) buildId: string,
@Query('take', new ParseIntPipe()) take: number,
@Query('skip', new ParseIntPipe()) skip: number
): Promise<PaginatedTestRunDto> {
return this.testRunsService.findMany(buildId, take, skip);
get(@Query('buildId', new ParseUUIDPipe()) buildId: string): Promise<TestRunDto[]> {
return this.testRunsService.findMany(buildId);
}

@Get('recalculateDiff/:id')
Expand Down
16 changes: 2 additions & 14 deletions src/test-runs/test-runs.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -843,28 +843,16 @@ describe('TestRunsService', () => {
merge: false,
};
const testRunFindManyMock = jest.fn().mockResolvedValueOnce([testRun]);
const testRunCountMock = jest.fn().mockResolvedValueOnce(30);
service = await initService({
testRunFindManyMock,
testRunCountMock,
});

const result = await service.findMany(buildId, 10, 1);
const result = await service.findMany(buildId);

expect(testRunFindManyMock).toHaveBeenCalledWith({
where: { buildId },
take: 10,
skip: 1,
});
expect(testRunCountMock).toHaveBeenCalledWith({
where: { buildId },
});
expect(result).toEqual({
data: [new TestRunDto(testRun)],
take: 10,
skip: 1,
total: 30,
});
expect(result).toEqual([new TestRunDto(testRun)]);
});

it('delete', async () => {
Expand Down
20 changes: 5 additions & 15 deletions src/test-runs/test-runs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,11 @@ export class TestRunsService {
private eventsGateway: EventsGateway
) {}

async findMany(buildId: string, take: number, skip: number): Promise<PaginatedTestRunDto> {
const [total, list] = await Promise.all([
this.prismaService.testRun.count({ where: { buildId } }),
this.prismaService.testRun.findMany({
where: { buildId },
take,
skip,
}),
]);
return {
data: list.map((item) => new TestRunDto(item)),
total,
take,
skip,
};
async findMany(buildId: string): Promise<TestRunDto[]> {
const list = await this.prismaService.testRun.findMany({
where: { buildId },
});
return list.map((item) => new TestRunDto(item));
}

async findOne(
Expand Down