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
35 changes: 1 addition & 34 deletions src/test-variations/test-variations.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,37 +466,12 @@ describe('TestVariationsService', () => {
ignoreAreas: JSON.parse(testVariationSecond.ignoreAreas),
});
expect(testRunCreateMock).toHaveBeenCalledTimes(2);
expect(buildUpdateMock).toHaveBeenCalledWith(build.id, { "isRunning": false });
expect(buildUpdateMock).toHaveBeenCalledWith(build.id, { isRunning: false });
});

it('delete', async () => {
const testRunId = 'test run id';
const testVariationId = 'test variation id';
const testRun: TestRun = {
id: testRunId,
imageName: '1592423768112.screenshot.png',
diffName: null,
diffPercent: null,
diffTollerancePercent: 1,
pixelMisMatchCount: null,
status: 'new',
buildId: '146e7a8d-89f0-4565-aa2c-e61efabb0afd',
testVariationId: testVariationId,
updatedAt: new Date(),
createdAt: new Date(),
name: 'ss2f77',
browser: 'chromium',
device: null,
os: null,
viewport: '1800x1600',
baselineName: null,
ignoreAreas: '[]',
tempIgnoreAreas: '[]',
comment: 'some comment',
baselineBranchName: 'master',
branchName: 'develop',
merge: false,
};
const variation: TestVariation & {
baselines: Baseline[];
} = {
Expand Down Expand Up @@ -526,25 +501,17 @@ describe('TestVariationsService', () => {
};

const variationDeleteMock = jest.fn();
const testRunFindMany = jest.fn().mockResolvedValueOnce([testRun]);
const testRunDeleteMock = jest.fn();
const getDetailsMock = jest.fn().mockResolvedValueOnce(variation);
const deleteBaselineMock = jest.fn().mockResolvedValueOnce(variation.baselines[0]);
const service = await initModule({
variationDeleteMock,
testRunFindMany,
testRunDeleteMock,
});
service.getDetails = getDetailsMock;
service.deleteBaseline = deleteBaselineMock;

await service.delete(testVariationId);

expect(service.getDetails).toHaveBeenCalledWith(testVariationId);
expect(testRunFindMany).toHaveBeenCalledWith({
where: { testVariationId },
});
expect(testRunDeleteMock).toHaveBeenCalledWith(testRunId);
expect(service.deleteBaseline).toHaveBeenCalledWith(variation.baselines[0]);
expect(variationDeleteMock).toHaveBeenCalledWith({
where: { id: testVariationId },
Expand Down
14 changes: 3 additions & 11 deletions src/test-variations/test-variations.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class TestVariationsService {
private testRunsService: TestRunsService,
@Inject(forwardRef(() => BuildsService))
private buildsService: BuildsService
) { }
) {}

async getDetails(id: string): Promise<TestVariation & { baselines: Baseline[] }> {
return this.prismaService.testVariation.findUnique({
Expand Down Expand Up @@ -138,19 +138,11 @@ export class TestVariationsService {
});

// stop build
return this.buildsService.update(build.id, { "isRunning": false });
return this.buildsService.update(build.id, { isRunning: false });
}

async delete(id: string): Promise<TestVariation> {
const [testVariation, testRuns] = await Promise.all([
this.getDetails(id),
this.prismaService.testRun.findMany({
where: { testVariationId: id },
}),
]);

// delete testRun
await Promise.all(testRuns.map((item) => this.testRunsService.delete(item.id)));
const testVariation = await this.getDetails(id);

// delete baseline
await Promise.all(testVariation.baselines.map((baseline) => this.deleteBaseline(baseline)));
Expand Down