Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/change structure #64

Merged
merged 2 commits into from
Nov 5, 2024
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
Empty file removed src/domain/index.ts
Empty file.
File renamed without changes.
File renamed without changes.
2 changes: 0 additions & 2 deletions src/domain/services/ai.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { ListMoviesEntity, MovieEntity } from "../entities";

export interface AiService {
generateResponse: (prompt: AiService.Params) => Promise<AiService.Model>;
}
Expand Down
2 changes: 1 addition & 1 deletion src/infrastructure/ai/chatGPTAiClient.infra.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AiClient, AiPrompt, AiResponse } from "@/data/protocols/ai";
import { AiClient, AiPrompt, AiResponse } from "@/domain/protocols/ai";
import { chunkProcessor, G4F } from "g4f";

export class ChatGPTAiClient implements AiClient {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/infrastructure/http/axiosHttpClient.infra.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HttpRequest, HttpResponse, HttpClient } from "@/data/protocols/http";
import { HttpRequest, HttpResponse, HttpClient } from "@/domain/protocols/http";

import axios, { AxiosResponse } from "axios";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ListMoviesEntity, MovieEntity } from "@/domain/entities";
import { MoviesRepository } from "@/domain/repositories";
import { HttpClient, HttpStatusCode } from "../protocols/http";
import { HttpClient, HttpStatusCode } from "../../domain/protocols/http";
import { Environment } from "@/main/config";
import {
AccessDeniedError,
NotFoundError,
UnexpectedError,
} from "@/domain/errors";
import { movieFromJson, moviesFromJsonList } from "@/helpers";
import { movieFromJson, moviesFromJsonList } from "@/infrastructure/helpers";

export class MoviesRepositoryImpl implements MoviesRepository {
constructor(private readonly httpClient: HttpClient) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
NotFoundError,
UnexpectedError,
} from "@/domain/errors";
import { HttpClient, HttpStatusCode } from "../protocols/http";
import { HttpClient, HttpStatusCode } from "../../domain/protocols/http";
import { AiService } from "./../../domain/services/ai.service";

export class AiServiceImpl implements AiService {
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/main/factories/repositories/movies.factory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MoviesRepositoryImpl } from "@/data/repositories";
import { MoviesRepositoryImpl } from "@/infrastructure/repositories";
import { MoviesRepository } from "@/domain/repositories";
import { makeAxiosHttpClient } from "../http/axiosHttpClient.factory";

Expand Down
2 changes: 1 addition & 1 deletion src/main/factories/services/ai.factory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AiServiceImpl } from "@/data/services";
import { AiService } from "@/domain/services";
import { makeAxiosHttpClient } from "../http/axiosHttpClient.factory";
import { Environment } from "@/main/config";
import { AiServiceImpl } from "@/infrastructure/services";

export const makeAiService = (): AiService =>
new AiServiceImpl(makeAxiosHttpClient(), Environment.baseUrlAi);
2 changes: 1 addition & 1 deletion src/main/factories/usecases/getMovie.factory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GetMovieUsecase } from "@/domain/usecases";
import { GetMovieUsecaseImpl } from "@/usecases";
import { makeMoviesRepository } from "../repositories/movies.factory";
import { GetMovieUsecaseImpl } from "@/infrastructure/usecases";

export const makeGetMovieUsecase = (): GetMovieUsecase =>
new GetMovieUsecaseImpl(makeMoviesRepository());
2 changes: 1 addition & 1 deletion src/main/factories/usecases/getMovieSuggestion.factory.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { GetMovieSuggestionUsecase } from "@/domain/usecases";

import { makeMoviesRepository } from "../repositories/movies.factory";
import { GetMovieSuggestionUsecaseImpl } from "@/usecases/getMovieSuggestion.usecase";
import { makeAiService } from "../services/ai.factory";
import { GetMovieSuggestionUsecaseImpl } from "@/infrastructure/usecases/getMovieSuggestion.usecase";

export const makeGetMovieSuggestionUsecase = (): GetMovieSuggestionUsecase =>
new GetMovieSuggestionUsecaseImpl(makeMoviesRepository(), makeAiService());
2 changes: 1 addition & 1 deletion src/main/factories/usecases/getMovies.factory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GetMoviesUsecase } from "@/domain/usecases";
import { GetMoviesUsecaseImpl } from "@/usecases";
import { makeMoviesRepository } from "../repositories/movies.factory";
import { GetMoviesUsecaseImpl } from "@/infrastructure/usecases";

