Skip to content

Commit

Permalink
Add an ability to download test report
Browse files Browse the repository at this point in the history
Ref: #5
  • Loading branch information
projkov committed Aug 23, 2024
1 parent 913d8fd commit 5780d29
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/modules/test_runs/testRun.controller.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { Body, Controller, Post, Res } from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { Body, Controller, Get, Param, Post, Res } from '@nestjs/common';
import { ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger';
import { InitiateTestRunDto } from './testRun.dto';
import { Response } from 'express';
import { runCLI } from '@jest/core';
import { TestRunService } from './testRun.service';
import { SessionService } from '../sessions/session.service';
import { TestRun } from './testRun.entity';

@ApiTags('test-runs')
@Controller('test-runs')
export class TestRunController {
requestService: any;
constructor(
private readonly testRunService: TestRunService,
private readonly sessionService: SessionService,
Expand Down Expand Up @@ -46,4 +48,31 @@ export class TestRunController {
res.status(500).json({ message: 'Internal server error', error: error.message });
}
}

@Get(':id')
@ApiOperation({ summary: 'Find a test run by ID' })
@ApiParam({ name: 'id', description: 'Test run ID' })
findOne(@Param('id') id: string): Promise<TestRun> {
return this.testRunService.findOne(id);
}

@Get(':id/report')
@ApiOperation({ summary: 'Find a test run by ID' })
@ApiParam({ name: 'id', description: 'Test run ID' })
async getReport(@Param('id') id: string) {
const testRun = await this.testRunService.findOne(id);
return testRun.testResults;
}

@Get(':id/report/download')
@ApiOperation({ summary: 'Find a test run by ID' })
@ApiParam({ name: 'id', description: 'Test run ID' })
async downloadReportFile(@Param('id') id: string, @Res() res: Response) {
const testRun = await this.testRunService.findOne(id);
const testResults = testRun.testResults;

res.setHeader('Content-Type', 'application/json');
res.setHeader('Content-Disposition', 'attachment; filename="users.json"');
res.send(testResults);
}
}

0 comments on commit 5780d29

Please sign in to comment.