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
90 changes: 44 additions & 46 deletions src/test-runs/test-runs.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ describe('TestRunsService', () => {
});
service.findOne = testRunFindOneMock;

await service.approve(testRun.id, false);
await service.approve(testRun.id);

expect(testRunFindOneMock).toHaveBeenCalledWith(testRun.id);
expect(getImageMock).toHaveBeenCalledWith(testRun.imageName);
Expand All @@ -238,14 +238,14 @@ describe('TestRunsService', () => {
testVariation: {
update: {
baselineName,
baselines: {
create: {
baselineName,
testRun: {
connect: {
id: testRun.id,
},
},
},
},
baseline: {
create: {
baselineName,
testVariation: {
connect: {
id: testRun.testVariationId,
},
},
},
Expand Down Expand Up @@ -318,14 +318,14 @@ describe('TestRunsService', () => {
testVariation: {
update: {
baselineName,
baselines: {
create: {
baselineName,
testRun: {
connect: {
id: testRun.id,
},
},
},
},
baseline: {
create: {
baselineName,
testVariation: {
connect: {
id: testRun.testVariationId,
},
},
},
Expand Down Expand Up @@ -427,39 +427,37 @@ describe('TestRunsService', () => {
expect(testRunFindOneMock).toHaveBeenCalledWith(testRun.id);
expect(getImageMock).toHaveBeenCalledWith(testRun.imageName);
expect(saveImageMock).toHaveBeenCalledTimes(1);
expect(testVariationCreateMock).toBeCalledWith({
data: {
project: { connect: { id: testRun.testVariation.projectId } },
baselineName,
name: testRun.name,
browser: testRun.browser,
device: testRun.device,
os: testRun.os,
viewport: testRun.viewport,
ignoreAreas: testRun.ignoreAreas,
comment: testRun.comment,
branchName: testRun.branchName,
},
});
expect(baselineCreateMock).toHaveBeenCalledWith({
data: {
baselineName,
testVariation: {
connect: { id: newTestVariation.id },
},
testRun: {
connect: {
id: testRun.id,
},
},
},
});
expect(testRunUpdateMock).toHaveBeenCalledWith({
where: { id: testRun.id },
data: {
status: TestStatus.approved,
testVariation: {
connect: { id: newTestVariation.id },
baseline: {
create: {
baselineName,
testVariation: {
create: {
baselineName,
name: testRun.name,
browser: testRun.browser,
device: testRun.device,
os: testRun.os,
viewport: testRun.viewport,
ignoreAreas: testRun.ignoreAreas,
comment: testRun.comment,
branchName: testRun.branchName,
project: {
connect: {
id: testRun.testVariation.projectId,
},
},
testRuns: {
connect: {
id: testRun.id,
},
},
},
},
},
},
},
});
Expand Down
80 changes: 45 additions & 35 deletions src/test-runs/test-runs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,15 @@ export class TestRunsService {
return new TestRunResultDto(testRunWithResult, testVariation);
}

async approve(id: string, merge: boolean, autoApprove?: boolean): Promise<TestRun> {
/**
* Confirm difference for testRun
*
* @param id
* @param merge replaces main branch baseline with feature one
* @param autoApprove set auto approve status
* @returns
*/
async approve(id: string, merge = false, autoApprove = false): Promise<TestRun> {
this.logger.log(`Approving testRun: ${id} merge: ${merge} autoApprove: ${autoApprove}`);
const status = autoApprove ? TestStatus.autoApproved : TestStatus.approved;
const testRun = await this.findOne(id);
Expand All @@ -88,58 +96,60 @@ export class TestRunsService {
const baselineName = this.staticService.saveImage('baseline', PNG.sync.write(baseline));
let testRunUpdated: TestRun;
if (merge || testRun.branchName === testRun.baselineBranchName) {
// update existing test variation
testRunUpdated = await this.prismaService.testRun.update({
where: { id },
data: {
status,
testVariation: {
update: {
baselineName,
baselines: {
create: {
baselineName,
testRun: {
connect: {
id: testRun.id,
},
},
},
},
baseline: {
create: {
baselineName,
testVariation: {
connect: {
id: testRun.testVariationId,
},
},
},
},
},
});
} else {
const newTestVariation = await this.prismaService.testVariation.create({
data: {
project: { connect: { id: testRun.testVariation.projectId } },
baselineName,
...getTestVariationUniqueData(testRun),
ignoreAreas: testRun.ignoreAreas,
comment: testRun.comment,
branchName: testRun.branchName,
},
});
await this.prismaService.baseline.create({
data: {
baselineName,
testVariation: {
connect: { id: newTestVariation.id },
},
testRun: {
connect: {
id: testRun.id,
},
},
},
});
// create new feature branch test variation
testRunUpdated = await this.prismaService.testRun.update({
where: { id },
data: {
status,
testVariation: {
connect: { id: newTestVariation.id },
},
baseline: autoApprove
? undefined
: {
create: {
baselineName,
testVariation: {
create: {
baselineName,
...getTestVariationUniqueData(testRun),
ignoreAreas: testRun.ignoreAreas,
comment: testRun.comment,
branchName: testRun.branchName,
project: {
connect: {
id: testRun.testVariation.projectId,
},
},
testRuns: {
connect: {
id,
},
},
},
},
},
},
},
});
}
Expand Down
Loading