refactor: remove unused tests, mocks, and outdated e2e configurations

Deleted unused e2e tests, mocks (`cuid2`, `jose`, `ml-kem`, `sha3`), and their associated jest configurations. Simplified services by ensuring proper dependency imports, resolving circular references, and improving TypeScript type usage for enhanced maintainability and testability. Upgraded Dockerfile base image to match new development standards.
This commit is contained in:
Mathis HERRIOT
2026-01-14 13:51:32 +01:00
parent 8ffeaeba05
commit 0c045e8d3c
44 changed files with 163 additions and 183 deletions

View File

@@ -2,11 +2,10 @@ jest.mock("uuid", () => ({
v4: jest.fn(() => "mocked-uuid"),
}));
import { CACHE_MANAGER } from "@nestjs/cache-manager";
import { BadRequestException } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { CACHE_MANAGER } from "@nestjs/cache-manager";
import { Test, TestingModule } from "@nestjs/testing";
import { DatabaseService } from "../database/database.service";
import { MediaService } from "../media/media.service";
import { S3Service } from "../s3/s3.service";
import { ContentsService } from "./contents.service";
@@ -44,9 +43,7 @@ describe("ContentsService", () => {
};
const mockCacheManager = {
store: {
keys: jest.fn().mockResolvedValue([]),
},
clear: jest.fn(),
del: jest.fn(),
};
@@ -141,7 +138,9 @@ describe("ContentsService", () => {
describe("incrementViews", () => {
it("should increment views", async () => {
mockContentsRepository.incrementViews.mockResolvedValue([{ id: "1", views: 1 }]);
mockContentsRepository.incrementViews.mockResolvedValue([
{ id: "1", views: 1 },
]);
const result = await service.incrementViews("1");
expect(mockContentsRepository.incrementViews).toHaveBeenCalledWith("1");
expect(result[0].views).toBe(1);

View File

@@ -1,13 +1,22 @@
import { BadRequestException, Injectable, Logger } from "@nestjs/common";
import { CACHE_MANAGER } from "@nestjs/cache-manager";
import { Cache } from "cache-manager";
import { Inject } from "@nestjs/common";
import {
BadRequestException,
Inject,
Injectable,
Logger,
} from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import type { Cache } from "cache-manager";
import { v4 as uuidv4 } from "uuid";
import type { IMediaService } from "../common/interfaces/media.interface";
import type {
IMediaService,
MediaProcessingResult,
} from "../common/interfaces/media.interface";
import type { IStorageService } from "../common/interfaces/storage.interface";
import { MediaService } from "../media/media.service";
import { S3Service } from "../s3/s3.service";
import { CreateContentDto } from "./dto/create-content.dto";
import { UploadContentDto } from "./dto/upload-content.dto";
import { ContentsRepository } from "./repositories/contents.repository";
@Injectable()
@@ -24,11 +33,7 @@ export class ContentsService {
private async clearContentsCache() {
this.logger.log("Clearing contents cache");
const keys = await this.cacheManager.store.keys();
const contentsKeys = keys.filter((key) => key.startsWith("contents/"));
for (const key of contentsKeys) {
await this.cacheManager.del(key);
}
await this.cacheManager.clear();
}
async getUploadUrl(userId: string, fileName: string) {
@@ -40,12 +45,7 @@ export class ContentsService {
async uploadAndProcess(
userId: string,
file: Express.Multer.File,
data: {
title: string;
type: "meme" | "gif";
categoryId?: string;
tags?: string[];
},
data: UploadContentDto,
) {
this.logger.log(`Uploading and processing file for user ${userId}`);
// 0. Validation du format et de la taille
@@ -86,7 +86,7 @@ export class ContentsService {
}
// 2. Transcodage
let processed;
let processed: MediaProcessingResult;
if (file.mimetype.startsWith("image/")) {
// Image ou GIF -> WebP (format moderne, bien supporté)
processed = await this.mediaService.processImage(file.buffer, "webp");
@@ -129,7 +129,7 @@ export class ContentsService {
return { data, totalCount };
}
async create(userId: string, data: any) {
async create(userId: string, data: CreateContentDto) {
this.logger.log(`Creating content for user ${userId}: ${data.title}`);
const { tags: tagNames, ...contentData } = data;
@@ -166,7 +166,7 @@ export class ContentsService {
return this.contentsRepository.findOne(idOrSlug);
}
generateBotHtml(content: any): string {
generateBotHtml(content: { title: string; storageKey: string }): string {
const imageUrl = this.getFileUrl(content.storageKey);
return `<!DOCTYPE html>
<html>

View File

@@ -6,9 +6,9 @@ import {
exists,
ilike,
isNull,
sql,
lte,
type SQL,
sql,
} from "drizzle-orm";
import { DatabaseService } from "../../database/database.service";
import {
@@ -113,10 +113,7 @@ export class ContentsRepository {
.select()
.from(favorites)
.where(
and(
eq(favorites.contentId, contents.id),
eq(favorites.userId, userId),
),
and(eq(favorites.contentId, contents.id), eq(favorites.userId, userId)),
),
),
);
@@ -143,7 +140,6 @@ export class ContentsRepository {
author: {
id: users.uuid,
username: users.username,
avatarUrl: users.avatarUrl,
},
category: {
id: categories.id,
@@ -173,18 +169,13 @@ export class ContentsRepository {
return results.map((r) => ({
...r,
tags: tagsForContents
.filter((t) => t.contentId === r.id)
.map((t) => t.name),
tags: tagsForContents.filter((t) => t.contentId === r.id).map((t) => t.name),
}));
}
async create(data: NewContentInDb & { userId: string }, tagNames?: string[]) {
return await this.databaseService.db.transaction(async (tx) => {
const [newContent] = await tx
.insert(contents)
.values(data)
.returning();
const [newContent] = await tx.insert(contents).values(data).returning();
if (tagNames && tagNames.length > 0) {
for (const tagName of tagNames) {
@@ -325,10 +316,7 @@ export class ContentsRepository {
.select()
.from(favorites)
.where(
and(
eq(favorites.contentId, contents.id),
eq(favorites.userId, userId),
),
and(eq(favorites.contentId, contents.id), eq(favorites.userId, userId)),
),
),
);
@@ -377,7 +365,12 @@ export class ContentsRepository {
async purgeSoftDeleted(before: Date) {
return await this.databaseService.db
.delete(contents)
.where(and(sql`${contents.deletedAt} IS NOT NULL`, lte(contents.deletedAt, before)))
.where(
and(
sql`${contents.deletedAt} IS NOT NULL`,
lte(contents.deletedAt, before),
),
)
.returning();
}
}