Skip to content

Commit

Permalink
Merge branch 'develop' into feature/#116-CRUD-metricas
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-cella authored Dec 10, 2023
2 parents 58f9eab + 8f2e68f commit 5af26ca
Show file tree
Hide file tree
Showing 15 changed files with 1,375 additions and 1,120 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Deploy

on:
push:
branches: ['main']
branches: ['develop']
tags: ['v*.*.*']

env:
Expand Down
9 changes: 9 additions & 0 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ FROM node:18.17.0-alpine

ENV NODE_ENV=production

ARG TZ='America/Sao_Paulo'

ENV TZ ${TZ}

RUN apk upgrade --update
RUN apk add --no-cache tzdata openssl
RUN cp /usr/share/zoneinfo/${TZ} /etc/localtime
RUN echo "${TZ}" > /etc/timezone

WORKDIR /app

COPY --chown=node:node --from=BUILD_IMAGE /home/node/app/dist /app
Expand Down
2,075 changes: 960 additions & 1,115 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"dependencies": {
"@grpc/grpc-js": "1.7.3",
"@grpc/proto-loader": "0.7.3",
"@nestjs/axios": "0.1.0",
"@nestjs/axios": "^0.1.0",
"@nestjs/common": "9.1.2",
"@nestjs/config": "2.2.0",
"@nestjs/core": "9.1.2",
Expand All @@ -43,9 +43,11 @@
"@nestjs/microservices": "9.1.2",
"@nestjs/passport": "9.0.3",
"@nestjs/platform-express": "9.1.2",
"@nestjs/schedule": "^4.0.0",
"@nestjs/typeorm": "9.0.1",
"amqp-connection-manager": "4.1.3",
"amqplib": "0.10.0",
"axios": "^1.6.2",
"bcrypt": "5.0.1",
"cache-manager": "3.4.3",
"cache-manager-redis-store": "2.0.0",
Expand Down
149 changes: 149 additions & 0 deletions reports/sonar-report.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<testExecutions version="1">
<file path="src/rotina/rotina.service.spec.ts">
<testCase name="RotinaService should be defined" duration="91" />
<testCase name="RotinaService should create Rotina" duration="40" />
<testCase name="RotinaService should find Rotina" duration="35" />
<testCase name="RotinaService should remove Rotina" duration="31" />
<testCase name="RotinaService should update Rotina" duration="47" />
<testCase name="RotinaService findAll should findAll Rotina" duration="48" />
<testCase name="RotinaService findAll should findAllToCron Rotina" duration="45" />
</file>
<file path="src/cron/cron.service.spec.ts">
<testCase name="CronService should be defined" duration="781" />
<testCase name="CronService should call rotina service" duration="334" />
</file>
<file path="src/rotina/rotina.controller.spec.ts">
<testCase name="RotinaController should be defined" duration="79" />
<testCase name="RotinaController should create Idoso" duration="39" />
<testCase name="RotinaController should find Idoso" duration="27" />
<testCase name="RotinaController should remove Idoso" duration="20" />
<testCase name="RotinaController should update Idoso" duration="24" />
<testCase name="RotinaController findAll should findAll Rotina" duration="22" />
</file>
<file path="src/idoso/idoso.controller.spec.ts">
<testCase name="IdosoController should be defined" duration="74" />
<testCase name="IdosoController should create Idoso" duration="35" />
<testCase name="IdosoController should find Idoso" duration="27" />
<testCase name="IdosoController should remove Idoso" duration="28" />
<testCase name="IdosoController should update Idoso" duration="40" />
<testCase name="IdosoController findAll should findAll Idoso" duration="47" />
</file>
<file path="src/idoso/idoso.service.spec.ts">
<testCase name="IdosoService should be defined" duration="83" />
<testCase name="IdosoService should create Idoso" duration="188" />
<testCase name="IdosoService should find Idoso" duration="61" />
<testCase name="IdosoService should remove Idoso" duration="28" />
<testCase name="IdosoService should update Idoso" duration="28" />
<testCase name="IdosoService should update Idoso with photo" duration="27" />
<testCase name="IdosoService findAll should findAll Idoso" duration="56" />
</file>
<file path="src/config/db/db.service.spec.ts">
<testCase name="DbService should be defined" duration="74" />
<testCase name="DbService should return db config development" duration="49" />
<testCase name="DbService should return db config production" duration="38" />
</file>
<file path="src/autenticacao.guard.spec.ts">
<testCase name="AutenticacaoGuard should be defined" duration="86" />
<testCase name="AutenticacaoGuard should pass if route is public" duration="33" />
<testCase name="AutenticacaoGuard should pass if authentication is successful" duration="40" />
<testCase name="AutenticacaoGuard should not pass if authentication is unsuccessful" duration="34" />
</file>
<file path="src/shared/validators/id.validator.spec.ts">
<testCase name="HttpResponse should be defined" duration="10" />
</file>
<file path="src/shared/decorators/paginate.decorator.spec.ts">
<testCase name="Pagination should be defined" duration="10" />
<testCase name="Pagination should be Paginate" duration="10" />
<testCase name="Pagination should be Paginate not limit" duration="2" />
<testCase name="Pagination should be Paginate not offset" duration="3" />
</file>
<file path="src/shared/decorators/ordenate.decorator.spec.ts">
<testCase name="Pagination should be defined" duration="10" />
<testCase name="Pagination should be Paginate" duration="8" />
<testCase name="Pagination should be Paginate not limit" duration="6" />
<testCase name="Pagination should be Paginate not offset" duration="3" />
<testCase name="Ordenate should return default object if there is no JSON" duration="4" />
<testCase name="Ordenate should return OrderParams object with values for order" duration="3" />
<testCase name="Ordenate should return default values when obj has empty props" duration="2" />
<testCase name="Ordenate should be Ordenate using factory" duration="2" />
</file>
<file path="src/shared/decorators/public-route.spec.ts">
<testCase name="Pagination should be defined" duration="10" />
</file>
<file path="src/shared/decorators/filtrate-string.spec.ts">
<testCase name="Pagination should be defined" duration="14" />
<testCase name="Pagination should be Paginate" duration="9" />
<testCase name="Pagination should be Paginate not limit" duration="6" />
<testCase name="Pagination should be Paginate not offset" duration="3" />
<testCase name="FiltrateString should return empty object for filter" duration="5" />
<testCase name="FiltrateString should return TestFilterProps object with values for filter" duration="2" />
<testCase name="FiltrateString should be FiltrateString using factory" duration="3" />
</file>
<file path="src/shared/interceptors/data-transform.interceptor.spec.ts">
<testCase name="DataTransformInterceptor should be defined" duration="10" />
<testCase name="DataTransformInterceptor should be intercept t1" duration="16" />
<testCase name="DataTransformInterceptor should be intercept should formatData with message" duration="2" />
<testCase name="DataTransformInterceptor should be intercept should formatData with no message" duration="2" />
<testCase name="DataTransformInterceptor should be intercept should formatData with Paginate" duration="3" />
</file>
<file path="src/shared/decorators/filtrate.decorator.spec.ts">
<testCase name="Pagination should be defined" duration="11" />
<testCase name="Pagination should be Paginate" duration="7" />
<testCase name="Pagination should be Paginate not limit" duration="5" />
<testCase name="Pagination should be Paginate not offset" duration="2" />
<testCase name="Filtrate should return empty object for filter" duration="4" />
<testCase name="Filtrate should return TestFilterProps object with values for filter" duration="2" />
<testCase name="Filtrate should be Filtrate using factory" duration="2" />
</file>
<file path="src/shared/filters/all-exceptions.filter.spec.ts">
<testCase name="AllExceptionsFilter should be defined" duration="10" />
<testCase name="AllExceptionsFilter should be catch" duration="8" />
<testCase name="AllExceptionsFilter should be not exception to class-validator" duration="3" />
<testCase name="AllExceptionsFilter should be not exception only message" duration="3" />
</file>
<file path="src/shared/filters/model-not-found.exception-filter.spec.ts">
<testCase name="ModelNotFoundExceptionFilter should be defined" duration="10" />
<testCase name="ModelNotFoundExceptionFilter should be catch" duration="8" />
</file>
<file path="src/shared/classes/http-response.spec.ts">
<testCase name="HttpResponse should be defined" duration="8" />
<testCase name="HttpResponse should create message with payload text" duration="6" />
<testCase name="HttpResponse should create message with success text" duration="2" />
<testCase name="HttpResponse should create message with updated text" duration="2" />
<testCase name="HttpResponse should create message with deleted text" duration="2" />
</file>
<file path="src/shared/helpers/string-helpers.spec.ts">
<testCase name="String Helpers should be regex" duration="9" />
</file>
<file path="src/shared/helpers/sql-query-helper.spec.ts">
<testCase name="Where Clause STRING should return empty string if value is undefined" duration="9" />
<testCase name="Where Clause STRING should return empty string if value has no length" duration="2" />
<testCase name="Where Clause STRING should return where string based on given value and tableColumn" duration="1" />
<testCase name="Where Clause NUMBER should return empty string if value is undefined" duration="1" />
<testCase name="Where Clause NUMBER should return where string based on given value and tableColumn" duration="3" />
<testCase name="Where Clause BOOLEAN should return empty string if value is undefined" duration="1" />
<testCase name="Where Clause BOOLEAN should return empty string if value is higher than 1" duration="1" />
<testCase name="Where Clause BOOLEAN should return where string based on given value and tableColumn" duration="1" />
<testCase name="Where Clause ARRAY NUMBER should return empty string if value is undefined" duration="3" />
<testCase name="Where Clause ARRAY NUMBER should return where string if value is number" duration="3" />
<testCase name="Where Clause ARRAY NUMBER should return where string if value is number array" duration="3" />
</file>
<file path="src/shared/helpers/buffer-to-image.spec.ts">
<testCase name="Buffer to image bufferToBase64 should be bufferToBase64 a image" duration="14" />
<testCase name="Buffer to image bufferToBase64 should getImageUri" duration="3" />
<testCase name="Buffer to image bufferToBase64 should be bufferToBase64 a empty if null" duration="3" />
<testCase name="Buffer to image bufferToBase64 should be bufferToBase64 a empty if not image" duration="3" />
<testCase name="Buffer to image isBase64 should be false" duration="3" />
<testCase name="Buffer to image isBase64 should be true" duration="4" />
<testCase name="Buffer to image isBase64Image should be false" duration="2" />
<testCase name="Buffer to image isBase64Image should be true" duration="3" />
</file>
<file path="src/shared/helpers/commons.spec.ts">
<testCase name="Helper deve criar um hash com tamanho default" duration="13" />
<testCase name="Helper should be return if its nill for undefined" duration="4" />
<testCase name="Helper should be return if its nill for null" duration="1" />
<testCase name="Helper should be isJsonObject to be true" duration="3" />
<testCase name="Helper should be isJsonObject to be false" duration="2" />
<testCase name="Helper should be isJsonObject to be false in not parse" duration="1" />
</file>
</testExecutions>
4 changes: 4 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { APP_GUARD } from '@nestjs/core';
import { ClientsModule, Transport } from '@nestjs/microservices';
import { ScheduleModule } from '@nestjs/schedule';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AutenticacaoGuard } from './autenticacao.guard';
import { DbModule } from './config/db/db.module';
import { DbService } from './config/db/db.service';
import { CronModule } from './cron/cron.module';
import { IdosoModule } from './idoso/idoso.module';
import { RotinaModule } from './rotina/rotina.module';
import { MetricaModule } from './metrica/metrica.module';
Expand All @@ -15,6 +17,7 @@ const ENV = process.env.NODE_ENV;

