feat: add accounts and movies tables in migrations

- 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.
This commit is contained in:
2025-10-02 20:54:41 +00:00
parent 91c14f750e
commit aaa0ca5a54
28 changed files with 617 additions and 654 deletions

View File

@@ -0,0 +1,80 @@
import { describe, it, expect } from "bun:test";
import {
InvalidUsernameFormatError,
WeakPasswordError,
} from "../../src/domain/account/errors/AccountErrors";
import {
MAX_USERNAME_LENGTH,
MIN_PASSWORD_LENGTH,
} from "../../src/domain/account/validation/AccountValidation";
import { AccountEntity } from "../../src/domain/account/entity/AccountEntity";
describe("AccountEntity", () => {
describe("create", () => {
it("should create an account with valid username and password", async () => {
const email = "testaccount";
const password = "a".repeat(MIN_PASSWORD_LENGTH);
const account = await AccountEntity.create(email, password);
expect(account.username).toBe(email);
expect(account.roleId).toBe(1);
expect(account).toBeDefined();
});
it("should throw InvalidUsernameFormatError for invalid username", () => {
const invalidUsername = "a".repeat(MAX_USERNAME_LENGTH + 1);
const password = "a".repeat(MIN_PASSWORD_LENGTH);
expect(AccountEntity.create(invalidUsername, password)).rejects.toThrow(
InvalidUsernameFormatError,
);
});
it("should throw WeakPasswordError for short password", () => {
const username = "testaccount";
const shortPassword = "a".repeat(MIN_PASSWORD_LENGTH - 1);
expect(AccountEntity.create(username, shortPassword)).rejects.toThrow(
WeakPasswordError,
);
});
});
describe("verifyPassword", () => {
it("should return true for correct password", async () => {
const createAccount = await AccountEntity.create(
"test@example.com",
"password123",
);
const account = new AccountEntity(
1,
createAccount.username,
createAccount.hashedPassword,
createAccount.roleId,
new Date(),
new Date(),
);
expect(await account.verifyPassword("password123")).toBe(true);
});
it("should return false for incorrect password", async () => {
const createAccount = await AccountEntity.create(
"test@example.com",
"password123",
);
const account = new AccountEntity(
1,
createAccount.username,
createAccount.hashedPassword,
createAccount.roleId,
new Date(),
new Date(),
);
expect(await account.verifyPassword("wrongpassword")).toBe(false);
});
});
});