Skip to content

Commit b185969

Browse files
committed
POC merge
1 parent c0016f5 commit b185969

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,7 @@ export class TestRunsService {
6969
// create test run result
7070
const testRun = await this.create(testVariation, createTestRequestDto);
7171

72-
// calculate diff
73-
let testRunWithResult = await this.calculateDiff(testRun);
74-
75-
// try auto approve
76-
testRunWithResult = await this.tryAutoApproveByPastBaselines(testVariation, testRunWithResult);
77-
testRunWithResult = await this.tryAutoApproveByNewBaselines(testVariation, testRunWithResult);
78-
return new TestRunResultDto(testRunWithResult, testVariation);
72+
return new TestRunResultDto(testRun, testVariation);
7973
}
8074

8175
/**
@@ -228,7 +222,15 @@ export class TestRunsService {
228222
});
229223

230224
this.eventsGateway.testRunCreated(testRun);
231-
return testRun;
225+
226+
// calculate diff
227+
let testRunWithResult = await this.calculateDiff(testRun);
228+
229+
// try auto approve
230+
testRunWithResult = await this.tryAutoApproveByPastBaselines(testVariation, testRunWithResult);
231+
testRunWithResult = await this.tryAutoApproveByNewBaselines(testVariation, testRunWithResult);
232+
233+
return testRunWithResult;
232234
}
233235

234236
async delete(id: string): Promise<TestRun> {

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,17 @@ export class TestVariationsController {
5252

5353
@Get('merge/')
5454
@ApiQuery({ name: 'projectId', required: true })
55-
@ApiQuery({ name: 'branchName', required: true })
55+
@ApiQuery({ name: 'fromBranch', required: true })
56+
@ApiQuery({ name: 'toBranch', required: true })
5657
@ApiOkResponse({ type: BuildDto })
5758
@ApiBearerAuth()
5859
@UseGuards(JwtAuthGuard)
5960
merge(
6061
@Query('projectId', new ParseUUIDPipe()) projectId: string,
61-
@Query('branchName') branchName: string
62+
@Query('fromBranch') fromBranch: string,
63+
@Query('toBranch') toBranch: string
6264
): Promise<BuildDto> {
63-
return this.testVariations.merge(projectId, branchName);
65+
return this.testVariations.merge(projectId, fromBranch, toBranch);
6466
}
6567

6668
@Delete(':id')

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ export class TestVariationsService {
3939
});
4040
}
4141

42-
async findOrCreate(projectId: string, baselineData: BaselineDataDto): Promise<TestVariation> {
42+
async findOrCreate(projectId: string, baselineData: BaselineDataDto, mainBranchName?: string): Promise<TestVariation> {
4343
const project = await this.prismaService.project.findUnique({ where: { id: projectId } });
4444

4545
const [[mainBranchTestVariation], [currentBranchTestVariation]] = await Promise.all([
4646
// search main branch variation
4747
this.prismaService.testVariation.findMany({
4848
where: {
4949
projectId,
50-
branchName: project.mainBranchName,
50+
branchName: mainBranchName ?? project.mainBranchName,
5151
...getTestVariationUniqueData(baselineData),
5252
},
5353
}),
@@ -92,18 +92,18 @@ export class TestVariationsService {
9292
});
9393
}
9494

95-
async merge(projectId: string, branchName: string): Promise<BuildDto> {
95+
async merge(projectId: string, fromBranch: string, toBranch: string): Promise<BuildDto> {
9696
const project: Project = await this.prismaService.project.findUnique({ where: { id: projectId } });
9797

9898
// create build
9999
const build: BuildDto = await this.buildsService.create({
100-
branchName: project.mainBranchName,
100+
branchName: toBranch,
101101
project: projectId,
102102
});
103103

104104
// find side branch variations
105105
const testVariations: TestVariation[] = await this.prismaService.testVariation.findMany({
106-
where: { projectId, branchName },
106+
where: { projectId, branchName: fromBranch },
107107
});
108108

109109
// compare to main branch variations
@@ -113,10 +113,10 @@ export class TestVariationsService {
113113
try {
114114
const imageBase64 = PNG.sync.write(baseline).toString('base64');
115115

116-
// get main branch variation
116+
// get destination branch variation
117117
const baselineData = convertBaselineDataToQuery({
118118
...sideBranchTestVariation,
119-
branchName: project.mainBranchName,
119+
branchName: toBranch,
120120
});
121121
const mainBranchTestVariation = await this.findOrCreate(projectId, baselineData);
122122

0 commit comments

Comments
 (0)