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
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Migration `20210709133029-275-project-to-testrun-relation`

This migration has been generated by Pavel Strunkin at 7/9/2021, 4:30:29 PM.
You can check out the [state of the schema](./schema.prisma) after the migration.

## Database Steps

```sql
ALTER TABLE "TestRun" ADD COLUMN "projectId" TEXT

ALTER TABLE "TestRun" ADD FOREIGN KEY("projectId")REFERENCES "Project"("id") ON DELETE SET NULL ON UPDATE CASCADE
```

## Changes

```diff
diff --git schema.prisma schema.prisma
migration 20210709115233-gh-275-max-branch-lifetime..20210709133029-275-project-to-testrun-relation
--- datamodel.dml
+++ datamodel.dml
@@ -3,9 +3,9 @@
}
datasource db {
provider = "postgresql"
- url = "***"
+ url = "***"
}
model Build {
id String @id @default(uuid())
@@ -40,8 +40,9 @@
autoApproveFeature Boolean @default(false)
imageComparison ImageComparison @default(pixelmatch)
imageComparisonConfig String @default("{ \"threshold\": 0.1, \"ignoreAntialiasing\": true, \"allowDiffDimensions\": false }")
+ TestRun TestRun[]
@@unique([name])
}
model TestRun {
@@ -55,8 +56,10 @@
buildId String
build Build @relation(fields: [buildId], references: [id])
testVariationId String?
testVariation TestVariation? @relation(fields: [testVariationId], references: [id])
+ projectId String?
+ project Project? @relation(fields: [projectId], references: [id])
merge Boolean @default(false)
updatedAt DateTime @updatedAt
createdAt DateTime @default(now())
// Test variation data
```


Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
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)
maxBuildAllowed Int @default(100)
maxBranchLifetime Int @default(30)
testVariations TestVariation[]
updatedAt DateTime @updatedAt
createdAt DateTime @default(now())
// config
autoApproveFeature Boolean @default(false)
imageComparison ImageComparison @default(pixelmatch)
imageComparisonConfig String @default("{ \"threshold\": 0.1, \"ignoreAntialiasing\": true, \"allowDiffDimensions\": false }")

TestRun TestRun[]
@@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])
projectId String?
project Project? @relation(fields: [projectId], 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])
userId String?
user User? @relation(fields: [userId], 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[]
baselines Baseline[]
updatedAt DateTime @updatedAt
createdAt DateTime @default(now())
}

enum TestStatus {
failed
new
ok
unresolved
approved
autoApproved
}

enum ImageComparison {
pixelmatch
lookSame
odiff
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"version": "0.3.14-fixed",
"steps": [
{
"tag": "CreateField",
"model": "Project",
"field": "TestRun",
"type": "TestRun",
"arity": "List"
},
{
"tag": "CreateField",
"model": "TestRun",
"field": "projectId",
"type": "String",
"arity": "Optional"
},
{
"tag": "CreateField",
"model": "TestRun",
"field": "project",
"type": "Project",
"arity": "Optional"
},
{
"tag": "CreateDirective",
"location": {
"path": {
"tag": "Field",
"model": "TestRun",
"field": "project"
},
"directive": "relation"
}
},
{
"tag": "CreateArgument",
"location": {
"tag": "Directive",
"path": {
"tag": "Field",
"model": "TestRun",
"field": "project"
},
"directive": "relation"
},
"argument": "fields",
"value": "[projectId]"
},
{
"tag": "CreateArgument",
"location": {
"tag": "Directive",
"path": {
"tag": "Field",
"model": "TestRun",
"field": "project"
},
"directive": "relation"
},
"argument": "references",
"value": "[id]"
}
]
}
3 changes: 2 additions & 1 deletion prisma/migrations/migrate.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
20210605124856-image-compare-config-as-json
20210612140950-limit-build-number
20210705154453-baseline-author
20210709115233-gh-275-max-branch-lifetime
20210709115233-gh-275-max-branch-lifetime
20210709133029-275-project-to-testrun-relation
3 changes: 3 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ model Project {
imageComparison ImageComparison @default(pixelmatch)
imageComparisonConfig String @default("{ \"threshold\": 0.1, \"ignoreAntialiasing\": true, \"allowDiffDimensions\": false }")
TestRun TestRun[]
@@unique([name])
}

Expand All @@ -56,6 +57,8 @@ model TestRun {
build Build @relation(fields: [buildId], references: [id])
testVariationId String?
testVariation TestVariation? @relation(fields: [testVariationId], references: [id])
projectId String?
project Project? @relation(fields: [projectId], references: [id])
merge Boolean @default(false)
updatedAt DateTime @updatedAt
createdAt DateTime @default(now())
Expand Down
1 change: 1 addition & 0 deletions src/_data_/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const generateTestRun = (testRun?: Partial<TestRun>): TestRun => {
status: 'new',
buildId: '146e7a8d-89f0-4565-aa2c-e61efabb0afd',
testVariationId: '3bc4a5bc-006e-4d43-8e4e-eaa132627fca',
projectId: '3bc4a5bc-006e-4d43-8e4e-eaa132627fcc',
updatedAt: new Date(),
createdAt: new Date(),
name: 'ss2f77',
Expand Down
38 changes: 9 additions & 29 deletions src/builds/builds.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Build, TestRun, TestStatus } from '@prisma/client';
import { mocked } from 'ts-jest/utils';
import { BuildDto } from './dto/build.dto';
import { ProjectsService } from '../projects/projects.service';
import { generateTestRun } from '../_data_';

jest.mock('./dto/build.dto');

Expand Down Expand Up @@ -91,34 +92,7 @@ describe('BuildsService', () => {
createdAt: new Date(),
userId: null,
isRunning: true,
testRuns: [
{
id: '10fb5e02-64e0-4cf5-9f17-c00ab3c96658',
imageName: '1592423768112.screenshot.png',
diffName: null,
diffPercent: null,
diffTollerancePercent: 1,
pixelMisMatchCount: null,
status: 'new',
buildId: '146e7a8d-89f0-4565-aa2c-e61efabb0afd',
testVariationId: '3bc4a5bc-006e-4d43-8e4e-eaa132627fca',
updatedAt: new Date(),
createdAt: new Date(),
name: 'ss2f77',
browser: 'chromium',
device: null,
os: null,
viewport: '1800x1600',
customTags: '',
baselineName: null,
ignoreAreas: '[]',
tempIgnoreAreas: '[]',
comment: 'some comment',
branchName: 'develop',
baselineBranchName: 'master',
merge: false,
},
],
testRuns: [generateTestRun()],
};

const buildDto: BuildDto = {
Expand Down Expand Up @@ -182,7 +156,13 @@ describe('BuildsService', () => {
const buildDeleteMock = jest.fn().mockImplementation(() => Promise.resolve(build));
const testRunDeleteMock = jest.fn();
const eventBuildDeletedMock = jest.fn();
service = await initService({ buildFindUniqueMock, buildDeleteMock, testRunDeleteMock, eventBuildDeletedMock, buildFindManyMock });
service = await initService({
buildFindUniqueMock,
buildDeleteMock,
testRunDeleteMock,
eventBuildDeletedMock,
buildFindManyMock,
});

await service.remove(build.id);

Expand Down
Loading