Skip to content

Commit aa896f5

Browse files
committed
test module removed
1 parent 7ce7fc1 commit aa896f5

17 files changed

+61
-138
lines changed

src/app.module.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { BuildsModule } from './builds/builds.module';
55
import { ProjectsModule } from './projects/projects.module';
66
import { TestRunsModule } from './test-runs/test-runs.module';
77
import { TestVariationsModule } from './test-variations/test-variations.module';
8-
import { TestModule } from './test/test.module';
98
import { PrismaService } from './prisma/prisma.service';
109
import { ConfigModule } from '@nestjs/config';
1110

@@ -18,7 +17,6 @@ import { ConfigModule } from '@nestjs/config';
1817
ProjectsModule,
1918
TestRunsModule,
2019
TestVariationsModule,
21-
TestModule,
2220
],
2321
providers: [PrismaService],
2422
})
File renamed without changes.
File renamed without changes.

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import { Test, TestingModule } from '@nestjs/testing';
22
import { TestRunsController } from './test-runs.controller';
33
import { TestRunsService } from './test-runs.service';
4+
import { TestVariationsService } from '../test-variations/test-variations.service';
5+
import { PrismaService } from '../prisma/prisma.service';
46

57
describe('TestRuns Controller', () => {
68
let controller: TestRunsController;
79

810
beforeEach(async () => {
911
const module: TestingModule = await Test.createTestingModule({
1012
controllers: [TestRunsController],
11-
providers: [{ provide: TestRunsService, useValue: {} }]
13+
providers: [
14+
{ provide: TestRunsService, useValue: {} },
15+
{ provide: TestVariationsService, useValue: {} },
16+
{ provide: PrismaService, useValue: {} },
17+
],
1218
}).compile();
1319

1420
controller = module.get<TestRunsController>(TestRunsController);

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
import { Controller, Delete, UseGuards, Param, ParseUUIDPipe, Put, Body, Get, Query } from '@nestjs/common';
2-
import { ApiTags, ApiParam, ApiBearerAuth, ApiQuery } from '@nestjs/swagger';
1+
import { Controller, Delete, UseGuards, Param, ParseUUIDPipe, Put, Body, Get, Query, Post } from '@nestjs/common';
2+
import { ApiTags, ApiParam, ApiBearerAuth, ApiQuery, ApiSecurity, ApiOkResponse } from '@nestjs/swagger';
33
import { JwtAuthGuard } from '../auth/guards/auth.guard';
44
import { TestRun } from '@prisma/client';
55
import { TestRunsService } from './test-runs.service';
6-
import { IgnoreAreaDto } from '../test/dto/ignore-area.dto';
6+
import { IgnoreAreaDto } from './dto/ignore-area.dto';
77
import { CommentDto } from '../shared/dto/comment.dto';
8+
import { TestRunResultDto } from './dto/testRunResult.dto';
9+
import { ApiGuard } from '../auth/guards/api.guard';
10+
import { CreateTestRequestDto } from './dto/create-test-request.dto';
811

912
@ApiTags('test-runs')
1013
@Controller('test-runs')
@@ -69,4 +72,12 @@ export class TestRunsController {
6972
updateComment(@Param('testRunId', new ParseUUIDPipe()) id: string, @Body() body: CommentDto): Promise<TestRun> {
7073
return this.testRunsService.updateComment(id, body);
7174
}
75+
76+
@Post()
77+
@ApiSecurity('api_key')
78+
@ApiOkResponse({ type: TestRunResultDto })
79+
@UseGuards(ApiGuard)
80+
postTestRun(@Body() createTestRequestDto: CreateTestRequestDto): Promise<TestRunResultDto> {
81+
return this.testRunsService.postTestRun(createTestRequestDto);
82+
}
7283
}

src/test-runs/test-runs.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { SharedModule } from '../shared/shared.module';
44
import { PrismaService } from '../prisma/prisma.service';
55
import { TestRunsController } from './test-runs.controller';
66
import { EventsGateway } from '../events/events.gateway';
7+
import { TestVariationsModule } from '../test-variations/test-variations.module';
78

89
@Module({
9-
imports: [SharedModule],
10+
imports: [SharedModule, TestVariationsModule],
1011
providers: [TestRunsService, PrismaService, EventsGateway],
1112
exports: [TestRunsService],
1213
controllers: [TestRunsController]

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

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import { StaticService } from '../shared/static/static.service';
66
import { PNG } from 'pngjs';
77
import { TestStatus, Build, TestRun } from '@prisma/client';
88
import Pixelmatch from 'pixelmatch';
9-
import { CreateTestRequestDto } from '../test/dto/create-test-request.dto';
9+
import { CreateTestRequestDto } from './dto/create-test-request.dto';
1010
import { DiffResult } from './diffResult';
11-
import { IgnoreAreaDto } from '../test/dto/ignore-area.dto';
11+
import { IgnoreAreaDto } from './dto/ignore-area.dto';
1212
import { EventsGateway } from '../events/events.gateway';
1313
import { CommentDto } from '../shared/dto/comment.dto';
1414
import { BuildDto } from '../builds/dto/build.dto';
15+
import { TestVariationsService } from '../test-variations/test-variations.service';
1516

1617
jest.mock('pixelmatch');
1718

@@ -43,7 +44,7 @@ const initService = async ({
4344
},
4445
build: {
4546
findOne: buildFindOneMock,
46-
}
47+
},
4748
},
4849
},
4950
{
@@ -58,9 +59,13 @@ const initService = async ({
5859
provide: EventsGateway,
5960
useValue: {
6061
newTestRun: eventNewTestRunMock,
61-
buildUpdated: eventBuildUpdatedMock
62+
buildUpdated: eventBuildUpdatedMock,
6263
},
6364
},
65+
{
66+
provide: TestVariationsService,
67+
useValue: {},
68+
},
6469
],
6570
}).compile();
6671

@@ -113,7 +118,7 @@ describe('TestRunsService', () => {
113118
status: TestStatus.failed,
114119
},
115120
});
116-
expect(service.emitUpdateBuildEvent).toBeCalledWith(testRun.buildId)
121+
expect(service.emitUpdateBuildEvent).toBeCalledWith(testRun.buildId);
117122
});
118123

