diff --git a/prisma/migrations/20210517203552-add-custom-tags/README.md b/prisma/migrations/20210517203552-add-custom-tags/README.md new file mode 100644 index 00000000..2cfcb133 --- /dev/null +++ b/prisma/migrations/20210517203552-add-custom-tags/README.md @@ -0,0 +1,65 @@ +# Migration `20210517203552-add-custom-tags` + +This migration has been generated by Surat Das at 5/17/2021, 1:35:52 PM. +You can check out the [state of the schema](./schema.prisma) after the migration. + +## Database Steps + +```sql +DROP INDEX "TestVariation.projectId_name_browser_device_os_viewport_branchN" + +ALTER TABLE "TestRun" ADD COLUMN "customTags" TEXT DEFAULT E'' + +ALTER TABLE "TestVariation" ADD COLUMN "customTags" TEXT NOT NULL DEFAULT E'' + +CREATE UNIQUE INDEX "TestVariation.projectId_name_browser_device_os_viewport_customTags_branchName_unique" ON "TestVariation"("projectId", "name", "browser", "device", "os", "viewport", "customTags", "branchName") +``` + +## Changes + +```diff +diff --git schema.prisma schema.prisma +migration 20210425191116-github_215_project_config..20210517203552-add-custom-tags +--- datamodel.dml ++++ datamodel.dml +@@ -3,9 +3,9 @@ + } + datasource db { + provider = "postgresql" +- url = "***" ++ url = "***" + } + model Build { + id String @id @default(uuid()) +@@ -64,8 +64,9 @@ + browser String? + device String? + os String? + viewport String? ++ customTags String? @default("") + baselineName String? + comment String? + baseline Baseline? + branchName String @default("master") +@@ -81,8 +82,9 @@ + browser String @default("") + device String @default("") + os String @default("") + viewport String @default("") ++ customTags String @default("") + baselineName String? + ignoreAreas String @default("[]") + projectId String + project Project @relation(fields: [projectId], references: [id]) +@@ -91,9 +93,9 @@ + comment String? + updatedAt DateTime @updatedAt + createdAt DateTime @default(now()) +- @@unique([projectId, name, browser, device, os, viewport, branchName]) ++ @@unique([projectId, name, browser, device, os, viewport, customTags, branchName]) + } + model Baseline { + id String @id @default(uuid()) +``` + + diff --git a/prisma/migrations/20210517203552-add-custom-tags/schema.prisma b/prisma/migrations/20210517203552-add-custom-tags/schema.prisma new file mode 100644 index 00000000..a37836bf --- /dev/null +++ b/prisma/migrations/20210517203552-add-custom-tags/schema.prisma @@ -0,0 +1,137 @@ +generator client { + provider = "prisma-client-js" +} + +datasource db { + provider = "postgresql" + url = "***" +} + +model Build { + id String @id @default(uuid()) + ciBuildId String? + number Int? + branchName String? + status String? + testRuns TestRun[] + projectId String + project Project @relation(fields: [projectId], references: [id]) + updatedAt DateTime @updatedAt + createdAt DateTime @default(now()) + user User? @relation(fields: [userId], references: [id]) + userId String? + isRunning Boolean? + + @@unique([projectId, ciBuildId]) +} + +model Project { + id String @id @default(uuid()) + name String + mainBranchName String @default("master") + builds Build[] + buildsCounter Int @default(0) + testVariations TestVariation[] + updatedAt DateTime @updatedAt + createdAt DateTime @default(now()) + // config + autoApproveFeature Boolean @default(false) + diffDimensionsFeature Boolean @default(false) + ignoreAntialiasing Boolean @default(true) + threshold Float @default(0.1) + imageComparison ImageComparison @default(pixelmatch) + + @@unique([name]) +} + +model TestRun { + id String @id @default(uuid()) + imageName String + diffName String? + diffPercent Float? + diffTollerancePercent Float @default(0) + pixelMisMatchCount Int? + status TestStatus + buildId String + build Build @relation(fields: [buildId], references: [id]) + testVariationId String? + testVariation TestVariation? @relation(fields: [testVariationId], references: [id]) + merge Boolean @default(false) + updatedAt DateTime @updatedAt + createdAt DateTime @default(now()) + // Test variation data + name String @default("") + browser String? + device String? + os String? + viewport String? + customTags String? @default("") + baselineName String? + comment String? + baseline Baseline? + branchName String @default("master") + baselineBranchName String? + ignoreAreas String @default("[]") + tempIgnoreAreas String @default("[]") +} + +model TestVariation { + id String @id @default(uuid()) + name String + branchName String @default("master") + browser String @default("") + device String @default("") + os String @default("") + viewport String @default("") + customTags String @default("") + baselineName String? + ignoreAreas String @default("[]") + projectId String + project Project @relation(fields: [projectId], references: [id]) + testRuns TestRun[] + baselines Baseline[] + comment String? + updatedAt DateTime @updatedAt + createdAt DateTime @default(now()) + + @@unique([projectId, name, browser, device, os, viewport, customTags, branchName]) +} + +model Baseline { + id String @id @default(uuid()) + baselineName String + testVariationId String + testVariation TestVariation @relation(fields: [testVariationId], references: [id]) + testRunId String? + testRun TestRun? @relation(fields: [testRunId], references: [id]) + updatedAt DateTime @updatedAt + createdAt DateTime @default(now()) +} + +model User { + id String @id @default(uuid()) + email String @unique + password String + firstName String? + lastName String? + apiKey String @unique + isActive Boolean @default(true) + builds Build[] + updatedAt DateTime @updatedAt + createdAt DateTime @default(now()) +} + +enum TestStatus { + failed + new + ok + unresolved + approved + autoApproved +} + +enum ImageComparison { + pixelmatch + lookSame + odiff +} diff --git a/prisma/migrations/20210517203552-add-custom-tags/steps.json b/prisma/migrations/20210517203552-add-custom-tags/steps.json new file mode 100644 index 00000000..82fab038 --- /dev/null +++ b/prisma/migrations/20210517203552-add-custom-tags/steps.json @@ -0,0 +1,101 @@ +{ + "version": "0.3.14-fixed", + "steps": [ + { + "tag": "CreateField", + "model": "TestRun", + "field": "customTags", + "type": "String", + "arity": "Optional" + }, + { + "tag": "CreateDirective", + "location": { + "path": { + "tag": "Field", + "model": "TestRun", + "field": "customTags" + }, + "directive": "default" + } + }, + { + "tag": "CreateArgument", + "location": { + "tag": "Directive", + "path": { + "tag": "Field", + "model": "TestRun", + "field": "customTags" + }, + "directive": "default" + }, + "argument": "", + "value": "\"\"" + }, + { + "tag": "CreateField", + "model": "TestVariation", + "field": "customTags", + "type": "String", + "arity": "Required" + }, + { + "tag": "CreateDirective", + "location": { + "path": { + "tag": "Field", + "model": "TestVariation", + "field": "customTags" + }, + "directive": "default" + } + }, + { + "tag": "CreateArgument", + "location": { + "tag": "Directive", + "path": { + "tag": "Field", + "model": "TestVariation", + "field": "customTags" + }, + "directive": "default" + }, + "argument": "", + "value": "\"\"" + }, + { + "tag": "CreateDirective", + "location": { + "path": { + "tag": "Model", + "model": "TestVariation", + "arguments": [ + { + "name": "", + "value": "[projectId, name, browser, device, os, viewport, customTags, branchName]" + } + ] + }, + "directive": "unique" + } + }, + { + "tag": "DeleteDirective", + "location": { + "path": { + "tag": "Model", + "model": "TestVariation", + "arguments": [ + { + "name": "", + "value": "[projectId, name, browser, device, os, viewport, branchName]" + } + ] + }, + "directive": "unique" + } + } + ] +} \ No newline at end of file diff --git a/prisma/migrations/migrate.lock b/prisma/migrations/migrate.lock index 6ccd928e..3ba4c1d4 100644 --- a/prisma/migrations/migrate.lock +++ b/prisma/migrations/migrate.lock @@ -16,4 +16,5 @@ 20210130115922-test-run-auto-approve-status-added 20210228121726-test-run--nullable-test-variation-id 20210405171118-github_243-set-empty-test-variation-tags-instead-of-null -20210425191116-github_215_project_config \ No newline at end of file +20210425191116-github_215_project_config +20210517203552-add-custom-tags \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 73a26a07..cdf2cd1b 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -65,6 +65,7 @@ model TestRun { device String? os String? viewport String? + customTags String? @default("") baselineName String? comment String? baseline Baseline? @@ -82,6 +83,7 @@ model TestVariation { device String @default("") os String @default("") viewport String @default("") + customTags String @default("") baselineName String? ignoreAreas String @default("[]") projectId String @@ -92,7 +94,7 @@ model TestVariation { updatedAt DateTime @updatedAt createdAt DateTime @default(now()) - @@unique([projectId, name, browser, device, os, viewport, branchName]) + @@unique([projectId, name, browser, device, os, viewport, customTags, branchName]) } model Baseline { diff --git a/src/_data_/index.ts b/src/_data_/index.ts index a6e7b6f0..453f7ce3 100644 --- a/src/_data_/index.ts +++ b/src/_data_/index.ts @@ -52,6 +52,7 @@ export const generateTestVariation = ( browser: 'browser', viewport: 'viewport', device: 'device', + customTags: '', ignoreAreas: '[]', comment: 'some comment', createdAt: new Date(), @@ -80,6 +81,7 @@ export const generateTestRun = (testRun?: Partial): TestRun => { device: null, os: null, viewport: '1800x1600', + customTags: '', baselineName: null, ignoreAreas: '[]', tempIgnoreAreas: '[]', diff --git a/src/builds/builds.service.spec.ts b/src/builds/builds.service.spec.ts index 7d927cfe..0823bfb5 100644 --- a/src/builds/builds.service.spec.ts +++ b/src/builds/builds.service.spec.ts @@ -108,6 +108,7 @@ describe('BuildsService', () => { device: null, os: null, viewport: '1800x1600', + customTags:'', baselineName: null, ignoreAreas: '[]', tempIgnoreAreas: '[]', diff --git a/src/builds/dto/build.dto.spec.ts b/src/builds/dto/build.dto.spec.ts index c9b04afb..172d1a86 100644 --- a/src/builds/dto/build.dto.spec.ts +++ b/src/builds/dto/build.dto.spec.ts @@ -92,6 +92,7 @@ describe('BuildDto', () => { device: null, os: null, viewport: '1800x1600', + customTags: '', baselineName: null, ignoreAreas: '[]', tempIgnoreAreas: '[]', @@ -117,6 +118,7 @@ describe('BuildDto', () => { device: null, os: null, viewport: '1800x1600', + customTags: '', baselineName: null, ignoreAreas: '[]', tempIgnoreAreas: '[]', @@ -179,6 +181,7 @@ describe('BuildDto', () => { device: null, os: null, viewport: '1800x1600', + customTags: '', baselineName: null, ignoreAreas: '[]', tempIgnoreAreas: '[]', @@ -204,6 +207,7 @@ describe('BuildDto', () => { device: null, os: null, viewport: '1800x1600', + customTags: '', baselineName: null, ignoreAreas: '[]', tempIgnoreAreas: '[]', @@ -229,6 +233,7 @@ describe('BuildDto', () => { device: null, os: null, viewport: '1800x1600', + customTags: '', baselineName: null, ignoreAreas: '[]', tempIgnoreAreas: '[]', @@ -291,6 +296,7 @@ describe('BuildDto', () => { device: null, os: null, viewport: '1800x1600', + customTags: '', baselineName: null, ignoreAreas: '[]', tempIgnoreAreas: '[]', @@ -316,6 +322,7 @@ describe('BuildDto', () => { device: null, os: null, viewport: '1800x1600', + customTags: '', baselineName: null, ignoreAreas: '[]', tempIgnoreAreas: '[]', @@ -341,6 +348,7 @@ describe('BuildDto', () => { device: null, os: null, viewport: '1800x1600', + customTags: '', baselineName: null, ignoreAreas: '[]', tempIgnoreAreas: '[]', @@ -366,6 +374,7 @@ describe('BuildDto', () => { device: null, os: null, viewport: '1800x1600', + customTags: '', baselineName: null, ignoreAreas: '[]', tempIgnoreAreas: '[]', @@ -391,6 +400,7 @@ describe('BuildDto', () => { device: null, os: null, viewport: '1800x1600', + customTags: '', baselineName: null, ignoreAreas: '[]', tempIgnoreAreas: '[]', diff --git a/src/shared/dto/baseline-data.dto.ts b/src/shared/dto/baseline-data.dto.ts index 5e2cf394..e648455c 100644 --- a/src/shared/dto/baseline-data.dto.ts +++ b/src/shared/dto/baseline-data.dto.ts @@ -26,6 +26,11 @@ export class BaselineDataDto { @IsString() device?: string; + @ApiProperty() + @IsOptional() + @IsString() + customTags?: string; + @ApiProperty() @IsString() branchName: string; diff --git a/src/shared/dto/custom-tags.dto.ts b/src/shared/dto/custom-tags.dto.ts new file mode 100644 index 00000000..091aa1e3 --- /dev/null +++ b/src/shared/dto/custom-tags.dto.ts @@ -0,0 +1,8 @@ +import { ApiProperty } from '@nestjs/swagger'; +import { IsString } from 'class-validator'; + +export class CustomTagsDto { + @ApiProperty() + @IsString() + customTags: string; +} diff --git a/src/test-runs/dto/testRun.dto.ts b/src/test-runs/dto/testRun.dto.ts index 07c0c303..23929c1f 100644 --- a/src/test-runs/dto/testRun.dto.ts +++ b/src/test-runs/dto/testRun.dto.ts @@ -31,6 +31,8 @@ export class TestRunDto { @ApiProperty() device: string; @ApiProperty() + customTags: string; + @ApiProperty() ignoreAreas: string; @ApiProperty() tempIgnoreAreas: string; @@ -58,6 +60,7 @@ export class TestRunDto { this.browser = testRun.browser; this.viewport = testRun.viewport; this.device = testRun.device; + this.customTags = testRun.customTags; this.ignoreAreas = testRun.ignoreAreas; this.tempIgnoreAreas = testRun.tempIgnoreAreas; this.comment = testRun.comment; diff --git a/src/test-runs/test-runs.controller.ts b/src/test-runs/test-runs.controller.ts index 37bfa940..78b7a25a 100644 --- a/src/test-runs/test-runs.controller.ts +++ b/src/test-runs/test-runs.controller.ts @@ -37,11 +37,12 @@ import { FileInterceptor } from '@nestjs/platform-express'; import { CreateTestRequestBase64Dto } from './dto/create-test-request-base64.dto'; import { CreateTestRequestMultipartDto } from './dto/create-test-request-multipart.dto'; import { FileToBodyInterceptor } from '../shared/fite-to-body.interceptor'; +import { CustomTagsDto } from '../shared/dto/custom-tags.dto'; @ApiTags('test-runs') @Controller('test-runs') export class TestRunsController { - constructor(private testRunsService: TestRunsService) {} + constructor(private testRunsService: TestRunsService) { } @Get() @ApiOkResponse({ type: [TestRunDto] }) @@ -98,6 +99,14 @@ export class TestRunsController { return this.testRunsService.updateComment(id, body); } + @Put('customTags/:testRunId') + @ApiParam({ name: 'testRunId', required: true }) + @ApiBearerAuth() + @UseGuards(JwtAuthGuard) + updateCustomTags(@Param('testRunId', new ParseUUIDPipe()) id: string, @Body() body: CustomTagsDto): Promise { + return this.testRunsService.updateCustomTags(id, body); + } + @Post() @ApiSecurity('api_key') @ApiOkResponse({ type: TestRunResultDto }) diff --git a/src/test-runs/test-runs.service.spec.ts b/src/test-runs/test-runs.service.spec.ts index f536b7a0..3747f9b1 100644 --- a/src/test-runs/test-runs.service.spec.ts +++ b/src/test-runs/test-runs.service.spec.ts @@ -16,6 +16,7 @@ import { generateBaseline, generateTestRun, generateTestVariation, TEST_PROJECT import { getTestVariationUniqueData } from '../utils'; import { BaselineDataDto } from '../shared/dto/baseline-data.dto'; import { CompareService } from '../compare/compare.service'; +import { CustomTagsDto } from '../shared/dto/custom-tags.dto'; jest.mock('pixelmatch'); jest.mock('./dto/testRunResult.dto'); @@ -174,6 +175,7 @@ describe('TestRunsService', () => { browser: 'browser', viewport: 'viewport', device: 'device', + customTags: '', diffTollerancePercent: undefined, branchName: 'develop', merge: true, @@ -213,6 +215,7 @@ describe('TestRunsService', () => { browser: 'browser', viewport: 'viewport', device: 'device', + customTags: '', ignoreAreas: '[{"x":3,"y":4,"width":500,"height":600}]', comment: 'some comment', createdAt: new Date(), @@ -271,6 +274,7 @@ describe('TestRunsService', () => { device: testVariation.device, os: testVariation.os, viewport: testVariation.viewport, + customTags:testVariation.customTags, baselineName: testVariation.baselineName, ignoreAreas: testVariation.ignoreAreas, tempIgnoreAreas: JSON.stringify(createTestRequestDto.ignoreAreas), @@ -304,6 +308,7 @@ describe('TestRunsService', () => { device: null, os: null, viewport: '1800x1600', + customTags: '', ignoreAreas: JSON.stringify(ignoreAreas), tempIgnoreAreas: JSON.stringify(tempIgnoreAreas), comment: 'some comment', @@ -361,6 +366,7 @@ describe('TestRunsService', () => { device: null, os: null, viewport: '1800x1600', + customTags: '', ignoreAreas: JSON.stringify(ignoreAreas), tempIgnoreAreas: JSON.stringify(tempIgnoreAreas), comment: 'some comment', @@ -441,6 +447,7 @@ describe('TestRunsService', () => { device: null, os: null, viewport: '1800x1600', + customTags: '', baselineName: null, ignoreAreas: '[]', tempIgnoreAreas: '[]', @@ -546,6 +553,29 @@ describe('TestRunsService', () => { expect(eventTestRunUpdatedMock).toHaveBeenCalledWith(id); }); + it('update custom tags', async () => { + const id = 'some id'; + const customTagDto: CustomTagsDto = { + customTags: 'random tag', + }; + const testRunUpdateMock = jest.fn().mockResolvedValueOnce(id); + const eventTestRunUpdatedMock = jest.fn(); + service = await initService({ + testRunUpdateMock, + eventTestRunUpdatedMock, + }); + + await service.updateCustomTags(id, customTagDto); + + expect(testRunUpdateMock).toHaveBeenCalledWith({ + where: { id }, + data: { + customTags: customTagDto.customTags, + }, + }); + expect(eventTestRunUpdatedMock).toHaveBeenCalledWith(id); + }); + it('postTestRun', async () => { const createTestRequestDto: CreateTestRequestDto = { buildId: 'buildId', @@ -566,6 +596,7 @@ describe('TestRunsService', () => { browser: 'browser', viewport: 'viewport', device: 'device', + customTags: '', ignoreAreas: '[]', comment: 'some comment', createdAt: new Date(), @@ -587,6 +618,7 @@ describe('TestRunsService', () => { name: 'ss2f77', browser: 'chromium', device: null, + customTags: '', os: null, viewport: '1800x1600', baselineName: null, diff --git a/src/test-runs/test-runs.service.ts b/src/test-runs/test-runs.service.ts index feffb8dd..c4bd2b47 100644 --- a/src/test-runs/test-runs.service.ts +++ b/src/test-runs/test-runs.service.ts @@ -13,6 +13,7 @@ import { TestVariationsService } from '../test-variations/test-variations.servic import { TestRunDto } from './dto/testRun.dto'; import { getTestVariationUniqueData } from '../utils'; import { CompareService } from '../compare/compare.service'; +import { CustomTagsDto } from '../shared/dto/custom-tags.dto'; @Injectable() export class TestRunsService { @@ -25,7 +26,7 @@ export class TestRunsService { private staticService: StaticService, private compareService: CompareService, private eventsGateway: EventsGateway - ) {} + ) { } async findMany(buildId: string): Promise { const list = await this.prismaService.testRun.findMany({ @@ -261,6 +262,20 @@ export class TestRunsService { }); } + async updateCustomTags(id: string, customTagsDto: CustomTagsDto): Promise { + return this.prismaService.testRun + .update({ + where: { id }, + data: { + customTags: customTagsDto.customTags, + }, + }) + .then((testRun) => { + this.eventsGateway.testRunUpdated(testRun); + return testRun; + }); + } + private getIgnoteAreas(testRun: TestRun): IgnoreAreaDto[] { let ignoreAreas: IgnoreAreaDto[] = JSON.parse(testRun.ignoreAreas); if (testRun.ignoreAreas?.length > 0) { diff --git a/src/test-variations/test-variations.controller.ts b/src/test-variations/test-variations.controller.ts index 840bf22a..c3c2eedb 100644 --- a/src/test-variations/test-variations.controller.ts +++ b/src/test-variations/test-variations.controller.ts @@ -7,11 +7,12 @@ import { PrismaService } from '../prisma/prisma.service'; import { IgnoreAreaDto } from '../test-runs/dto/ignore-area.dto'; import { CommentDto } from '../shared/dto/comment.dto'; import { BuildDto } from '../builds/dto/build.dto'; +import { CustomTagsDto } from '../shared/dto/custom-tags.dto'; @ApiTags('test-variations') @Controller('test-variations') export class TestVariationsController { - constructor(private testVariations: TestVariationsService, private prismaService: PrismaService) {} + constructor(private testVariations: TestVariationsService, private prismaService: PrismaService) { } @Get() @ApiQuery({ name: 'projectId', required: true }) @@ -50,6 +51,14 @@ export class TestVariationsController { return this.testVariations.updateComment(id, body); } + @Put('customTags/:id') + @ApiParam({ name: 'id', required: true }) + @ApiBearerAuth() + @UseGuards(JwtAuthGuard) + updateCustomTags(@Param('id', new ParseUUIDPipe()) id: string, @Body() body: CustomTagsDto): Promise { + return this.testVariations.updateCustomTags(id, body); + } + @Get('merge/') @ApiQuery({ name: 'projectId', required: true }) @ApiQuery({ name: 'branchName', required: true }) diff --git a/src/test-variations/test-variations.service.spec.ts b/src/test-variations/test-variations.service.spec.ts index 8e960702..db295b50 100644 --- a/src/test-variations/test-variations.service.spec.ts +++ b/src/test-variations/test-variations.service.spec.ts @@ -6,6 +6,7 @@ import { StaticService } from '../shared/static/static.service'; import { IgnoreAreaDto } from '../test-runs/dto/ignore-area.dto'; import { TestVariation, Baseline, Project, Build } from '@prisma/client'; import { CommentDto } from '../shared/dto/comment.dto'; +import { CustomTagsDto } from '../shared/dto/custom-tags.dto'; import { PNG } from 'pngjs'; import { BuildsService } from '../builds/builds.service'; import { TestRunsService } from '../test-runs/test-runs.service'; @@ -120,6 +121,7 @@ describe('TestVariationsService', () => { browser: 'browser', viewport: 'viewport', device: 'device', + customTags: '', branchName: 'develop', }; @@ -132,6 +134,7 @@ describe('TestVariationsService', () => { browser: 'browser', viewport: 'viewport', device: 'device', + customTags: '', ignoreAreas: '[]', comment: 'some comment', branchName: 'develop', @@ -155,6 +158,7 @@ describe('TestVariationsService', () => { browser: createRequest.browser, viewport: createRequest.viewport, device: createRequest.device, + customTags: createRequest.customTags, branchName: projectMock.mainBranchName, }); expect(service.findUnique).toHaveBeenNthCalledWith(2, { @@ -164,6 +168,7 @@ describe('TestVariationsService', () => { browser: createRequest.browser, viewport: createRequest.viewport, device: createRequest.device, + customTags: createRequest.customTags, branchName: createRequest.branchName, }); expect(result).toBe(variationMock); @@ -178,6 +183,7 @@ describe('TestVariationsService', () => { browser: 'browser', viewport: 'viewport', device: 'device', + customTags: '', branchName: 'develop', }; @@ -190,6 +196,7 @@ describe('TestVariationsService', () => { browser: 'browser', viewport: 'viewport', device: 'device', + customTags: '', ignoreAreas: '[]', comment: 'some comment', branchName: 'develop', @@ -213,6 +220,7 @@ describe('TestVariationsService', () => { browser: createRequest.browser, viewport: createRequest.viewport, device: createRequest.device, + customTags: createRequest.customTags, branchName: projectMock.mainBranchName, }); expect(service.findUnique).toHaveBeenNthCalledWith(2, { @@ -222,6 +230,7 @@ describe('TestVariationsService', () => { browser: createRequest.browser, viewport: createRequest.viewport, device: createRequest.device, + customTags: createRequest.customTags, branchName: createRequest.branchName, }); expect(result).toBe(variationMock); @@ -236,6 +245,7 @@ describe('TestVariationsService', () => { browser: 'browser', viewport: 'viewport', device: 'device', + customTags:'', branchName: 'develop', }; @@ -248,6 +258,7 @@ describe('TestVariationsService', () => { browser: 'browser', viewport: 'viewport', device: 'device', + customTags: '', ignoreAreas: '[]', comment: 'some comment', branchName: 'master', @@ -263,6 +274,7 @@ describe('TestVariationsService', () => { browser: 'browser', viewport: 'viewport', device: 'device', + customTags: '', ignoreAreas: '[]', comment: 'some comment', branchName: 'develop', @@ -289,6 +301,7 @@ describe('TestVariationsService', () => { browser: createRequest.browser, viewport: createRequest.viewport, device: createRequest.device, + customTags:createRequest.customTags, branchName: projectMock.mainBranchName, }); expect(service.findUnique).toHaveBeenNthCalledWith(2, { @@ -298,6 +311,7 @@ describe('TestVariationsService', () => { browser: createRequest.browser, viewport: createRequest.viewport, device: createRequest.device, + customTags:createRequest.customTags, branchName: createRequest.branchName, }); expect(result).toBe(variationMainMock); @@ -312,6 +326,7 @@ describe('TestVariationsService', () => { browser: 'browser', viewport: 'viewport', device: 'device', + customTags : '', branchName: 'develop', }; @@ -332,6 +347,7 @@ describe('TestVariationsService', () => { browser: createRequest.browser, viewport: createRequest.viewport, device: createRequest.device, + customTags:createRequest.customTags, branchName: createRequest.branchName, project: { connect: { @@ -390,6 +406,26 @@ describe('TestVariationsService', () => { }); }); + it('updateCustomTags', async () => { + const id = 'some id'; + const customTagsDto: CustomTagsDto = { + customTags: 'random tag', + }; + const variationUpdateMock = jest.fn(); + service = await initModule({ + variationUpdateMock, + }); + + await service.updateCustomTags(id, customTagsDto); + + expect(variationUpdateMock).toHaveBeenCalledWith({ + where: { id }, + data: { + customTags: customTagsDto.customTags, + }, + }); + }); + it('merge', async () => { const mergedBranch = 'develop'; const project: Project = TEST_PROJECT; @@ -414,6 +450,7 @@ describe('TestVariationsService', () => { browser: 'browser', viewport: 'viewport', device: 'device', + customTags: '', ignoreAreas: '[]', comment: 'some comment', createdAt: new Date(), @@ -429,6 +466,7 @@ describe('TestVariationsService', () => { browser: 'browser', viewport: 'viewport', device: 'device', + customTags: '', ignoreAreas: '[]', comment: 'some comment', createdAt: new Date(), @@ -444,6 +482,7 @@ describe('TestVariationsService', () => { browser: 'browser', viewport: 'viewport', device: 'device', + customTags: '', ignoreAreas: '[]', comment: 'some comment', createdAt: new Date(), @@ -459,6 +498,7 @@ describe('TestVariationsService', () => { browser: 'browser', viewport: 'viewport', device: 'device', + customTags: '', ignoreAreas: '[]', comment: 'some comment', createdAt: new Date(), @@ -508,6 +548,7 @@ describe('TestVariationsService', () => { device: testVariation.device, browser: testVariation.browser, viewport: testVariation.viewport, + customTags:testVariation.customTags, branchName: project.mainBranchName, }); @@ -552,6 +593,7 @@ describe('TestVariationsService', () => { browser: 'browser', viewport: 'viewport', device: 'device', + customTags: '', ignoreAreas: '[]', comment: 'some comment', branchName: 'develop', diff --git a/src/test-variations/test-variations.service.ts b/src/test-variations/test-variations.service.ts index c8728adb..ebd4b088 100644 --- a/src/test-variations/test-variations.service.ts +++ b/src/test-variations/test-variations.service.ts @@ -5,7 +5,7 @@ import { TestVariation, Baseline, Project, - ProjectIdNameBrowserDeviceOsViewportBranchNameCompoundUniqueInput, + ProjectIdNameBrowserDeviceOsViewportCustomTagsBranchNameCompoundUniqueInput, Prisma, TestRun, Build, @@ -19,6 +19,7 @@ import { PNG } from 'pngjs'; import { CreateTestRequestDto } from 'src/test-runs/dto/create-test-request.dto'; import { BuildDto } from 'src/builds/dto/build.dto'; import { getTestVariationUniqueData } from '../utils'; +import { CustomTagsDto } from 'src/shared/dto/custom-tags.dto'; @Injectable() export class TestVariationsService { @@ -29,7 +30,7 @@ export class TestVariationsService { private testRunsService: TestRunsService, @Inject(forwardRef(() => BuildsService)) private buildsService: BuildsService - ) {} + ) { } async getDetails(id: string): Promise { return this.prismaService.testVariation.findUnique({ @@ -48,11 +49,11 @@ export class TestVariationsService { } async findUnique( - uniqueInput: Prisma.ProjectIdNameBrowserDeviceOsViewportBranchNameCompoundUniqueInput + uniqueInput: Prisma.ProjectIdNameBrowserDeviceOsViewportCustomTagsBranchNameCompoundUniqueInput ): Promise { return this.prismaService.testVariation.findUnique({ where: { - projectId_name_browser_device_os_viewport_branchName: uniqueInput, + projectId_name_browser_device_os_viewport_customTags_branchName: uniqueInput, }, }); } @@ -68,7 +69,7 @@ export class TestVariationsService { }) { return this.prismaService.testVariation.upsert({ where: { - projectId_name_browser_device_os_viewport_branchName: { + projectId_name_browser_device_os_viewport_customTags_branchName: { projectId, branchName: testRun.branchName, ...getTestVariationUniqueData(testRun), @@ -121,11 +122,11 @@ export class TestVariationsService { }), // search current branch variation baselineData.branchName !== project.mainBranchName && - this.findUnique({ - projectId, - branchName: baselineData.branchName, - ...getTestVariationUniqueData(baselineData), - }), + this.findUnique({ + projectId, + branchName: baselineData.branchName, + ...getTestVariationUniqueData(baselineData), + }), ]); if (!!currentBranchTestVariation) { @@ -166,6 +167,15 @@ export class TestVariationsService { }); } + async updateCustomTags(id: string, customTagsDto: CustomTagsDto): Promise { + return this.prismaService.testVariation.update({ + where: { id }, + data: { + customTags: customTagsDto.customTags, + }, + }); + } + async addBaseline({ id, testRunId, diff --git a/src/utils/index.ts b/src/utils/index.ts index 4c999af6..89552f90 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -9,6 +9,7 @@ export const getTestVariationUniqueData = ( device: string; browser: string; viewport: string; + customTags: string; } => { return { name: object.name, @@ -16,5 +17,6 @@ export const getTestVariationUniqueData = ( device: object.device ?? '', browser: object.browser ?? '', viewport: object.viewport ?? '', + customTags: object.customTags ?? '', }; };