@Module({
imports: [
ScheduleModule.forRoot(),
ConfigModule.forRoot({
isGlobal: true,
envFilePath: !ENV ? '.env' : `.env.${ENV}`,
Expand Down Expand Up @@ -42,6 +45,7 @@ const ENV = process.env.NODE_ENV;
RotinaModule,
MetricaModule,
ValorMetricaModule
CronModule,
],
controllers: [],
providers: [
Expand Down
13 changes: 13 additions & 0 deletions src/cron/cron.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { HttpModule } from '@nestjs/axios';
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Rotina } from '../rotina/entities/rotina.entity';
import { RotinaService } from '../rotina/rotina.service';
import { CronService } from './cron.service';

@Module({
imports: [TypeOrmModule.forFeature([Rotina]), HttpModule],
providers: [CronService, RotinaService, Repository],
})
export class CronModule {}
94 changes: 94 additions & 0 deletions src/cron/cron.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { HttpModule, HttpService } from '@nestjs/axios';
import { SchedulerRegistry } from '@nestjs/schedule';
import { Test, TestingModule } from '@nestjs/testing';
import { getRepositoryToken } from '@nestjs/typeorm';
import { of } from 'rxjs';
import { ECategoriaRotina } from '../rotina/classes/categoria-rotina.enum';
import { Rotina } from '../rotina/entities/rotina.entity';
import { RotinaService } from '../rotina/rotina.service';
import { AppModule } from './../app.module';
import { CronService } from './cron.service';

jest.mock('cron', () => {
const mScheduleJob = { start: jest.fn(), stop: jest.fn() };
const mCronJob = jest.fn(() => mScheduleJob);
return { CronJob: mCronJob };
});

describe('CronService', () => {
let service: CronService;
let rotinaService: RotinaService;
let schedulerRegistry: SchedulerRegistry;
let httpService: HttpService;

const rotina = {
idIdoso: 1,
titulo: 'titulo',
categoria: ECategoriaRotina.ALIMENTACAO,
descricao: 'desc',
dataHora: new Date().toISOString() as any,
dataHoraConcluidos: [],
dias: [0, 1],
token: '',
notificacao: false,
id: 1,
};

const mockRepository = {
createQueryBuilder: jest.fn(() => ({
where: jest.fn().mockReturnThis(),
getMany: jest.fn(),
})),
};

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [AppModule, HttpModule],
providers: [
{
provide: RotinaService,
useValue: {
findAllToCron() {
return of([rotina]);
},
},
},
{
provide: getRepositoryToken(Rotina),
useValue: mockRepository,
},
CronService,
],
}).compile();

service = module.get<CronService>(CronService);
rotinaService = module.get<RotinaService>(RotinaService);
httpService = module.get<HttpService>(HttpService);
schedulerRegistry = module.get<SchedulerRegistry>(SchedulerRegistry);
});

afterEach(() => {
jest.clearAllMocks();
});

it('should be defined', () => {
expect(service).toBeDefined();
});

it('should call rotina service', async () => {
service.onModuleInit();

const spy = jest
.spyOn(rotinaService, 'findAllToCron')
.mockReturnValue(Promise.resolve([rotina]));

const spyHttp = jest
.spyOn(httpService, 'post')
.mockReturnValue(of(true as any));

await service.cronRotinas();
expect(spy).toHaveBeenCalledTimes(1);
expect(spyHttp).toHaveBeenCalledTimes(1);
schedulerRegistry.deleteCronJob('cronRotinas');
});
});
Loading

0 comments on commit 5af26ca

Please sign in to comment.