feat(users): enhance user schema and extend service dependencies
Add `email` and `status` fields to user schema for better data handling. Update `UsersService` with new service dependencies (`RbacService`, `MediaService`, `S3Service`, `ConfigService`) for enhanced functionality. Mock dependencies in tests for improved coverage. Adjust user model with optional and extended fields for flexibility. Streamline and update import statements.
This commit is contained in:
@@ -68,6 +68,7 @@ export class UsersRepository {
|
||||
.select({
|
||||
uuid: users.uuid,
|
||||
username: users.username,
|
||||
email: users.email,
|
||||
displayName: users.displayName,
|
||||
avatarUrl: users.avatarUrl,
|
||||
status: users.status,
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
jest.mock("uuid", () => ({
|
||||
v4: jest.fn(() => "mocked-uuid"),
|
||||
}));
|
||||
|
||||
jest.mock("@noble/post-quantum/ml-kem.js", () => ({
|
||||
ml_kem768: {
|
||||
keygen: jest.fn(),
|
||||
@@ -12,7 +16,11 @@ jest.mock("jose", () => ({
|
||||
}));
|
||||
|
||||
import { CACHE_MANAGER } from "@nestjs/cache-manager";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import { Test, TestingModule } from "@nestjs/testing";
|
||||
import { RbacService } from "../auth/rbac.service";
|
||||
import { MediaService } from "../media/media.service";
|
||||
import { S3Service } from "../s3/s3.service";
|
||||
import { UsersRepository } from "./repositories/users.repository";
|
||||
import { UsersService } from "./users.service";
|
||||
|
||||
@@ -39,6 +47,23 @@ describe("UsersService", () => {
|
||||
del: jest.fn(),
|
||||
};
|
||||
|
||||
const mockRbacService = {
|
||||
getUserRoles: jest.fn(),
|
||||
};
|
||||
|
||||
const mockMediaService = {
|
||||
scanFile: jest.fn(),
|
||||
processImage: jest.fn(),
|
||||
};
|
||||
|
||||
const mockS3Service = {
|
||||
uploadFile: jest.fn(),
|
||||
};
|
||||
|
||||
const mockConfigService = {
|
||||
get: jest.fn(),
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
jest.clearAllMocks();
|
||||
|
||||
@@ -47,6 +72,10 @@ describe("UsersService", () => {
|
||||
UsersService,
|
||||
{ provide: UsersRepository, useValue: mockUsersRepository },
|
||||
{ provide: CACHE_MANAGER, useValue: mockCacheManager },
|
||||
{ provide: RbacService, useValue: mockRbacService },
|
||||
{ provide: MediaService, useValue: mockMediaService },
|
||||
{ provide: S3Service, useValue: mockS3Service },
|
||||
{ provide: ConfigService, useValue: mockConfigService },
|
||||
],
|
||||
}).compile();
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
Injectable,
|
||||
Logger,
|
||||
} from "@nestjs/common";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import type { Cache } from "cache-manager";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { RbacService } from "../auth/rbac.service";
|
||||
@@ -27,6 +28,7 @@ export class UsersService {
|
||||
private readonly rbacService: RbacService,
|
||||
@Inject(MediaService) private readonly mediaService: IMediaService,
|
||||
@Inject(S3Service) private readonly s3Service: IStorageService,
|
||||
private readonly configService: ConfigService,
|
||||
) {}
|
||||
|
||||
private async clearUserCache(username?: string) {
|
||||
@@ -114,9 +116,7 @@ export class UsersService {
|
||||
}
|
||||
|
||||
if (file.size > 2 * 1024 * 1024) {
|
||||
throw new BadRequestException(
|
||||
"Image trop volumineuse. Limite: 2 Mo.",
|
||||
);
|
||||
throw new BadRequestException("Image trop volumineuse. Limite: 2 Mo.");
|
||||
}
|
||||
|
||||
// 1. Scan Antivirus
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { LogIn, User as UserIcon } from "lucide-react";
|
||||
import { LogIn } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import * as React from "react";
|
||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useAuth } from "@/providers/auth-provider";
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
export interface User {
|
||||
id: string;
|
||||
id?: string;
|
||||
uuid: string;
|
||||
username: string;
|
||||
email: string;
|
||||
email?: string;
|
||||
displayName?: string;
|
||||
avatarUrl?: string;
|
||||
bio?: string;
|
||||
role: "user" | "admin";
|
||||
role?: "user" | "admin";
|
||||
status?: "active" | "verification" | "suspended" | "pending" | "deleted";
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user