- Created migration for accounts table with fields: id, username, password, role_id, created_at, updated_at. - Created migration for movies table with fields: id, title, overview, poster_path, backdrop_path, release_date, tmdb_id. refactor: update package.json scripts and dependencies - Changed dev script to use bun instead of tsx. - Added build:migrate script for migration. - Updated devDependencies for bun and oxlint. fix: refactor database connection and migration execution - Updated PgDatabase to use SQL from bun. - Refactored migration execution logic to read SQL files and execute them. feat: implement account creation and validation logic - Updated AccountEntity to use username instead of email. - Added validation for username format and password strength. - Implemented account repository methods for finding by username and inserting accounts. test: add tests for account entity, repository, and service - Created tests for AccountEntity to validate username and password. - Added tests for AccountRepository to ensure correct database interactions. - Implemented tests for AccountService to validate registration and login logic. chore: remove outdated tests and files - Deleted old tests related to email-based account management. - Cleaned up unused imports and files to streamline the codebase.
94 lines
3.0 KiB
TypeScript
94 lines
3.0 KiB
TypeScript
import { describe, it, expect } from "bun:test";
|
|
import {
|
|
passwordSchema,
|
|
loginSchema,
|
|
registerSchema,
|
|
MIN_PASSWORD_LENGTH,
|
|
} from "../../src/domain/account/validation/AccountValidation";
|
|
import { WeakPasswordError } from "../../src/domain/account/errors/AccountErrors";
|
|
import { AccountEntity } from "../../src/domain/account/entity/AccountEntity";
|
|
|
|
describe("AccountValidation", () => {
|
|
describe("Password validation consistency", () => {
|
|
const validPasswords = ["password123", "abcdefgh", "12345678", "P@ssw0rd!"];
|
|
|
|
const invalidPasswords = ["1234567", "short", "", "abc"];
|
|
|
|
it("should validate same passwords in Zod and Entity", () => {
|
|
validPasswords.forEach((password) => {
|
|
expect(passwordSchema.safeParse(password).success).toBe(true);
|
|
expect(() =>
|
|
AccountEntity.create("test@example.com", password),
|
|
).not.toThrow(WeakPasswordError);
|
|
});
|
|
|
|
invalidPasswords.forEach((password) => {
|
|
expect(passwordSchema.safeParse(password).success).toBe(false);
|
|
expect(() =>
|
|
AccountEntity.create("test@example.com", password),
|
|
).toThrow(WeakPasswordError);
|
|
});
|
|
});
|
|
|
|
it("should use same minimum length", () => {
|
|
validPasswords.forEach((password) => {
|
|
expect(password.length >= MIN_PASSWORD_LENGTH).toBe(true);
|
|
});
|
|
|
|
invalidPasswords.forEach((password) => {
|
|
expect(password.length >= MIN_PASSWORD_LENGTH).toBe(false);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("Complete schemas", () => {
|
|
it("should validate login schema correctly", () => {
|
|
const validLogin = {
|
|
username: "testaccount",
|
|
password: "password123",
|
|
};
|
|
const invalidLogin = { username: "ii", password: "123" };
|
|
|
|
expect(loginSchema.safeParse(validLogin).success).toBe(true);
|
|
expect(loginSchema.safeParse(invalidLogin).success).toBe(false);
|
|
});
|
|
|
|
it("should validate register schema correctly", () => {
|
|
const validRegister = {
|
|
username: "testaccount",
|
|
password: "password123",
|
|
};
|
|
const invalidRegister = { username: "ii", password: "123" };
|
|
|
|
expect(registerSchema.safeParse(validRegister).success).toBe(true);
|
|
expect(registerSchema.safeParse(invalidRegister).success).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("Error messages consistency", () => {
|
|
it("should return consistent password error message", () => {
|
|
const result = passwordSchema.safeParse("123");
|
|
expect(result.success).toBe(false);
|
|
if (!result.success) {
|
|
expect(result.error.issues[0]?.message).toContain(
|
|
`${MIN_PASSWORD_LENGTH} caractères`,
|
|
);
|
|
}
|
|
});
|
|
|
|
it("should return consistent username error message", () => {
|
|
const result = registerSchema.safeParse({
|
|
username: "ii",
|
|
password: "validPassword123",
|
|
});
|
|
|
|
expect(result.success).toBe(false);
|
|
if (!result.success) {
|
|
expect(result.error.issues[0]?.message).toContain(
|
|
"doit contenir au moins",
|
|
);
|
|
}
|
|
});
|
|
});
|
|
});
|