switch to bun

This commit is contained in:
2025-09-22 21:39:45 +00:00
parent 049ed4b956
commit 91c14f750e
17 changed files with 208 additions and 276 deletions

View File

@@ -1,6 +1,5 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { describe, it, expect, jest, beforeEach } from "bun:test";
import AccountService from "../src/domain/account/service/AccountService";
import { AccountRepositoryInterface } from "../src/domain/account/repository/AccountRepositoryInterface";
import { AccountEntity } from "../src/domain/account/entity/AccountEntity";
import {
AccountNotFoundError,
@@ -10,15 +9,19 @@ import {
describe("AccountService", () => {
let accountService: AccountService;
let mockAccountRepository: AccountRepositoryInterface;
let mockAccountRepository: {
findByEmail: ReturnType<typeof jest.fn>;
save: ReturnType<typeof jest.fn>;
findById: ReturnType<typeof jest.fn>;
};
beforeEach(() => {
mockAccountRepository = {
findByEmail: vi.fn(),
save: vi.fn(),
findById: vi.fn(),
findByEmail: jest.fn(() => Promise.resolve(null)),
save: jest.fn(() => Promise.resolve("123")),
findById: jest.fn(() => Promise.resolve(null)),
};
accountService = new AccountService(mockAccountRepository);
accountService = new AccountService(mockAccountRepository as any);
});
describe("createAccount", () => {
@@ -26,8 +29,12 @@ describe("AccountService", () => {
const email = "test@example.com";
const password = "password123";
vi.mocked(mockAccountRepository.findByEmail).mockResolvedValue(null);
vi.mocked(mockAccountRepository.save).mockResolvedValue("123");
mockAccountRepository.findByEmail.mockImplementation(() =>
Promise.resolve(null),
);
mockAccountRepository.save.mockImplementation(() =>
Promise.resolve("123"),
);
const result = await accountService.register(email, password);
@@ -44,8 +51,8 @@ describe("AccountService", () => {
const password = "password123";
const existingAccount = AccountEntity.create(email, password);
vi.mocked(mockAccountRepository.findByEmail).mockResolvedValue(
existingAccount,
mockAccountRepository.findByEmail.mockImplementation(() =>
Promise.resolve(existingAccount),
);
await expect(accountService.register(email, password)).rejects.toThrow(
@@ -60,7 +67,9 @@ describe("AccountService", () => {
const password = "password123";
const account = AccountEntity.create(email, password);
vi.mocked(mockAccountRepository.findByEmail).mockResolvedValue(account);
mockAccountRepository.findByEmail.mockImplementation(() =>
Promise.resolve(account),
);
const result = await accountService.login(email, password);
@@ -72,7 +81,9 @@ describe("AccountService", () => {
const email = "test@example.com";
const password = "password123";
vi.mocked(mockAccountRepository.findByEmail).mockResolvedValue(null);
mockAccountRepository.findByEmail.mockImplementation(() =>
Promise.resolve(null),
);
await expect(accountService.login(email, password)).rejects.toThrow(
AccountNotFoundError,
@@ -85,7 +96,9 @@ describe("AccountService", () => {
const wrongPassword = "wrongpassword";
const account = AccountEntity.create(email, password);
vi.mocked(mockAccountRepository.findByEmail).mockResolvedValue(account);
mockAccountRepository.findByEmail.mockImplementation(() =>
Promise.resolve(account),
);
await expect(accountService.login(email, wrongPassword)).rejects.toThrow(
BadPasswordError,