website refactor
This commit is contained in:
@@ -6,11 +6,19 @@ import { GameKey } from '../../domain/value-objects/GameKey';
|
||||
import { ExternalRating } from '../../domain/value-objects/ExternalRating';
|
||||
import { ExternalRatingProvenance } from '../../domain/value-objects/ExternalRatingProvenance';
|
||||
import { UpsertExternalGameRatingInput } from '../dtos/UpsertExternalGameRatingDto';
|
||||
import { vi, describe, it, expect, beforeEach } from 'vitest';
|
||||
import { vi, describe, it, expect, beforeEach, type Mock } from 'vitest';
|
||||
|
||||
describe('UpsertExternalGameRatingUseCase', () => {
|
||||
let useCase: UpsertExternalGameRatingUseCase;
|
||||
let mockRepository: ExternalGameRatingRepository;
|
||||
let mockRepository: {
|
||||
findByUserIdAndGameKey: Mock;
|
||||
findByUserId: Mock;
|
||||
findByGameKey: Mock;
|
||||
save: Mock;
|
||||
saveMany: Mock;
|
||||
delete: Mock;
|
||||
exists: Mock;
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
mockRepository = {
|
||||
@@ -21,9 +29,17 @@ describe('UpsertExternalGameRatingUseCase', () => {
|
||||
saveMany: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
exists: vi.fn(),
|
||||
} as any;
|
||||
} as unknown as {
|
||||
findByUserIdAndGameKey: Mock;
|
||||
findByUserId: Mock;
|
||||
findByGameKey: Mock;
|
||||
save: Mock;
|
||||
saveMany: Mock;
|
||||
delete: Mock;
|
||||
exists: Mock;
|
||||
};
|
||||
|
||||
useCase = new UpsertExternalGameRatingUseCase(mockRepository);
|
||||
useCase = new UpsertExternalGameRatingUseCase(mockRepository as unknown as ExternalGameRatingRepository);
|
||||
});
|
||||
|
||||
describe('execute', () => {
|
||||
@@ -42,8 +58,8 @@ describe('UpsertExternalGameRatingUseCase', () => {
|
||||
},
|
||||
};
|
||||
|
||||
(mockRepository.findByUserIdAndGameKey as any).mockResolvedValue(null);
|
||||
(mockRepository.save as any).mockImplementation(async (profile: any) => profile);
|
||||
mockRepository.findByUserIdAndGameKey.mockResolvedValue(null);
|
||||
mockRepository.save.mockImplementation(async (profile: ExternalGameRatingProfile) => profile);
|
||||
|
||||
const result = await useCase.execute(input);
|
||||
|
||||
@@ -61,8 +77,8 @@ describe('UpsertExternalGameRatingUseCase', () => {
|
||||
|
||||
it('should update existing profile', async () => {
|
||||
const existingProfile = createTestProfile('user-123', 'iracing');
|
||||
(mockRepository.findByUserIdAndGameKey as any).mockResolvedValue(existingProfile);
|
||||
(mockRepository.save as any).mockImplementation(async (profile: any) => profile);
|
||||
mockRepository.findByUserIdAndGameKey.mockResolvedValue(existingProfile);
|
||||
mockRepository.save.mockImplementation(async (profile: ExternalGameRatingProfile) => profile);
|
||||
|
||||
const input: UpsertExternalGameRatingInput = {
|
||||
userId: 'user-123',
|
||||
@@ -211,7 +227,7 @@ describe('UpsertExternalGameRatingUseCase', () => {
|
||||
},
|
||||
};
|
||||
|
||||
(mockRepository.findByUserIdAndGameKey as any).mockRejectedValue(new Error('Database connection failed'));
|
||||
mockRepository.findByUserIdAndGameKey.mockRejectedValue(new Error('Database connection failed'));
|
||||
|
||||
const result = await useCase.execute(input);
|
||||
|
||||
@@ -232,8 +248,8 @@ describe('UpsertExternalGameRatingUseCase', () => {
|
||||
},
|
||||
};
|
||||
|
||||
(mockRepository.findByUserIdAndGameKey as any).mockResolvedValue(null);
|
||||
(mockRepository.save as any).mockImplementation(async (profile: any) => profile);
|
||||
mockRepository.findByUserIdAndGameKey.mockResolvedValue(null);
|
||||
mockRepository.save.mockImplementation(async (profile: ExternalGameRatingProfile) => profile);
|
||||
|
||||
const result = await useCase.execute(input);
|
||||
|
||||
@@ -254,8 +270,8 @@ describe('UpsertExternalGameRatingUseCase', () => {
|
||||
},
|
||||
};
|
||||
|
||||
(mockRepository.findByUserIdAndGameKey as any).mockResolvedValue(null);
|
||||
(mockRepository.save as any).mockImplementation(async (profile: any) => profile);
|
||||
mockRepository.findByUserIdAndGameKey.mockResolvedValue(null);
|
||||
mockRepository.save.mockImplementation(async (profile: ExternalGameRatingProfile) => profile);
|
||||
|
||||
const result = await useCase.execute(input);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user