integration tests
Some checks failed
CI / lint-typecheck (pull_request) Failing after 4m50s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
Some checks failed
CI / lint-typecheck (pull_request) Failing after 4m50s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { MediaTestContext } from '../MediaTestContext';
|
||||
import { AvatarGenerationRequest } from '@core/media/domain/entities/AvatarGenerationRequest';
|
||||
|
||||
describe('Avatar Management: Generation and Selection', () => {
|
||||
let ctx: MediaTestContext;
|
||||
|
||||
beforeEach(() => {
|
||||
ctx = MediaTestContext.create();
|
||||
ctx.reset();
|
||||
});
|
||||
|
||||
describe('RequestAvatarGenerationUseCase', () => {
|
||||
it('should request avatar generation from photo', async () => {
|
||||
const result = await ctx.requestAvatarGenerationUseCase.execute({
|
||||
userId: 'user-1',
|
||||
facePhotoData: 'https://example.com/face-photo.jpg',
|
||||
suitColor: 'red',
|
||||
style: 'realistic',
|
||||
});
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
const successResult = result.unwrap();
|
||||
expect(successResult.requestId).toBeDefined();
|
||||
expect(successResult.status).toBe('completed');
|
||||
expect(successResult.avatarUrls).toHaveLength(3);
|
||||
|
||||
const request = await ctx.avatarGenerationRepository.findById(successResult.requestId);
|
||||
expect(request).not.toBeNull();
|
||||
expect(request?.status).toBe('completed');
|
||||
});
|
||||
|
||||
it('should reject generation with invalid face photo', async () => {
|
||||
const originalValidate = ctx.faceValidation.validateFacePhoto;
|
||||
ctx.faceValidation.validateFacePhoto = async () => ({
|
||||
isValid: false,
|
||||
hasFace: false,
|
||||
faceCount: 0,
|
||||
confidence: 0.0,
|
||||
errorMessage: 'No face detected',
|
||||
});
|
||||
|
||||
const result = await ctx.requestAvatarGenerationUseCase.execute({
|
||||
userId: 'user-1',
|
||||
facePhotoData: 'https://example.com/invalid-photo.jpg',
|
||||
suitColor: 'red',
|
||||
});
|
||||
|
||||
expect(result.isErr()).toBe(true);
|
||||
expect(result.unwrapErr().code).toBe('FACE_VALIDATION_FAILED');
|
||||
|
||||
ctx.faceValidation.validateFacePhoto = originalValidate;
|
||||
});
|
||||
});
|
||||
|
||||
describe('SelectAvatarUseCase', () => {
|
||||
it('should select a generated avatar', async () => {
|
||||
const request = AvatarGenerationRequest.create({
|
||||
id: 'request-1',
|
||||
userId: 'user-1',
|
||||
facePhotoUrl: 'https://example.com/face-photo.jpg',
|
||||
suitColor: 'red',
|
||||
style: 'realistic',
|
||||
});
|
||||
request.completeWithAvatars([
|
||||
'https://example.com/avatar-1.png',
|
||||
'https://example.com/avatar-2.png',
|
||||
'https://example.com/avatar-3.png',
|
||||
]);
|
||||
await ctx.avatarGenerationRepository.save(request);
|
||||
|
||||
const result = await ctx.selectAvatarUseCase.execute({
|
||||
requestId: 'request-1',
|
||||
selectedIndex: 1,
|
||||
});
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
const successResult = result.unwrap();
|
||||
expect(successResult.selectedAvatarUrl).toBe('https://example.com/avatar-2.png');
|
||||
|
||||
const updatedRequest = await ctx.avatarGenerationRepository.findById('request-1');
|
||||
expect(updatedRequest?.selectedAvatarUrl).toBe('https://example.com/avatar-2.png');
|
||||
});
|
||||
|
||||
it('should reject selection when request does not exist', async () => {
|
||||
const result = await ctx.selectAvatarUseCase.execute({
|
||||
requestId: 'non-existent-request',
|
||||
selectedIndex: 0,
|
||||
});
|
||||
|
||||
expect(result.isErr()).toBe(true);
|
||||
expect(result.unwrapErr().code).toBe('REQUEST_NOT_FOUND');
|
||||
});
|
||||
|
||||
it('should reject selection when request is not completed', async () => {
|
||||
const request = AvatarGenerationRequest.create({
|
||||
id: 'request-1',
|
||||
userId: 'user-1',
|
||||
facePhotoUrl: 'https://example.com/face-photo.jpg',
|
||||
suitColor: 'red',
|
||||
style: 'realistic',
|
||||
});
|
||||
await ctx.avatarGenerationRepository.save(request);
|
||||
|
||||
const result = await ctx.selectAvatarUseCase.execute({
|
||||
requestId: 'request-1',
|
||||
selectedIndex: 0,
|
||||
});
|
||||
|
||||
expect(result.isErr()).toBe(true);
|
||||
expect(result.unwrapErr().code).toBe('REQUEST_NOT_COMPLETED');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,89 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { MediaTestContext } from '../MediaTestContext';
|
||||
import { Avatar } from '@core/media/domain/entities/Avatar';
|
||||
|
||||
describe('Avatar Management: Retrieval and Updates', () => {
|
||||
let ctx: MediaTestContext;
|
||||
|
||||
beforeEach(() => {
|
||||
ctx = MediaTestContext.create();
|
||||
ctx.reset();
|
||||
});
|
||||
|
||||
describe('GetAvatarUseCase', () => {
|
||||
it('should retrieve driver avatar when avatar exists', async () => {
|
||||
const avatar = Avatar.create({
|
||||
id: 'avatar-1',
|
||||
driverId: 'driver-1',
|
||||
mediaUrl: 'https://example.com/avatar.png',
|
||||
});
|
||||
await ctx.avatarRepository.save(avatar);
|
||||
|
||||
const result = await ctx.getAvatarUseCase.execute({ driverId: 'driver-1' });
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
const successResult = result.unwrap();
|
||||
expect(successResult.avatar.id).toBe('avatar-1');
|
||||
expect(successResult.avatar.driverId).toBe('driver-1');
|
||||
expect(successResult.avatar.mediaUrl).toBe('https://example.com/avatar.png');
|
||||
});
|
||||
|
||||
it('should return AVATAR_NOT_FOUND when driver has no avatar', async () => {
|
||||
const result = await ctx.getAvatarUseCase.execute({ driverId: 'driver-1' });
|
||||
|
||||
expect(result.isErr()).toBe(true);
|
||||
expect(result.unwrapErr().code).toBe('AVATAR_NOT_FOUND');
|
||||
});
|
||||
|
||||
it('should handle repository errors gracefully', async () => {
|
||||
const originalFind = ctx.avatarRepository.findActiveByDriverId;
|
||||
ctx.avatarRepository.findActiveByDriverId = async () => {
|
||||
throw new Error('Database connection error');
|
||||
};
|
||||
|
||||
const result = await ctx.getAvatarUseCase.execute({ driverId: 'driver-1' });
|
||||
|
||||
expect(result.isErr()).toBe(true);
|
||||
expect(result.unwrapErr().code).toBe('REPOSITORY_ERROR');
|
||||
|
||||
ctx.avatarRepository.findActiveByDriverId = originalFind;
|
||||
});
|
||||
});
|
||||
|
||||
describe('UpdateAvatarUseCase', () => {
|
||||
it('should update existing avatar for a driver', async () => {
|
||||
const existingAvatar = Avatar.create({
|
||||
id: 'avatar-1',
|
||||
driverId: 'driver-1',
|
||||
mediaUrl: 'https://example.com/old-avatar.png',
|
||||
});
|
||||
await ctx.avatarRepository.save(existingAvatar);
|
||||
|
||||
const result = await ctx.updateAvatarUseCase.execute({
|
||||
driverId: 'driver-1',
|
||||
mediaUrl: 'https://example.com/new-avatar.png',
|
||||
});
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
|
||||
const oldAvatar = await ctx.avatarRepository.findById('avatar-1');
|
||||
expect(oldAvatar?.isActive).toBe(false);
|
||||
|
||||
const newAvatar = await ctx.avatarRepository.findActiveByDriverId('driver-1');
|
||||
expect(newAvatar).not.toBeNull();
|
||||
expect(newAvatar?.mediaUrl.value).toBe('https://example.com/new-avatar.png');
|
||||
});
|
||||
|
||||
it('should update avatar when driver has no existing avatar', async () => {
|
||||
const result = await ctx.updateAvatarUseCase.execute({
|
||||
driverId: 'driver-1',
|
||||
mediaUrl: 'https://example.com/avatar.png',
|
||||
});
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
const newAvatar = await ctx.avatarRepository.findActiveByDriverId('driver-1');
|
||||
expect(newAvatar).not.toBeNull();
|
||||
expect(newAvatar?.mediaUrl.value).toBe('https://example.com/avatar.png');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user