Skip to content

Commit 5397e3b

Browse files
authored
275 tv clean (#153)
* Clean up old test variations Visual-Regression-Tracker/Visual-Regression-Tracker#275
1 parent 78468f4 commit 5397e3b

File tree

13 files changed

+340
-426
lines changed

13 files changed

+340
-426
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Migration `20210709133029-275-project-to-testrun-relation`
2+
3+
This migration has been generated by Pavel Strunkin at 7/9/2021, 4:30:29 PM.
4+
You can check out the [state of the schema](./schema.prisma) after the migration.
5+
6+
## Database Steps
7+
8+
```sql
9+
ALTER TABLE "TestRun" ADD COLUMN "projectId" TEXT
10+
11+
ALTER TABLE "TestRun" ADD FOREIGN KEY("projectId")REFERENCES "Project"("id") ON DELETE SET NULL ON UPDATE CASCADE
12+
```
13+
14+
## Changes
15+
16+
```diff
17+
diff --git schema.prisma schema.prisma
18+
migration 20210709115233-gh-275-max-branch-lifetime..20210709133029-275-project-to-testrun-relation
19+
--- datamodel.dml
20+
+++ datamodel.dml
21+
@@ -3,9 +3,9 @@
22+
}
23+
datasource db {
24+
provider = "postgresql"
25+
- url = "***"
26+
+ url = "***"
27+
}
28+
model Build {
29+
id String @id @default(uuid())
30+
@@ -40,8 +40,9 @@
31+
autoApproveFeature Boolean @default(false)
32+
imageComparison ImageComparison @default(pixelmatch)
33+
imageComparisonConfig String @default("{ \"threshold\": 0.1, \"ignoreAntialiasing\": true, \"allowDiffDimensions\": false }")
34+
+ TestRun TestRun[]
35+
@@unique([name])
36+
}
37+
model TestRun {
38+
@@ -55,8 +56,10 @@
39+
buildId String
40+
build Build @relation(fields: [buildId], references: [id])
41+
testVariationId String?
42+
testVariation TestVariation? @relation(fields: [testVariationId], references: [id])
43+
+ projectId String?
44+
+ project Project? @relation(fields: [projectId], references: [id])
45+
merge Boolean @default(false)
46+
updatedAt DateTime @updatedAt
47+
createdAt DateTime @default(now())
48+
// Test variation data
49+
```
50+
51+
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
generator client {
2+
provider = "prisma-client-js"
3+
}
4+
5+
datasource db {
6+
provider = "postgresql"
7+
url = "***"
8+
}
9+
10+
model Build {
11+
id String @id @default(uuid())
12+
ciBuildId String?
13+
number Int?
14+
branchName String?
15+
status String?
16+
testRuns TestRun[]
17+
projectId String
18+
project Project @relation(fields: [projectId], references: [id])
19+
updatedAt DateTime @updatedAt
20+
createdAt DateTime @default(now())
21+
user User? @relation(fields: [userId], references: [id])
22+
userId String?
23+
isRunning Boolean?
24+
25+
@@unique([projectId, ciBuildId])
26+
}
27+
28+
model Project {
29+
id String @id @default(uuid())
30+
name String
31+
mainBranchName String @default("master")
32+
builds Build[]
33+
buildsCounter Int @default(0)
34+
maxBuildAllowed Int @default(100)
35+
maxBranchLifetime Int @default(30)
36+
testVariations TestVariation[]
37+
updatedAt DateTime @updatedAt
38+
createdAt DateTime @default(now())
39+
// config
40+
autoApproveFeature Boolean @default(false)
41+
imageComparison ImageComparison @default(pixelmatch)
42+
imageComparisonConfig String @default("{ \"threshold\": 0.1, \"ignoreAntialiasing\": true, \"allowDiffDimensions\": false }")
43+
44+
TestRun TestRun[]
45+
@@unique([name])
46+
}
47+
48+
model TestRun {
49+
id String @id @default(uuid())
50+
imageName String
51+
diffName String?
52+
diffPercent Float?
53+
diffTollerancePercent Float @default(0)
54+
pixelMisMatchCount Int?
55+
status TestStatus
56+
buildId String
57+
build Build @relation(fields: [buildId], references: [id])
58+
testVariationId String?
59+
testVariation TestVariation? @relation(fields: [testVariationId], references: [id])
60+
projectId String?
61+
project Project? @relation(fields: [projectId], references: [id])
62+
merge Boolean @default(false)
63+
updatedAt DateTime @updatedAt
64+
createdAt DateTime @default(now())
65+
// Test variation data
66+
name String @default("")
67+
browser String?
68+
device String?
69+
os String?
70+
viewport String?
71+
customTags String? @default("")
72+
baselineName String?
73+
comment String?
74+
baseline Baseline?
75+
branchName String @default("master")
76+
baselineBranchName String?
77+
ignoreAreas String @default("[]")
78+
tempIgnoreAreas String @default("[]")
79+
}
80+
81+
model TestVariation {
82+
id String @id @default(uuid())
83+
name String
84+
branchName String @default("master")
85+
browser String @default("")
86+
device String @default("")
87+
os String @default("")
88+
viewport String @default("")
89+
customTags String @default("")
90+
baselineName String?
91+
ignoreAreas String @default("[]")
92+
projectId String
93+
project Project @relation(fields: [projectId], references: [id])
94+
testRuns TestRun[]
95+
baselines Baseline[]
96+
comment String?
97+
updatedAt DateTime @updatedAt
98+
createdAt DateTime @default(now())
99+
100+
@@unique([projectId, name, browser, device, os, viewport, customTags, branchName])
101+
}
102+
103+
model Baseline {
104+
id String @id @default(uuid())
105+
baselineName String
106+
testVariationId String
107+
testVariation TestVariation @relation(fields: [testVariationId], references: [id])
108+
testRunId String?
109+
testRun TestRun? @relation(fields: [testRunId], references: [id])
110+
userId String?
111+
user User? @relation(fields: [userId], references: [id])
112+
updatedAt DateTime @updatedAt
113+
createdAt DateTime @default(now())
114+
}
115+
116+
model User {
117+
id String @id @default(uuid())
118+
email String @unique
119+
password String
120+
firstName String?
121+
lastName String?
122+
apiKey String @unique
123+
isActive Boolean @default(true)
124+
builds Build[]
125+
baselines Baseline[]
126+
updatedAt DateTime @updatedAt
127+
createdAt DateTime @default(now())
128+
}
129+
130+
enum TestStatus {
131+
failed
132+
new
133+
ok
134+
unresolved
135+
approved
136+
autoApproved
137+
}
138+
139+
enum ImageComparison {
140+
pixelmatch
141+
lookSame
142+
odiff
143+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"version": "0.3.14-fixed",
3+
"steps": [
4+
{
5+
"tag": "CreateField",
6+
"model": "Project",
7+
"field": "TestRun",
8+
"type": "TestRun",
9+
"arity": "List"
10+
},
11+
{
12+
"tag": "CreateField",
13+
"model": "TestRun",
14+
"field": "projectId",
15+
"type": "String",
16+
"arity": "Optional"
17+
},
18+
{
19+
"tag": "CreateField",
20+
"model": "TestRun",
21+
"field": "project",
22+
"type": "Project",
23+
"arity": "Optional"
24+
},
25+
{
26+
"tag": "CreateDirective",
27+
"location": {
28+
"path": {
29+
"tag": "Field",
30+
"model": "TestRun",
31+
"field": "project"
32+
},
33+
"directive": "relation"
34+
}
35+
},
36+
{
37+
"tag": "CreateArgument",
38+
"location": {
39+
"tag": "Directive",
40+
"path": {
41+
"tag": "Field",
42+
"model": "TestRun",
43+
"field": "project"
44+
},
45+
"directive": "relation"
46+
},
47+
"argument": "fields",
48+
"value": "[projectId]"
49+
},
50+
{
51+
"tag": "CreateArgument",
52+
"location": {
53+
"tag": "Directive",
54+
"path": {
55+
"tag": "Field",
56+
"model": "TestRun",
57+
"field": "project"
58+
},
59+
"directive": "relation"
60+
},
61+
"argument": "references",
62+
"value": "[id]"
63+
}
64+
]
65+
}

prisma/migrations/migrate.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@
2121
20210605124856-image-compare-config-as-json
2222
20210612140950-limit-build-number
2323
20210705154453-baseline-author
24-
20210709115233-gh-275-max-branch-lifetime
24+
20210709115233-gh-275-max-branch-lifetime
25+
20210709133029-275-project-to-testrun-relation

prisma/schema.prisma

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ model Project {
4141
imageComparison ImageComparison @default(pixelmatch)
4242
imageComparisonConfig String @default("{ \"threshold\": 0.1, \"ignoreAntialiasing\": true, \"allowDiffDimensions\": false }")
4343
44+
TestRun TestRun[]
4445
@@unique([name])
4546
}
4647

@@ -56,6 +57,8 @@ model TestRun {
5657
build Build @relation(fields: [buildId], references: [id])
5758
testVariationId String?
5859
testVariation TestVariation? @relation(fields: [testVariationId], references: [id])
60+
projectId String?
61+
project Project? @relation(fields: [projectId], references: [id])
5962
merge Boolean @default(false)
6063
updatedAt DateTime @updatedAt
6164
createdAt DateTime @default(now())

src/_data_/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export const generateTestRun = (testRun?: Partial<TestRun>): TestRun => {
7676
status: 'new',
7777
buildId: '146e7a8d-89f0-4565-aa2c-e61efabb0afd',
7878
testVariationId: '3bc4a5bc-006e-4d43-8e4e-eaa132627fca',
79+
projectId: '3bc4a5bc-006e-4d43-8e4e-eaa132627fcc',
7980
updatedAt: new Date(),
8081
createdAt: new Date(),
8182
name: 'ss2f77',

src/builds/builds.service.spec.ts

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Build, TestRun, TestStatus } from '@prisma/client';
77
import { mocked } from 'ts-jest/utils';
88
import { BuildDto } from './dto/build.dto';
99
import { ProjectsService } from '../projects/projects.service';
10+
import { generateTestRun } from '../_data_';
1011

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

@@ -91,34 +92,7 @@ describe('BuildsService', () => {
9192
createdAt: new Date(),
9293
userId: null,
9394
isRunning: true,
94-
testRuns: [
95-
{
96-
id: '10fb5e02-64e0-4cf5-9f17-c00ab3c96658',
97-
imageName: '1592423768112.screenshot.png',
98-
diffName: null,
99-
diffPercent: null,
100-
diffTollerancePercent: 1,
101-
pixelMisMatchCount: null,
102-
status: 'new',
103-
buildId: '146e7a8d-89f0-4565-aa2c-e61efabb0afd',
104-
testVariationId: '3bc4a5bc-006e-4d43-8e4e-eaa132627fca',
105-
updatedAt: new Date(),
106-
createdAt: new Date(),
107-
name: 'ss2f77',
108-
browser: 'chromium',
109-
device: null,
110-
os: null,
111-
viewport: '1800x1600',
112-
customTags: '',
113-
baselineName: null,
114-
ignoreAreas: '[]',
115-
tempIgnoreAreas: '[]',
116-
comment: 'some comment',
117-
branchName: 'develop',
118-
baselineBranchName: 'master',
119-
merge: false,
120-
},
121-
],
95+
testRuns: [generateTestRun()],
12296
};
12397

12498
const buildDto: BuildDto = {
@@ -182,7 +156,13 @@ describe('BuildsService', () => {
182156
const buildDeleteMock = jest.fn().mockImplementation(() => Promise.resolve(build));
183157
const testRunDeleteMock = jest.fn();
184158
const eventBuildDeletedMock = jest.fn();
185-
service = await initService({ buildFindUniqueMock, buildDeleteMock, testRunDeleteMock, eventBuildDeletedMock, buildFindManyMock });
159+
service = await initService({
160+
buildFindUniqueMock,
161+
buildDeleteMock,
162+
testRunDeleteMock,
163+
eventBuildDeletedMock,
164+
buildFindManyMock,
165+
});
186166

187167
await service.remove(build.id);
188168

0 commit comments

Comments
 (0)