Skip to content

Commit

Permalink
feat: remove sgtu mock
Browse files Browse the repository at this point in the history
  • Loading branch information
yxuo committed Jan 18, 2024
1 parent 4eea1b8 commit 1e5edde
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 242 deletions.
2 changes: 0 additions & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { DataSource, DataSourceOptions } from 'typeorm';
import { AllConfigType } from './config/config.type';
import { InfoModule } from './info/info.module';
import { AuthLicenseeModule } from './auth-licensee/auth-licensee.module';
import { SgtuModule } from './sgtu/sgtu.module';
import { MailHistoryModule } from './mail-history/mail-history.module';
import { BanksModule } from './banks/banks.module';
import { BankStatementsModule } from './bank-statements/bank-statements.module';
Expand Down Expand Up @@ -97,7 +96,6 @@ import { BigqueryModule } from './bigquery/bigquery.module';
HomeModule,
InfoModule,
AuthLicenseeModule,
SgtuModule,
MailHistoryModule,
BanksModule,
BankStatementsModule,
Expand Down
2 changes: 0 additions & 2 deletions src/auth-licensee/auth-licensee.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Module } from '@nestjs/common';
import { AuthLicenseeController } from './auth-licensee.controller';
import { AuthLicenseeService } from './auth-licensee.service';
import { SgtuModule } from 'src/sgtu/sgtu.module';
import { UsersModule } from 'src/users/users.module';
import { AuthModule } from 'src/auth/auth.module';
import { ConfigModule, ConfigService } from '@nestjs/config';
Expand All @@ -15,7 +14,6 @@ import { IsNotExist } from 'src/utils/validators/is-not-exists.validator';
imports: [
ConfigModule,
AuthModule,
SgtuModule,
UsersModule,
MailModule,
MailHistoryModule,
Expand Down
19 changes: 0 additions & 19 deletions src/auth-licensee/auth-licensee.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { MailHistoryService } from 'src/mail-history/mail-history.service';
import { MailService } from 'src/mail/mail.service';
import { Role } from 'src/roles/entities/role.entity';
import { RoleEnum } from 'src/roles/roles.enum';
import { SgtuDto } from 'src/sgtu/dto/sgtu.dto';
import { SgtuService } from 'src/sgtu/sgtu.service';
import { User } from 'src/users/entities/user.entity';
import { UsersService } from 'src/users/users.service';
import { BaseValidator } from 'src/utils/validators/base-validator';
Expand All @@ -25,7 +23,6 @@ describe('AuthLicenseeService', () => {
let jwtService: JwtService;
let usersService: UsersService;
let mailHistoryService: MailHistoryService;
let sgtuService: SgtuService;
let baseValidator: BaseValidator;

beforeEach(async () => {
Expand Down Expand Up @@ -69,12 +66,6 @@ describe('AuthLicenseeService', () => {
sign: jest.fn(),
},
} as Provider;
const sgtuServiceMock = {
provide: SgtuService,
useValue: {
getGeneratedProfile: jest.fn(),
},
} as Provider;
const BaseValidatorMock = {
provide: BaseValidator,
useValue: {
Expand All @@ -90,15 +81,13 @@ describe('AuthLicenseeService', () => {
forgotServiceMock,
mailServiceMock,
mailHistoryServiceMock,
sgtuServiceMock,
BaseValidatorMock,
],
}).compile();

authLicenseeService = module.get<AuthLicenseeService>(AuthLicenseeService);
usersService = module.get<UsersService>(UsersService);
mailHistoryService = module.get<MailHistoryService>(MailHistoryService);
sgtuService = module.get<SgtuService>(SgtuService);
jwtService = module.get<JwtService>(JwtService);
jwtService = module.get<JwtService>(JwtService);
baseValidator = module.get<BaseValidator>(BaseValidator);
Expand Down Expand Up @@ -152,17 +141,9 @@ describe('AuthLicenseeService', () => {
inviteStatus: new InviteStatus(InviteStatusEnum.sent),
sentAt: dateNow,
} as MailHistory;
const sgtuProfile = {
cpfCnpj: 'cpf1',
permitCode: 'permitCode1',
email: user.email,
} as SgtuDto;
jest.spyOn(mailHistoryService, 'findOne').mockResolvedValue(mailHistory);
jest.spyOn(usersService, 'getOne').mockResolvedValue(user);
jest.spyOn(usersService, 'update').mockResolvedValue(user);
jest
.spyOn(sgtuService, 'getGeneratedProfile')
.mockResolvedValue(sgtuProfile);
jest
.spyOn(global.Date, 'now')
.mockImplementation(() => dateNow.valueOf());
Expand Down
70 changes: 11 additions & 59 deletions src/auth-licensee/auth-licensee.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { InviteStatusEnum } from 'src/mail-history-statuses/mail-history-status.
import { MailHistoryService } from 'src/mail-history/mail-history.service';
import { MailService } from 'src/mail/mail.service';
import { RoleEnum } from 'src/roles/roles.enum';
import { SgtuDto } from 'src/sgtu/dto/sgtu.dto';
import { SgtuService } from 'src/sgtu/sgtu.service';
import { Status } from 'src/statuses/entities/status.entity';
import { StatusEnum } from 'src/statuses/statuses.enum';
import { UsersService } from 'src/users/users.service';
Expand All @@ -28,11 +26,10 @@ export class AuthLicenseeService {
constructor(
private jwtService: JwtService,
private usersService: UsersService,
private sgtuService: SgtuService,
private mailHistoryService: MailHistoryService,
private baseValidator: BaseValidator,
private mailService: MailService,
) {}
) { }

async validateLogin(
loginDto: AuthLicenseeLoginDto,
Expand Down Expand Up @@ -131,51 +128,21 @@ export class AuthLicenseeService {

const user = await this.usersService.getOne({ id: invite.user.id });

if (user.id !== invite.user.id || typeof user.permitCode !== 'string') {
throw new HttpException(
{
error: HttpErrorMessages.UNAUTHORIZED,
details: {
user: {
...(user.id !== invite.user.id && {
id: 'invalidUserForInviteHash',
}),
...(typeof user.permitCode !== 'string' && {
permitCode: 'cantBeEmpty',
}),
},
},
},
HttpStatus.UNAUTHORIZED,
);
}

const sgtuProfile: SgtuDto = await this.sgtuService.getGeneratedProfile(
invite,
);

await this.baseValidator.validateOrReject(
sgtuProfile,
SgtuDto,
HttpStatus.UNAUTHORIZED,
HttpErrorMessages.UNAUTHORIZED,
);

if (
sgtuProfile.permitCode !== user.permitCode ||
sgtuProfile.email !== user.email
user.id !== invite.user.id
|| !user.permitCode || !user.fullName || !user.email
) {
throw new HttpException(
{
error: HttpErrorMessages.UNAUTHORIZED,
details: {
user: {
...(sgtuProfile.permitCode !== user.permitCode && {
id: 'differentPermitCodeFound',
}),
...(sgtuProfile.email !== user.email && {
permitCode: 'differentEmailFound',
...(user.id !== invite.user.id && {
id: 'invalidUserForInviteHash',
}),
...(!user.permitCode && { permitCode: 'campoNulo' }),
...(!user.fullName && { fullName: 'campoNulo' }),
...(!user.email && { email: 'campoNulo' }),
},
},
},
Expand All @@ -184,9 +151,9 @@ export class AuthLicenseeService {
}

const inviteResponse: IALInviteProfile = {
fullName: sgtuProfile.fullName,
permitCode: sgtuProfile.permitCode,
email: sgtuProfile.email,
fullName: user.fullName as string,
permitCode: user.permitCode,
email: user.email,
hash: invite.hash,
inviteStatus: invite.inviteStatus,
};
Expand Down Expand Up @@ -253,17 +220,6 @@ export class AuthLicenseeService {
);
}

const sgtuProfile: SgtuDto = await this.sgtuService.getGeneratedProfile(
invite,
);

await this.baseValidator.validateOrReject(
sgtuProfile,
SgtuDto,
HttpStatus.UNAUTHORIZED,
HttpErrorMessages.UNAUTHORIZED,
);

await this.mailHistoryService.update(
invite.id,
{
Expand All @@ -279,10 +235,6 @@ export class AuthLicenseeService {
{
password: registerDto.password,
hash: hash,
fullName: sgtuProfile.fullName,
cpfCnpj: sgtuProfile.cpfCnpj,
permitCode: sgtuProfile.permitCode,
isSgtuBlocked: sgtuProfile.isSgtuBlocked,
status: {
id: StatusEnum.active,
} as Status,
Expand Down
28 changes: 0 additions & 28 deletions src/sgtu/data/sgtu-response-mockup.ts

This file was deleted.

26 changes: 0 additions & 26 deletions src/sgtu/dto/sgtu.dto.ts

This file was deleted.

8 changes: 0 additions & 8 deletions src/sgtu/sgtu.module.ts

This file was deleted.

18 changes: 0 additions & 18 deletions src/sgtu/sgtu.service.spec.ts

This file was deleted.

75 changes: 0 additions & 75 deletions src/sgtu/sgtu.service.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/ticket-revenues/interfaces/ticket-revenue.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export interface ITicketRevenue {

/**
* **Important field**
*
*
* Represents `permissao`
*
* @description Número da permissão do operador
Expand Down
1 change: 0 additions & 1 deletion src/users/entities/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ export class User extends EntityHelper {
'permitCode',
'email',
'passValidatorId',
'isSgtuBlocked',
// editable
'phone',
'bankCode',
Expand Down
Loading

0 comments on commit 1e5edde

Please sign in to comment.