export const makeGetMoviesUsecase = (): GetMoviesUsecase =>
new GetMoviesUsecaseImpl(makeMoviesRepository());
1 change: 0 additions & 1 deletion src/pages/api/chat.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ChatGPTAiClient } from "@/infrastructure/ai/chatGPTAiClient.infra";
import { makeChatGptAiClient } from "@/main/factories/ai/chatGPTAiClient.factory";
import { NextApiRequest, NextApiResponse } from "next";

Expand Down
3 changes: 0 additions & 3 deletions tests/data/mocks/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion tests/domain/mocks/index.ts

This file was deleted.

3 changes: 1 addition & 2 deletions tests/infrastructure/http/axiosHttpClient.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { AxiosHttpClient } from "@/infrastructure/http";
import { mockAxios, mockHttpResponse } from "../mocks";
import { mockHttpRequest } from "../../data/mocks";
import { mockAxios, mockHttpRequest, mockHttpResponse } from "../mocks";

import axios from "axios";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
HttpResponse,
HttpStatusCode,
HttpClient,
} from "@/data/protocols/http";
} from "@/domain/protocols/http";

import { faker } from "@faker-js/faker";

Expand Down
4 changes: 4 additions & 0 deletions tests/infrastructure/mocks/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export * from "./axios.mock";
export * from "./http.mock";
export * from "./moviesRepositoryImpl.mock";
export * from "./aiServiceImpl.mock";
export * from "./movie.mock";
Comment on lines 1 to +5
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Existem mocks não exportados no arquivo index

Foram identificados os seguintes arquivos mock que não estão sendo exportados no index.ts:

  • getMovieSuggestionUsecaseImpl.mock.ts
  • getMovieUsecaseImpl.mock.ts
  • searchContent.mock.ts (este está em outro diretório, então pode ser intencional)

Recomendo adicionar as exportações dos mocks de usecase que estão no mesmo diretório:

export * from "./getMovieSuggestionUsecaseImpl.mock";
export * from "./getMovieUsecaseImpl.mock";
🔗 Analysis chain

Verificar se todos os mocks necessários estão incluídos

A centralização dos mocks em um único arquivo index é uma boa prática. No entanto, é importante garantir que todos os mocks necessários para os testes estejam presentes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Descrição: Verificar se existem outros arquivos mock que deveriam ser exportados

# Procurar por arquivos .mock.ts que podem estar faltando no index
fd -e ts -e tsx --full-path '.*\.mock\.(ts|tsx)$' | grep -v "$(rg -l 'export \* from' tests/infrastructure/mocks/index.ts | xargs -I {} dirname {})"

Length of output: 292


Script:

#!/bin/bash
# Buscar todos os arquivos .mock.ts no diretório de testes
fd -e ts -e tsx '.*\.mock\.(ts|tsx)$' tests/

# Listar os imports dos arquivos de teste para identificar possíveis mocks utilizados
rg -g '*.test.ts' -g '*.spec.ts' 'import.*from.*\.mock' tests/

