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,76 @@
# Migration `20210228121726-test-run--nullable-test-variation-id`

This migration has been generated by Pavel Strunkin at 2/28/2021, 2:17:26 PM.
You can check out the [state of the schema](./schema.prisma) after the migration.

## Database Steps

```sql
ALTER TYPE "TestStatus" ADD VALUE 'autoApproved'
```

## Changes

```diff
diff --git schema.prisma schema.prisma
migration 20210130115922-test-run-auto-approve-status-added..20210228121726-test-run--nullable-test-variation-id
--- datamodel.dml
+++ datamodel.dml
@@ -3,9 +3,9 @@
}
datasource db {
provider = "postgresql"
- url = "***"
+ url = "***"
}
model Build {
id String @id @default(uuid())
@@ -38,35 +38,35 @@
@@unique([name])
}
model TestRun {
- id String @id @default(uuid())
+ id String @id @default(uuid())
imageName String
diffName String?
diffPercent Float?
- diffTollerancePercent Float @default(0)
+ 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())
+ 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("")
+ name String @default("")
browser String?
device String?
os String?
viewport String?
baselineName String?
comment String?
baseline Baseline?
- branchName String @default("master")
+ branchName String @default("master")
baselineBranchName String?
- ignoreAreas String @default("[]")
- tempIgnoreAreas String @default("[]")
+ ignoreAreas String @default("[]")
+ tempIgnoreAreas String @default("[]")
}
model TestVariation {
id String @id @default(uuid())
```


Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
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())

@@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?
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?
device String?
os String?
viewport String?
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, 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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": "0.3.14-fixed",
"steps": [
{
"tag": "UpdateField",
"model": "TestRun",
"field": "testVariationId",
"arity": "Optional"
},
{
"tag": "UpdateField",
"model": "TestRun",
"field": "testVariation",
"arity": "Optional"
}
]
}
3 changes: 2 additions & 1 deletion prisma/migrations/migrate.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
20201115155739-ci-build-id-added
20201201211711-test-run--temp-ignore-areas-added
20210118201534-build--project-id---ci-build-id-constraint
20210130115922-test-run-auto-approve-status-added
20210130115922-test-run-auto-approve-status-added
20210228121726-test-run--nullable-test-variation-id
24 changes: 12 additions & 12 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,33 @@ model Project {
}

model TestRun {
id String @id @default(uuid())
id String @id @default(uuid())
imageName String
diffName String?
diffPercent Float?
diffTollerancePercent Float @default(0)
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())
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("")
name String @default("")
browser String?
device String?
os String?
viewport String?
baselineName String?
comment String?
baseline Baseline?
branchName String @default("master")
branchName String @default("master")
baselineBranchName String?
ignoreAreas String @default("[]")
tempIgnoreAreas String @default("[]")
ignoreAreas String @default("[]")
tempIgnoreAreas String @default("[]")
}

model TestVariation {
Expand Down
12 changes: 4 additions & 8 deletions src/projects/projects.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,10 @@ export class ProjectsService {
},
});

try {
await Promise.all(project.builds.map((build) => this.buildsService.remove(build.id)));
await Promise.all(
project.testVariations.map((testVariation) => this.testVariationsService.delete(testVariation.id))
);
} catch (err) {
console.log(err);
}
await Promise.all(project.builds.map((build) => this.buildsService.remove(build.id)));
await Promise.all(
project.testVariations.map((testVariation) => this.testVariationsService.delete(testVariation.id))
);

return this.prismaService.project.delete({
where: { id },
Expand Down
5 changes: 5 additions & 0 deletions src/test-variations/test-variations.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const initModule = async ({
testRunCreateMock = jest.fn(),
testRunFindMany = jest.fn(),
testRunDeleteMock = jest.fn(),
$executeRawMock = jest.fn(),
}) => {
const module: TestingModule = await Test.createTestingModule({
providers: [
Expand Down Expand Up @@ -54,6 +55,7 @@ const initModule = async ({
{
provide: PrismaService,
useValue: {
$executeRaw: $executeRawMock,
testVariation: {
findUnique: variationfindUniqueMock,
findMany: variationFindManyMock,
Expand Down Expand Up @@ -500,11 +502,13 @@ describe('TestVariationsService', () => {
],
};

const $executeRawMock = jest.fn();
const variationDeleteMock = jest.fn();
const getDetailsMock = jest.fn().mockResolvedValueOnce(variation);
const deleteBaselineMock = jest.fn().mockResolvedValueOnce(variation.baselines[0]);
const service = await initModule({
variationDeleteMock,
$executeRawMock,
});
service.getDetails = getDetailsMock;
service.deleteBaseline = deleteBaselineMock;
Expand All @@ -513,6 +517,7 @@ describe('TestVariationsService', () => {

expect(service.getDetails).toHaveBeenCalledWith(testVariationId);
expect(service.deleteBaseline).toHaveBeenCalledWith(variation.baselines[0]);
expect($executeRawMock).toHaveBeenCalled();
expect(variationDeleteMock).toHaveBeenCalledWith({
where: { id: testVariationId },
});
Expand Down
9 changes: 7 additions & 2 deletions src/test-variations/test-variations.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,15 @@ export class TestVariationsService {
async delete(id: string): Promise<TestVariation> {
const testVariation = await this.getDetails(id);

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

// delete testVariation
// disconnect TestRuns
// workaround due to https://github.com/prisma/prisma/issues/2810
await this.prismaService
.$executeRaw`UPDATE "public"."TestRun" SET "testVariationId" = NULL::text WHERE "testVariationId" = ${id}`;

// delete TestVariation
return this.prismaService.testVariation.delete({
where: { id },
});
Expand Down
1 change: 1 addition & 0 deletions test/jest-e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"rootDir": "../",
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"testTimeout": 30000,
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
}
Expand Down
1 change: 0 additions & 1 deletion test/test-runs.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { ProjectsService } from '../src/projects/projects.service';
import { Project, TestStatus } from '@prisma/client';
import { BuildsService } from '../src/builds/builds.service';

jest.setTimeout(20000);
jest.useFakeTimers();

describe('TestRuns (e2e)', () => {
Expand Down
Loading