Skip to content

Commit

Permalink
test: bankAccountDigit ngth msut be = 1, no invalid ClienteFavorecido
Browse files Browse the repository at this point in the history
  • Loading branch information
yxuo committed Aug 2, 2024
1 parent 357f0f4 commit 0d18346
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cnab/cnab.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ export class CnabService {
await this.itemTransacaoService.saveMany(itemTransacaoDTOs);
}

private async updateAllFavorecidosFromUsers() {
public async updateAllFavorecidosFromUsers() {
const allUsers = await this.usersService.findManyRegisteredUsers();
await this.clienteFavorecidoService.updateAllFromUsers(allUsers);
}
Expand Down
4 changes: 4 additions & 0 deletions src/cnab/repository/cliente-favorecido.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export class ClienteFavorecidoRepository {

createQueryBuilder = this.clienteFavorecidoRepository.createQueryBuilder;

async remove(favorecidos: ClienteFavorecido[]) {
return await this.clienteFavorecidoRepository.remove(favorecidos);
}

async save(dto: SaveClienteFavorecidoDTO): Promise<void> {
if (dto.id === undefined) {
await this.create(dto);
Expand Down
66 changes: 66 additions & 0 deletions test/user/users.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { HttpStatus } from '@nestjs/common';
import * as fs from 'fs';
import * as path from 'path';
import { User } from 'src/users/entities/user.entity';
import * as request from 'supertest';
import {
APP_URL,
LICENSEE_CPF_PASSWORD,
LICENSEE_CPF_PERMIT_CODE
} from '../utils/constants';

describe('Users managing itself (e2e)', () => {
const app = APP_URL;
const tempFolder = path.join(__dirname, 'temp');
let apiToken: any = {};
let user: User = new User();

beforeAll(async () => {
await request(app)
.post('/api/v1/auth/licensee/login')
.send({
permitCode: LICENSEE_CPF_PERMIT_CODE,
password: LICENSEE_CPF_PASSWORD,
})
.then(({ body }) => {
apiToken = body.token;
user = new User(body.user);
});

if (!fs.existsSync(tempFolder)) {
fs.mkdirSync(tempFolder);
}
});

describe('Setup tests', () => {
it('should have UTC and local timezones', () => {
new Date().getTimezoneOffset();
expect(process.env.TZ).toEqual('UTC');
expect(global.__localTzOffset).toBeDefined();
});
});

describe('Manage users', () => {
test('Should block User account digit length > 1', /**
* Requirement reviewed: 2024/08/02 {@link https://github.com/RJ-SMTR/api-cct/issues/366 #366 - GitHub}
*/ async () => {
// Assert
await request(app)
.patch(`/api/v1/users/${user.id}`)
.auth(apiToken, { type: 'bearer' })
.send({ bankAccountDigit: '12' })
.expect(HttpStatus.UNPROCESSABLE_ENTITY);
}, 20000);

test('Should allow User account digit = 1', /**
* Requirement reviewed: 2024/08/02 {@link https://github.com/RJ-SMTR/api-cct/issues/366 #366 - GitHub}
*/ async () => {
// Assert
await request(app)
.patch(`/api/v1/users/${user.id}`)
.auth(apiToken, { type: 'bearer' })
.send({ bankAccountDigit: '3' })
.expect(HttpStatus.OK);
}, 20000);
});
});

0 comments on commit 0d18346

Please sign in to comment.