119124
describe('approve', () => {
@@ -174,7 +179,7 @@ describe('TestRunsService', () => {
174179
},
175180
},
176181
});
177-
expect(service.emitUpdateBuildEvent).toBeCalledWith(testRun.buildId)
182+
expect(service.emitUpdateBuildEvent).toBeCalledWith(testRun.buildId);
178183
});
179184
});
180185

@@ -615,23 +620,23 @@ describe('TestRunsService', () => {
615620
},
616621
],
617622
};
618-
const buildFindOneMock = jest.fn().mockResolvedValueOnce(build)
619-
const eventBuildUpdatedMock = jest.fn()
623+
const buildFindOneMock = jest.fn().mockResolvedValueOnce(build);
624+
const eventBuildUpdatedMock = jest.fn();
620625
service = await initService({
621626
buildFindOneMock,
622627
eventBuildUpdatedMock,
623628
});
624629

625-
await service.emitUpdateBuildEvent(build.id)
630+
await service.emitUpdateBuildEvent(build.id);
626631

627632
expect(buildFindOneMock).toHaveBeenCalledWith({
628633
where: {
629-
id: build.id
634+
id: build.id,
630635
},
631636
include: {
632-
testRuns: true
633-
}
634-
})
635-
expect(eventBuildUpdatedMock).toHaveBeenCalledWith(new BuildDto(build))
636-
})
637+
testRuns: true,
638+
},
639+
});
640+
expect(eventBuildUpdatedMock).toHaveBeenCalledWith(new BuildDto(build));
641+
});
637642
});

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
import { Injectable } from '@nestjs/common';
22
import { PNG } from 'pngjs';
33
import Pixelmatch from 'pixelmatch';
4-
import { CreateTestRequestDto } from '../test/dto/create-test-request.dto';
5-
import { IgnoreAreaDto } from '../test/dto/ignore-area.dto';
4+
import { CreateTestRequestDto } from './dto/create-test-request.dto';
5+
import { IgnoreAreaDto } from './dto/ignore-area.dto';
66
import { StaticService } from '../shared/static/static.service';
77
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';
1111
import { CommentDto } from '../shared/dto/comment.dto';
1212
import { BuildDto } from '../builds/dto/build.dto';
13+
import { TestRunResultDto } from '../test-runs/dto/testRunResult.dto';
14+
import { TestVariationsService } from '../test-variations/test-variations.service';
1315

1416
@Injectable()
1517
export class TestRunsService {
1618
constructor(
19+
private testVariationService: TestVariationsService,
1720
private prismaService: PrismaService,
1821
private staticService: StaticService,
1922
private eventsGateway: EventsGateway,
@@ -40,6 +43,14 @@ export class TestRunsService {
4043
});
4144
}
4245

46+
async postTestRun(createTestRequestDto: CreateTestRequestDto): Promise<TestRunResultDto> {
47+
const testVariation = await this.testVariationService.findOrCreate(createTestRequestDto);
48+
49+
const testRun = await this.create(testVariation, createTestRequestDto);
50+
51+
return new TestRunResultDto(testRun, testVariation);
52+
}
53+
4354
async emitUpdateBuildEvent(buildId: string) {
4455
const build = await this.prismaService.build.findOne({
4556
where: {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { TestVariationsService } from './test-variations.service';
44
import { TestVariation, Baseline } from '@prisma/client';
55
import { JwtAuthGuard } from '../auth/guards/auth.guard';
66
import { PrismaService } from '../prisma/prisma.service';
7-
import { IgnoreAreaDto } from '../test/dto/ignore-area.dto';
7+
import { IgnoreAreaDto } from '../test-runs/dto/ignore-area.dto';
88
import { CommentDto } from '../shared/dto/comment.dto';
99

1010
@ApiTags('test-variations')

0 commit comments

Comments
 (0)