refactor use cases
This commit is contained in:
@@ -2,11 +2,8 @@ import { vi, type Mock } from 'vitest';
|
||||
import { GetCurrentSessionUseCase } from './GetCurrentSessionUseCase';
|
||||
import { User } from '../../domain/entities/User';
|
||||
import { IUserRepository, StoredUser } from '../../domain/repositories/IUserRepository';
|
||||
import type { Logger, UseCaseOutputPort } from '@core/shared/application';
|
||||
|
||||
type GetCurrentSessionOutput = {
|
||||
user: User;
|
||||
};
|
||||
import type { Logger } from '@core/shared/application';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
|
||||
describe('GetCurrentSessionUseCase', () => {
|
||||
let useCase: GetCurrentSessionUseCase;
|
||||
@@ -18,7 +15,6 @@ describe('GetCurrentSessionUseCase', () => {
|
||||
emailExists: Mock;
|
||||
};
|
||||
let logger: Logger;
|
||||
let output: UseCaseOutputPort<GetCurrentSessionOutput> & { present: Mock };
|
||||
|
||||
beforeEach(() => {
|
||||
mockUserRepo = {
|
||||
@@ -34,13 +30,9 @@ describe('GetCurrentSessionUseCase', () => {
|
||||
warn: vi.fn(),
|
||||
error: vi.fn(),
|
||||
} as unknown as Logger;
|
||||
output = {
|
||||
present: vi.fn(),
|
||||
};
|
||||
useCase = new GetCurrentSessionUseCase(
|
||||
mockUserRepo as IUserRepository,
|
||||
logger,
|
||||
output,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -60,11 +52,10 @@ describe('GetCurrentSessionUseCase', () => {
|
||||
|
||||
expect(mockUserRepo.findById).toHaveBeenCalledWith(userId);
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(output.present).toHaveBeenCalled();
|
||||
const callArgs = output.present.mock.calls?.[0]?.[0];
|
||||
expect(callArgs?.user).toBeInstanceOf(User);
|
||||
expect(callArgs?.user.getId().value).toBe(userId);
|
||||
expect(callArgs?.user.getDisplayName()).toBe('John Smith');
|
||||
const sessionResult = result.unwrap();
|
||||
expect(sessionResult.user).toBeInstanceOf(User);
|
||||
expect(sessionResult.user.getId().value).toBe(userId);
|
||||
expect(sessionResult.user.getDisplayName()).toBe('John Smith');
|
||||
});
|
||||
|
||||
it('should return error when user does not exist', async () => {
|
||||
@@ -75,5 +66,6 @@ describe('GetCurrentSessionUseCase', () => {
|
||||
|
||||
expect(mockUserRepo.findById).toHaveBeenCalledWith(userId);
|
||||
expect(result.isErr()).toBe(true);
|
||||
expect(result.unwrapErr().code).toBe('USER_NOT_FOUND');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user