Skip to content

Commit 531a2c1

Browse files
authored
Fix: cannot add/update ignore areas (#248)
* Fix: cannot add/update ignore areas closes Visual-Regression-Tracker/Visual-Regression-Tracker#419
1 parent 981c868 commit 531a2c1

8 files changed

+76
-21
lines changed

src/http-exception.filter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class HttpExceptionFilter implements ExceptionFilter {
2121
? this.getCustomMessageForException(exception)
2222
: exception.message;
2323

24-
Logger.error(exception, exception.stack);
24+
Logger.error(exception, exception.stack, exception.getResponse?.());
2525

2626
response.status(status).json({
2727
path: request.url,

src/test-runs/dto/update-ignore-area.dto.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { ApiProperty } from '@nestjs/swagger';
22
import { IgnoreAreaDto } from './ignore-area.dto';
33
import { Type } from 'class-transformer';
4-
import { ValidateNested } from 'class-validator';
4+
import { ValidateNested, IsString } from 'class-validator';
55

66
export class UpdateIgnoreAreasDto {
77
@ApiProperty({type: String, isArray: true })
8-
@Type(() => String)
9-
@ValidateNested({ each: true })
8+
@IsString({each: true})
109
readonly ids: string[];
1110

1211
@ApiProperty({ type: IgnoreAreaDto, isArray: true })

test/builds.e2e-spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Test, TestingModule } from '@nestjs/testing';
2-
import { INestApplication } from '@nestjs/common';
2+
import { INestApplication, ValidationPipe } from '@nestjs/common';
33
import { AppModule } from '../src/app.module';
44
import { UsersService } from '../src/users/users.service';
55
import { haveTestRunCreated, haveUserLogged, requestWithApiKey, requestWithAuth } from './preconditions';
@@ -29,6 +29,7 @@ describe('Builds (e2e)', () => {
2929
}).compile();
3030

3131
app = moduleFixture.createNestApplication();
32+
app.useGlobalPipes(new ValidationPipe());
3233
buildsService = moduleFixture.get<BuildsService>(BuildsService);
3334
buildsController = moduleFixture.get<BuildsController>(BuildsController);
3435
usersService = moduleFixture.get<UsersService>(UsersService);

test/preconditions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Build } from '@prisma/client';
1010
import { CreateUserDto } from 'src/users/dto/user-create.dto';
1111

1212
export const generateUser = (password: string): CreateUserDto => ({
13-
email: `${uuidAPIKey.create().uuid}@example.com`,
13+
email: `email+${uuidAPIKey.create().apiKey.toLocaleLowerCase()}@example.com`,
1414
password,
1515
firstName: 'fName',
1616
lastName: 'lName',

test/projects.e2e-spec.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
import { Test, TestingModule } from '@nestjs/testing';
2-
import { INestApplication } from '@nestjs/common';
2+
import { INestApplication, ValidationPipe } from '@nestjs/common';
33
import { AppModule } from '../src/app.module';
44
import { UsersService } from '../src/users/users.service';
55
import { requestWithAuth, haveUserLogged } from './preconditions';
66
import { ProjectsService } from '../src/projects/projects.service';
77
import uuidAPIKey from 'uuid-apikey';
88
import { UserLoginResponseDto } from 'src/users/dto/user-login-response.dto';
9+
import { ProjectDto } from 'src/projects/dto/project.dto';
910

10-
const project = {
11+
const project: ProjectDto = {
1112
id: uuidAPIKey.create().uuid,
1213
name: 'Test project',
14+
buildsCounter: 0,
15+
mainBranchName: 'master',
16+
createdAt: new Date(),
17+
updatedAt: new Date(),
18+
autoApproveFeature: true,
19+
imageComparison: 'pixelmatch',
20+
maxBuildAllowed: 0,
21+
maxBranchLifetime: 0,
22+
imageComparisonConfig: '{}'
1323
};
1424

1525
const projectServiceMock = {
@@ -33,6 +43,7 @@ describe('Projects (e2e)', () => {
3343
.compile();
3444

3545
app = moduleFixture.createNestApplication();
46+
app.useGlobalPipes(new ValidationPipe());
3647
usersService = moduleFixture.get<UsersService>(UsersService);
3748

3849
await app.init();
@@ -81,7 +92,11 @@ describe('Projects (e2e)', () => {
8192
it('can delete', async () => {
8293
const res = await requestWithAuth(app, 'delete', `/projects/${project.id}`, loggedUser.token).send().expect(200);
8394

84-
expect(res.body).toStrictEqual(projectServiceMock.remove());
95+
expect(res.body).toStrictEqual({
96+
...projectServiceMock.remove(),
97+
createdAt: expect.any(String),
98+
updatedAt: expect.any(String),
99+
});
85100
});
86101

87102
it('not valid UUID', async () => {
@@ -97,7 +112,11 @@ describe('Projects (e2e)', () => {
97112
it('can edit', async () => {
98113
const res = await requestWithAuth(app, 'put', `/projects`, loggedUser.token).send(project).expect(200);
99114

100-
expect(res.body).toStrictEqual(projectServiceMock.update());
115+
expect(res.body).toStrictEqual({
116+
...projectServiceMock.update(),
117+
createdAt: expect.any(String),
118+
updatedAt: expect.any(String),
119+
});
101120
});
102121

103122
it('not valid token', async () => {

test/test-runs.e2e-spec.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Test, TestingModule } from '@nestjs/testing';
2-
import { INestApplication } from '@nestjs/common';
2+
import { INestApplication, ValidationPipe } from '@nestjs/common';
33
import { AppModule } from '../src/app.module';
44
import { UsersService } from '../src/users/users.service';
55
import { haveTestRunCreated, haveUserLogged, requestWithApiKey, requestWithAuth } from './preconditions';
@@ -11,6 +11,7 @@ import { BuildsService } from '../src/builds/builds.service';
1111
import { TestVariationsService } from '../src/test-variations/test-variations.service';
1212
import { TEST_PROJECT } from '../src/_data_';
1313
import uuidAPIKey from 'uuid-apikey';
14+
import { UpdateIgnoreAreasDto } from 'src/test-runs/dto/update-ignore-area.dto';
1415

1516
describe('TestRuns (e2e)', () => {
1617
let app: INestApplication;
@@ -32,6 +33,7 @@ describe('TestRuns (e2e)', () => {
3233
}).compile();
3334

3435
app = moduleFixture.createNestApplication();
36+
app.useGlobalPipes(new ValidationPipe());
3537
testRunsService = moduleFixture.get<TestRunsService>(TestRunsService);
3638
usersService = moduleFixture.get<UsersService>(UsersService);
3739
projecstService = moduleFixture.get<ProjectsService>(ProjectsService);
@@ -444,4 +446,42 @@ describe('TestRuns (e2e)', () => {
444446
await requestWithAuth(app, 'post', `/test-runs/reject`, user.token).send([testRun1.id, testRun2.id]).expect(201);
445447
});
446448
});
449+
450+
describe('POST /ignoreAreas/update', () => {
451+
it('200', async () => {
452+
const { testRun } = await haveTestRunCreated(buildsService, testRunsService, project.id, 'develop', image_v1);
453+
454+
const request: UpdateIgnoreAreasDto = {
455+
ids: [testRun.id],
456+
ignoreAreas: [
457+
{
458+
x: 182,
459+
y: 28,
460+
width: 38,
461+
height: 30,
462+
},
463+
],
464+
};
465+
await requestWithAuth(app, 'post', `/test-runs/ignoreAreas/update`, user.token).send(request).expect(201);
466+
});
467+
});
468+
469+
describe('POST /ignoreAreas/add', () => {
470+
it('200', async () => {
471+
const { testRun } = await haveTestRunCreated(buildsService, testRunsService, project.id, 'develop', image_v1);
472+
473+
const request: UpdateIgnoreAreasDto = {
474+
ids: [testRun.id],
475+
ignoreAreas: [
476+
{
477+
x: 182,
478+
y: 28,
479+
width: 38,
480+
height: 30,
481+
},
482+
],
483+
};
484+
await requestWithAuth(app, 'post', `/test-runs/ignoreAreas/add`, user.token).send(request).expect(201);
485+
});
486+
});
447487
});

test/test-variations.e2e-spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Test, TestingModule } from '@nestjs/testing';
2-
import { INestApplication } from '@nestjs/common';
2+
import { INestApplication, ValidationPipe } from '@nestjs/common';
33
import { AppModule } from '../src/app.module';
44
import { UsersService } from '../src/users/users.service';
55
import { haveTestRunCreated, haveUserLogged } from './preconditions';
@@ -28,6 +28,7 @@ describe('TestVariations (e2e)', () => {
2828
}).compile();
2929

3030
app = moduleFixture.createNestApplication();
31+
app.useGlobalPipes(new ValidationPipe());
3132
testRunsService = moduleFixture.get<TestRunsService>(TestRunsService);
3233
usersService = moduleFixture.get<UsersService>(UsersService);
3334
projecstService = moduleFixture.get<ProjectsService>(ProjectsService);

test/users.e2e-spec.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { Test, TestingModule } from '@nestjs/testing';
2-
import { INestApplication } from '@nestjs/common';
2+
import { INestApplication, ValidationPipe } from '@nestjs/common';
33
import request from 'supertest';
44
import { AppModule } from '../src/app.module';
5-
import uuidAPIKey from 'uuid-apikey';
65
import { UsersService } from '../src/users/users.service';
76
import { UserLoginRequestDto } from '../src/users/dto/user-login-request.dto';
87
import { compareSync } from 'bcryptjs';
@@ -20,6 +19,7 @@ describe('Users (e2e)', () => {
2019
}).compile();
2120

2221
app = moduleFixture.createNestApplication();
22+
app.useGlobalPipes(new ValidationPipe());
2323
usersService = moduleFixture.get<UsersService>(UsersService);
2424
await app.init();
2525
});
@@ -33,12 +33,7 @@ describe('Users (e2e)', () => {
3333
});
3434

3535
it('POST /register', () => {
36-
user = {
37-
email: `${uuidAPIKey.create().uuid}@example.com'`,
38-
password: '123456',
39-
firstName: 'fName',
40-
lastName: 'lName',
41-
};
36+
user = generateUser("123456");
4237
return request(app.getHttpServer())
4338
.post('/users/register')
4439
.send(user)
@@ -108,7 +103,7 @@ describe('Users (e2e)', () => {
108103
const password = '123456';
109104
user = await usersService.create(generateUser(password));
110105
const editedUser = {
111-
email: `${uuidAPIKey.create().uuid}@example.com'`,
106+
email: 'edited' + user.email,
112107
firstName: 'EDITEDfName',
113108
lastName: 'EDITEDlName',
114109
};

0 commit comments

Comments
 (0)