Length of output: 786

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { MoviesRepositoryImpl } from "@/data/repositories/moviesImpl.repository";
import { MoviesRepositoryImpl } from "@/infrastructure/repositories/moviesImpl.repository";
import {
HttpClientSpy,
mockGetMovieRepositoryImpl,
mockGetMoviesRepositoryImpl,
} from "../mocks";
import { HttpStatusCode } from "@/data/protocols/http";
import { HttpStatusCode } from "@/domain/protocols/http";
import { Environment } from "@/main/config";
import {
AccessDeniedError,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { AiServiceImpl } from "@/data/services";
import { HttpClientSpy, mockGenerateResponse } from "../mocks";
import { Environment } from "@/main/config";
import { HttpStatusCode } from "@/data/protocols/http";
import { HttpStatusCode } from "@/domain/protocols/http";
import {
BadRequestError,
NotFoundError,
UnexpectedError,
} from "@/domain/errors";
import { AiServiceImpl } from "@/infrastructure/services";

type SutTypes = {
sut: AiServiceImpl;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { MoviesRepositoryImpl } from "@/data/repositories";
import { AiServiceImpl } from "@/data/services";
import { GetMovieSuggestionUsecaseImpl } from "@/usecases/getMovieSuggestion.usecase";
import { MoviesRepositoryImpl } from "@/infrastructure/repositories";

import { mock } from "jest-mock-extended";
import {
listMoviesMock,
mockGenerateResponse,
movieMock,
} from "./mocks/getMovieSuggestionUsecaseImpl.mock";
} from "../mocks/getMovieSuggestionUsecaseImpl.mock";
import { ListMoviesEntity } from "@/domain/entities";
import { UnexpectedError } from "@/domain/errors";
import { AiServiceImpl } from "@/infrastructure/services";
import { GetMovieSuggestionUsecaseImpl } from "@/infrastructure/usecases/getMovieSuggestion.usecase";

type SutTypes = {
repository: ReturnType<typeof mock<MoviesRepositoryImpl>>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { MoviesRepositoryImpl } from "@/data/repositories";
import { GetMovieUsecaseImpl } from "@/usecases";
import { MoviesRepositoryImpl } from "@/infrastructure/repositories";

import { mock } from "jest-mock-extended";
import { movieMock } from "./mocks/getMovieUsecaseImpl.mock";
import { movieMock } from "../mocks/getMovieUsecaseImpl.mock";
import { GetMovieUsecaseImpl } from "@/infrastructure/usecases";

type SutTypes = {
movieRepository: ReturnType<typeof mock<MoviesRepositoryImpl>>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { MoviesRepositoryImpl } from "@/data/repositories";
import { GetMoviesUsecaseImpl } from "@/usecases";
import { MoviesRepositoryImpl } from "@/infrastructure/repositories";

import { mock } from "jest-mock-extended";
import { listMoviesMock, movieMock } from "./mocks/getMovieUsecaseImpl.mock";
import { listMoviesMock, movieMock } from "../mocks/getMovieUsecaseImpl.mock";
import { GetMoviesUsecaseImpl } from "@/infrastructure/usecases";

type SutTypes = {
movieRepository: ReturnType<typeof mock<MoviesRepositoryImpl>>;
Expand Down
2 changes: 1 addition & 1 deletion tests/main/factories/repositories/movies.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MoviesRepositoryImpl } from "@/data/repositories";
import { MoviesRepositoryImpl } from "@/infrastructure/repositories";
import { MoviesRepository } from "@/domain/repositories";
import { AxiosHttpClient } from "@/infrastructure/http";

Expand Down
2 changes: 1 addition & 1 deletion tests/main/factories/services/ai.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AiServiceImpl } from "@/data/services";
import { AiService } from "@/domain/services";
import { AxiosHttpClient } from "@/infrastructure/http";
import { AiServiceImpl } from "@/infrastructure/services";
import { Environment } from "@/main/config";

type SutTypes = {
Expand Down
4 changes: 2 additions & 2 deletions tests/main/factories/usecases/getMovie.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { MoviesRepositoryImpl } from "@/data/repositories";
import { MoviesRepositoryImpl } from "@/infrastructure/repositories";
import { MoviesRepository } from "@/domain/repositories";
import { GetMovieUsecase } from "@/domain/usecases";
import { AxiosHttpClient } from "@/infrastructure/http";
import { GetMovieUsecaseImpl } from "@/usecases";
import { GetMovieUsecaseImpl } from "@/infrastructure/usecases";

type SutTypes = {
axiosHttpClient: AxiosHttpClient;
Expand Down
7 changes: 4 additions & 3 deletions tests/main/factories/usecases/getMovieSuggestion.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { MoviesRepositoryImpl } from "@/data/repositories";
import { AiServiceImpl } from "@/data/services";
import { MoviesRepositoryImpl } from "@/infrastructure/repositories";

import { MoviesRepository } from "@/domain/repositories";
import { AiService } from "@/domain/services";
import { GetMovieSuggestionUsecase, GetMoviesUsecase } from "@/domain/usecases";
import { AxiosHttpClient } from "@/infrastructure/http";
import { Environment } from "@/main/config";
import { GetMovieSuggestionUsecaseImpl } from "@/usecases/getMovieSuggestion.usecase";
import { AiServiceImpl } from "@/infrastructure/services";
import { GetMovieSuggestionUsecaseImpl } from "@/infrastructure/usecases/getMovieSuggestion.usecase";

type SutTypes = {
axiosHttpClient: AxiosHttpClient;
Expand Down
4 changes: 2 additions & 2 deletions tests/main/factories/usecases/getMovies.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { MoviesRepositoryImpl } from "@/data/repositories";
import { MoviesRepositoryImpl } from "@/infrastructure/repositories";
import { MoviesRepository } from "@/domain/repositories";
import { GetMoviesUsecase } from "@/domain/usecases";
import { AxiosHttpClient } from "@/infrastructure/http";
import { GetMoviesUsecaseImpl } from "@/usecases";
import { GetMoviesUsecaseImpl } from "@/infrastructure/usecases";

type SutTypes = {
axiosHttpClient: AxiosHttpClient;
Expand Down
Loading